convert

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FinishReasonUnspecified     = "FINISH_REASON_UNSPECIFIED"
	FinishStop                  = "STOP"
	FinishMaxTokens             = "MAX_TOKENS"
	FinishSafety                = "SAFETY"
	FinishRecitation            = "RECITATION"
	FinishLanguage              = "LANGUAGE"
	FinishOther                 = "OTHER"
	FinishBlockList             = "BLOCKLIST"
	FinishProhibitedContent     = "PROHIBITED_CONTENT"
	FinishSPII                  = "SPII"
	FinishMalformedFunctionCall = "MALFORMED_FUNCTION_CALL"
)

Variables

View Source
var (
	AIModelInputTokenLabel  = "ai_model_input_token"
	AIModelOutputTokenLabel = "ai_model_output_token"
	AIModelTotalTokenLabel  = "ai_model_total_token"
	AIModelModeLabel        = "ai_model_mode"
	AIModelLabel            = "ai_model"
	AIProviderLabel         = "ai_provider"
	AIProviderStatusesLabel = "ai_provider_statuses"
	AIModelStatusLabel      = "ai_model_status"
)
View Source
var (
	StatusNormal         = "normal"
	StatusInvalidRequest = "invalid request"
	StatusQuotaExhausted = "quota exhausted"
	StatusExpired        = "expired"
	StatusExceeded       = "exceeded"
	StatusInvalid        = "invalid"
	StatusTimeout        = "timeout"
)

Functions

func CheckKeySourceSkill added in v0.19.5

func CheckKeySourceSkill(skill string) bool

func CheckProviderSkill added in v0.19.5

func CheckProviderSkill(skill string) bool

func DelKeyResource added in v0.19.5

func DelKeyResource(provider string, resourceId string)

func DelProvider added in v0.19.5

func DelProvider(provider string)

func GetAIModel added in v0.19.5

func GetAIModel(ctx eocontext.EoContext) string

func GetAIModelInputToken added in v0.19.5

func GetAIModelInputToken(ctx eocontext.EoContext) int

func GetAIModelMode added in v0.19.5

func GetAIModelMode(ctx eocontext.EoContext) string

func GetAIModelOutputToken added in v0.19.5

func GetAIModelOutputToken(ctx eocontext.EoContext) int

func GetAIModelTotalToken added in v0.19.5

func GetAIModelTotalToken(ctx eocontext.EoContext) int

func GetAIProvider added in v0.19.5

func GetAIProvider(ctx eocontext.EoContext) string

func GetAIStatus added in v0.19.5

func GetAIStatus(ctx eocontext.EoContext) string

func GetAIStatusExceeded added in v0.19.5

func GetAIStatusExceeded(ctx eocontext.EoContext) string

func GetAIStatusExpired added in v0.19.5

func GetAIStatusExpired(ctx eocontext.EoContext) string

func GetAIStatusInvalid added in v0.19.5

func GetAIStatusInvalid(ctx eocontext.EoContext) string

func GetAIStatusInvalidRequest added in v0.19.5

func GetAIStatusInvalidRequest(ctx eocontext.EoContext) string

func GetAIStatusNormal added in v0.19.5

func GetAIStatusNormal(ctx eocontext.EoContext) string

func GetAIStatusQuotaExhausted added in v0.19.5

func GetAIStatusQuotaExhausted(ctx eocontext.EoContext) string

func GetAIStatusTimeout added in v0.19.5

func GetAIStatusTimeout(ctx eocontext.EoContext) string

func LoadModels added in v0.19.5

func LoadModels(providerContent []byte, dirFs embed.FS) (map[string]*Model, error)

func MapToStruct added in v0.19.5

func MapToStruct[T any](tmp map[string]interface{}) *T

MapToStruct 将 map 转换为结构体实例

func NewBalanceHandler added in v0.19.5

func NewBalanceHandler(id string, base string, timeout time.Duration) (eocontext.BalanceHandler, error)

func NewBaseNode added in v0.19.5

func NewBaseNode(id string, ip string, port int) *_BaseNode

func SetAIModel added in v0.19.5

func SetAIModel(ctx eocontext.EoContext, model string)

func SetAIModelInputToken added in v0.19.5

func SetAIModelInputToken(ctx eocontext.EoContext, token int)

func SetAIModelMode added in v0.19.5

func SetAIModelMode(ctx eocontext.EoContext, mode string)

func SetAIModelOutputToken added in v0.19.5

func SetAIModelOutputToken(ctx eocontext.EoContext, token int)

func SetAIModelTotalToken added in v0.19.5

func SetAIModelTotalToken(ctx eocontext.EoContext, token int)

func SetAIProvider added in v0.19.5

func SetAIProvider(ctx eocontext.EoContext, provider string)

func SetAIProviderStatuses added in v0.19.5

func SetAIProviderStatuses(ctx eocontext.EoContext, status AIProviderStatus)

func SetAIStatus added in v0.19.5

func SetAIStatus(ctx eocontext.EoContext, status string)

func SetAIStatusExceeded added in v0.19.5

func SetAIStatusExceeded(ctx eocontext.EoContext)

func SetAIStatusExpired added in v0.19.5

func SetAIStatusExpired(ctx eocontext.EoContext)

func SetAIStatusInvalid added in v0.19.5

func SetAIStatusInvalid(ctx eocontext.EoContext)

func SetAIStatusInvalidRequest added in v0.19.5

func SetAIStatusInvalidRequest(ctx eocontext.EoContext)

func SetAIStatusNormal added in v0.19.5

func SetAIStatusNormal(ctx eocontext.EoContext)

func SetAIStatusQuotaExhausted added in v0.19.5

func SetAIStatusQuotaExhausted(ctx eocontext.EoContext)

func SetAIStatusTimeout added in v0.19.5

func SetAIStatusTimeout(ctx eocontext.EoContext)

func SetKeyResource added in v0.19.5

func SetKeyResource(provider string, resource IKeyResource)

func SetProvider added in v0.19.5

func SetProvider(provider string, p IProvider)

Types

type AIProviderStatus added in v0.19.5

type AIProviderStatus struct {
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Key      string `json:"key"`
	Status   string `json:"status"`
}

func GetAIProviderStatuses added in v0.19.5

func GetAIProviderStatuses(ctx eocontext.EoContext) []AIProviderStatus

type ClientRequest added in v0.19.5

type ClientRequest struct {
	Messages []*Message `json:"messages"`
}

type ClientResponse added in v0.19.5

type ClientResponse struct {
	Message      Message `json:"message,omitempty"`
	FinishReason string  `json:"finish_reason,omitempty"`
	Code         int     `json:"code"`
	Error        string  `json:"error"`
}

type FGenerateConfig

type FGenerateConfig func(cfg string) (map[string]interface{}, error)

type IChildConverter

type IChildConverter interface {
	IConverter
	Endpoint() string
}

type IConverter

type IConverter interface {
	RequestConvert(ctx eocontext.EoContext, extender map[string]interface{}) error
	ResponseConvert(ctx eocontext.EoContext) error
}

type IConverterDriver

type IConverterDriver interface {
	GetModel(model string) (FGenerateConfig, bool)
	GetConverter(model string) (IConverter, bool)
}

type IConverterFactory added in v0.19.5

type IConverterFactory interface {
	Create(cfg string) (IConverterDriver, error)
}

type IKeyResource added in v0.19.5

type IKeyResource interface {
	ID() string
	Health() bool
	Priority() int
	// Up 上线
	Up()
	// Down 下线
	Down()

	IsBreaker() bool
	// Breaker 熔断
	Breaker()
	ConverterDriver() IConverterDriver
}

func KeyResources added in v0.19.5

func KeyResources(provider string) ([]IKeyResource, bool)

type IManager

type IManager interface {
	Get(id string) (IConverterFactory, bool)
	Set(id string, driver IConverterFactory)
	Del(id string)
}

type IProvider added in v0.19.5

type IProvider interface {
	Provider() string
	Model() string
	ModelConfig() map[string]interface{}
	Priority() int
	Health() bool
	Down()
	BalanceHandler() eoscContext.BalanceHandler
}

func GetProvider added in v0.19.5

func GetProvider(provider string) (IProvider, bool)

func Providers added in v0.19.5

func Providers() []IProvider

type KeyPool added in v0.19.5

type KeyPool eosc.Untyped[string, IKeyResource]

type KeyPoolManager added in v0.19.5

type KeyPoolManager struct {
	// contains filtered or unexported fields
}

func NewKeyPoolManager added in v0.19.5

func NewKeyPoolManager() *KeyPoolManager

func (*KeyPoolManager) Del added in v0.19.5

func (m *KeyPoolManager) Del(id string)

func (*KeyPoolManager) DelKeySource added in v0.19.5

func (m *KeyPoolManager) DelKeySource(id, resourceId string)

func (*KeyPoolManager) KeyResources added in v0.19.5

func (m *KeyPoolManager) KeyResources(id string) ([]IKeyResource, bool)

func (*KeyPoolManager) Set added in v0.19.5

func (m *KeyPoolManager) Set(id string, resource IKeyResource)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func (*Manager) Del

func (m *Manager) Del(id string)

func (*Manager) Get

func (m *Manager) Get(id string) (IConverterFactory, bool)

func (*Manager) Set

func (m *Manager) Set(id string, driver IConverterFactory)

type Message added in v0.19.5

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Mode added in v0.19.5

type Mode string
const (
	ModeChat     Mode = "chat"
	ModeComplete Mode = "complete"
)

func (Mode) String added in v0.19.5

func (m Mode) String() string

type Model added in v0.19.5

type Model struct {
	Model           string     `json:"model" yaml:"model"`
	ModelType       ModelType  `json:"model_type" yaml:"model_type"`
	ModelProperties *ModelMode `json:"model_properties" yaml:"model_properties"`
}

type ModelMode added in v0.19.5

type ModelMode struct {
	Mode        string `json:"mode" yaml:"mode"`
	ContextSize int    `json:"context_size" yaml:"context_size"`
}

type ModelType added in v0.19.5

type ModelType string
const (
	ModelTypeLLM           ModelType = "llm"
	ModelTypeTextEmbedding ModelType = "text-embedding"
	ModelTypeSpeech2Text   ModelType = "speech2text"
	ModelTypeModeration    ModelType = "moderation"
	ModelTypeTTS           ModelType = "tts"
)

type Provider added in v0.19.5

type Provider struct {
	Provider            string   `json:"provider" yaml:"provider"`
	SupportedModelTypes []string `json:"supported_model_types" yaml:"supported_model_types"`
}

type ProviderManager added in v0.19.5

type ProviderManager struct {
	// contains filtered or unexported fields
}

func NewProviderManager added in v0.19.5

func NewProviderManager() *ProviderManager

func (*ProviderManager) Del added in v0.19.5

func (m *ProviderManager) Del(provider string)

func (*ProviderManager) Get added in v0.19.5

func (m *ProviderManager) Get(provider string) (IProvider, bool)

func (*ProviderManager) Providers added in v0.19.5

func (m *ProviderManager) Providers() []IProvider

func (*ProviderManager) Set added in v0.19.5

func (m *ProviderManager) Set(provider string, p IProvider)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL