Documentation
¶
Index ¶
- Constants
- Variables
- func CheckKeySourceSkill(skill string) bool
- func CheckProviderSkill(skill string) bool
- func DelKeyResource(provider string, resourceId string)
- func DelProvider(id string)
- func GetAIKey(ctx eocontext.EoContext) string
- func GetAIModel(ctx eocontext.EoContext) string
- func GetAIModelInputToken(ctx eocontext.EoContext) int
- func GetAIModelMode(ctx eocontext.EoContext) string
- func GetAIModelOutputToken(ctx eocontext.EoContext) int
- func GetAIModelTotalToken(ctx eocontext.EoContext) int
- func GetAIProvider(ctx eocontext.EoContext) string
- func GetAIStatus(ctx eocontext.EoContext) string
- func GetAIStatusExceeded(ctx eocontext.EoContext) string
- func GetAIStatusExpired(ctx eocontext.EoContext) string
- func GetAIStatusInvalid(ctx eocontext.EoContext) string
- func GetAIStatusInvalidRequest(ctx eocontext.EoContext) string
- func GetAIStatusNormal(ctx eocontext.EoContext) string
- func GetAIStatusQuotaExhausted(ctx eocontext.EoContext) string
- func GetAIStatusTimeout(ctx eocontext.EoContext) string
- func MapToStruct[T any](tmp map[string]interface{}) *T
- func NewBalanceHandler(id string, base string, timeout time.Duration) (eocontext.BalanceHandler, error)
- func NewBaseNode(id string, ip string, port int) *_BaseNode
- func RegisterConverterCreateFunc(id string, fn IConverterCreateFunc)
- func ResponseConvert(ctx eoscContext.EoContext, checkErr CheckError, ...) error
- func SetAIKey(ctx eocontext.EoContext, key string)
- func SetAIModel(ctx eocontext.EoContext, model string)
- func SetAIModelInputToken(ctx eocontext.EoContext, token int)
- func SetAIModelMode(ctx eocontext.EoContext, mode string)
- func SetAIModelOutputToken(ctx eocontext.EoContext, token int)
- func SetAIModelTotalToken(ctx eocontext.EoContext, token int)
- func SetAIProvider(ctx eocontext.EoContext, provider string)
- func SetAIProviderStatuses(ctx eocontext.EoContext, status AIProviderStatus)
- func SetAIStatus(ctx eocontext.EoContext, status string)
- func SetAIStatusExceeded(ctx eocontext.EoContext)
- func SetAIStatusExpired(ctx eocontext.EoContext)
- func SetAIStatusInvalid(ctx eocontext.EoContext)
- func SetAIStatusInvalidRequest(ctx eocontext.EoContext)
- func SetAIStatusNormal(ctx eocontext.EoContext)
- func SetAIStatusQuotaExhausted(ctx eocontext.EoContext)
- func SetAIStatusTimeout(ctx eocontext.EoContext)
- func SetKeyResource(provider string, resource IKeyResource)
- func SetProvider(id string, p IProvider)
- func TransformData(inputJSON string, mappingRule MappingRule) (map[string]interface{}, error)
- type AIProviderStatus
- type BalanceManager
- type CheckError
- type Error
- type FGenerateConfig
- type IChildConverter
- type IConverter
- type IConverterCreateFunc
- type IConverterFactory
- type IKeyResource
- type IManager
- type IModelAccessConfig
- type IModelAccessConfigManager
- type IProvider
- type KeyPool
- type KeyPoolManager
- type Manager
- type MappingRule
- type Message
- type ModelConfig
- type OpenAIConvert
- type Request
- type Response
- type ValueRule
Constants ¶
View Source
const (
OpenAIChatCompletePath = "/chat/completions"
)
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" AIKeyLabel = "ai_key" 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" ParamAIModel = "param_ai_model" )
Functions ¶
func CheckKeySourceSkill ¶
func CheckProviderSkill ¶
func DelKeyResource ¶
func DelProvider ¶
func DelProvider(id string)
func GetAIModel ¶
func GetAIModelInputToken ¶
func GetAIModelMode ¶
func GetAIModelOutputToken ¶
func GetAIModelTotalToken ¶
func GetAIProvider ¶
func GetAIStatus ¶
func GetAIStatusExceeded ¶
func GetAIStatusExpired ¶
func GetAIStatusInvalid ¶
func GetAIStatusNormal ¶
func GetAIStatusTimeout ¶
func MapToStruct ¶
MapToStruct 将 map 转换为结构体实例
func NewBalanceHandler ¶
func NewBaseNode ¶
func RegisterConverterCreateFunc ¶
func RegisterConverterCreateFunc(id string, fn IConverterCreateFunc)
func ResponseConvert ¶
func ResponseConvert(ctx eoscContext.EoContext, checkErr CheckError, errorCallback func(ctx http_service.IHttpContext, body []byte)) error
func SetAIModel ¶
func SetAIModelInputToken ¶
func SetAIModelMode ¶
func SetAIModelOutputToken ¶
func SetAIModelTotalToken ¶
func SetAIProvider ¶
func SetAIProviderStatuses ¶
func SetAIProviderStatuses(ctx eocontext.EoContext, status AIProviderStatus)
func SetAIStatus ¶
func SetAIStatusExceeded ¶
func SetAIStatusExpired ¶
func SetAIStatusInvalid ¶
func SetAIStatusNormal ¶
func SetAIStatusTimeout ¶
func SetKeyResource ¶
func SetKeyResource(provider string, resource IKeyResource)
func SetProvider ¶
func TransformData ¶
func TransformData(inputJSON string, mappingRule MappingRule) (map[string]interface{}, error)
TransformData 执行字段映射和类型转换
Types ¶
type AIProviderStatus ¶
type AIProviderStatus struct {
Provider string `json:"provider"`
Model string `json:"model"`
Key string `json:"key"`
Status string `json:"status"`
}
func GetAIProviderStatuses ¶
func GetAIProviderStatuses(ctx eocontext.EoContext) []AIProviderStatus
type BalanceManager ¶
type BalanceManager struct {
// contains filtered or unexported fields
}
func NewBalanceManager ¶
func NewBalanceManager() *BalanceManager
func (*BalanceManager) Balances ¶
func (m *BalanceManager) Balances() []IProvider
func (*BalanceManager) Del ¶
func (m *BalanceManager) Del(id string) string
func (*BalanceManager) SetProvider ¶
func (m *BalanceManager) SetProvider(id string, p IProvider)
type CheckError ¶
type CheckError func(ctx http_service.IHttpContext, body []byte) bool
type FGenerateConfig ¶
type IChildConverter ¶
type IChildConverter interface {
IConverter
Endpoint() string
}
type IConverter ¶
type IConverterCreateFunc ¶
type IConverterCreateFunc func(cfg string) (IConverter, error)
func GetConverterCreateFunc ¶
func GetConverterCreateFunc(id string) (IConverterCreateFunc, bool)
type IConverterFactory ¶
type IConverterFactory interface {
Create(cfg string) (IConverter, error)
}
type IKeyResource ¶
type IKeyResource interface {
ID() string
Health() bool
Priority() int
// Up 上线
Up()
// Down 下线
Down()
IsBreaker() bool
// Breaker 熔断
Breaker()
IConverter
}
func KeyResources ¶
func KeyResources(provider string) ([]IKeyResource, bool)
type IManager ¶
type IManager interface {
Get(id string) (IConverterCreateFunc, bool)
Set(id string, driver IConverterCreateFunc)
Del(id string)
}
func NewManager ¶
func NewManager() IManager
type IModelAccessConfig ¶
type IModelAccessConfigManager ¶
type IModelAccessConfigManager interface {
Get(id string) (IModelAccessConfig, bool)
Set(id string, config IModelAccessConfig)
Del(id string)
}
func NewModelAccessConfigManager ¶
func NewModelAccessConfigManager() IModelAccessConfigManager
type IProvider ¶
type IProvider interface {
Provider() string
Model() string
ModelConfig() map[string]interface{}
Priority() int
Health() bool
Down()
BalanceHandler() eoscContext.BalanceHandler
GenExtender(cfg string) (map[string]interface{}, error)
}
func GetProvider ¶
type KeyPoolManager ¶
type KeyPoolManager struct {
// contains filtered or unexported fields
}
func NewKeyPoolManager ¶
func NewKeyPoolManager() *KeyPoolManager
func (*KeyPoolManager) Del ¶
func (m *KeyPoolManager) Del(id string)
func (*KeyPoolManager) DelKeySource ¶
func (m *KeyPoolManager) DelKeySource(id, resourceId string)
func (*KeyPoolManager) KeyResources ¶
func (m *KeyPoolManager) KeyResources(id string) ([]IKeyResource, bool)
func (*KeyPoolManager) Set ¶
func (m *KeyPoolManager) Set(id string, resource IKeyResource)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) Set ¶
func (m *Manager) Set(id string, driver IConverterCreateFunc)
type Message ¶
type Message struct {
// Role indicates the role of the message sender (e.g., "system", "user", "assistant").
Role string `json:"role"`
// Content contains the actual text of the message.
Content string `json:"content"`
}
Message represents a single message in the conversation.
type ModelConfig ¶
type ModelConfig struct {
MaxTokens int `json:"max_tokens,omitempty"`
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
N int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
Stop []string `json:"stop,omitempty"`
PresencePenalty float32 `json:"presence_penalty,omitempty"`
ResponseFormat *openai.ChatCompletionResponseFormat `json:"response_format,omitempty"`
Seed *int `json:"seed,omitempty"`
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
LogProbs bool `json:"logprobs,omitempty"`
TopLogProbs int `json:"top_logprobs,omitempty"`
}
type OpenAIConvert ¶
type OpenAIConvert struct {
// contains filtered or unexported fields
}
func NewOpenAIConvert ¶
func NewOpenAIConvert(apikey string, baseUrl string, timeout time.Duration, checkErr CheckError, errorCallback func(ctx http_service.IHttpContext, body []byte)) (*OpenAIConvert, error)
func (*OpenAIConvert) RequestConvert ¶
func (o *OpenAIConvert) RequestConvert(ctx eoscContext.EoContext, extender map[string]interface{}) error
func (*OpenAIConvert) ResponseConvert ¶
func (o *OpenAIConvert) ResponseConvert(ctx eoscContext.EoContext) error
type Request ¶
type Request struct {
Model string `json:"model"`
Messages []openai.ChatCompletionMessage `json:"messages"`
// MaxTokens The maximum number of tokens that can be generated in the chat completion.
// This value can be used to control costs for text generated via API.
// This value is now deprecated in favor of max_completion_tokens, and is not compatible with o1 series models.
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat-create-max_tokens
MaxTokens int `json:"max_tokens,omitempty"`
// MaxCompletionTokens An upper bound for the number of tokens that can be generated for a completion,
// including visible output tokens and reasoning tokens https://platform.openai.com/docs/guides/reasoning
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
N int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
Stop []string `json:"stop,omitempty"`
PresencePenalty float32 `json:"presence_penalty,omitempty"`
}
Request 定义客户端统一输入请求格式
type Response ¶
type Response struct {
*openai.ChatCompletionResponse `json:"response,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response 定义客户端统一输出响应格式
Click to show internal directories.
Click to hide internal directories.