Documentation
¶
Index ¶
- Variables
- func AfterHandler(ctx context.Context, mak *MAK, after *mcommon.AfterHandler)
- func BeforeHandler(ctx context.Context, before *mcommon.BeforeHandler)
- func Billing(ctx context.Context, mak *MAK, billingData *common.BillingData, ...) (spend common.Spend)
- func CheckIp(ctx context.Context, ipWhitelist, ipBlacklist []string) error
- func ConvChatCompletionsToResponsesRequest(ctx context.Context, body []byte) smodel.OpenAIResponsesReq
- func ConvQuota(quota int, n ...int) float64
- func ConvResponsesStreamToChatCompletionsResponse(ctx context.Context, res smodel.OpenAIResponsesStreamRes) smodel.ChatCompletionResponse
- func ConvResponsesToChatCompletionsRequest(request *ghttp.Request, isChatCompletions bool) smodel.ChatCompletionRequest
- func ConvResponsesToChatCompletionsResponse(ctx context.Context, res smodel.OpenAIResponsesRes) smodel.ChatCompletionResponse
- func DefaultLogUserPrivacy(logPrivacy *mcommon.LogPrivacy) *mcommon.UserPrivacy
- func DefaultUserPrivacy() *mcommon.UserPrivacy
- func GetProviderCode(ctx context.Context, providerId string) string
- func GetResolvedSessionKeepConfig(mak *MAK) *mcommon.ModelAgentSessionKeep
- func HandleMessages(messages []smodel.ChatCompletionMessage) []smodel.ChatCompletionMessage
- func HandleSessionKeepFailure(ctx context.Context, mak *MAK)
- func HandleSessionKeepSuccess(ctx context.Context, mak *MAK)
- func IsAborted(err error) bool
- func IsMaxRetry(isEnableModelAgent bool, agentTotal, keyTotal, retry int) bool
- func IsNeedRetry(err error) (isRetry bool, isDisabled bool)
- func MatchTimeRule(ctx context.Context, rules []*common.TimeRule, model ...*model.Model) *common.TimeRule
- func New() service.ICommon
- func NewAdapter(ctx context.Context, mak *MAK, isLong bool) (adapter sdk.Adapter)
- func NewAdapterOfficial(ctx context.Context, mak *MAK, isLong bool) (adapter sdk.AdapterOfficial)
- func NewAdapterOpenAI(ctx context.Context, mak *MAK, isLong bool) *openai.OpenAI
- func NewConverter(ctx context.Context, provider string) sdk.Converter
- func NewModerationClient(ctx context.Context, m *model.Model, key, baseUrl, path string, ...) *sdk.ModerationClient
- func NewRealtimeClient(ctx context.Context, model *model.Model, key, baseUrl, path string) *sdk.RealtimeClient
- func NormalizeUserPrivacy(privacy *mcommon.UserPrivacy, logPrivacy *mcommon.LogPrivacy) *mcommon.UserPrivacy
- func RecordSpend(ctx context.Context, spend common.Spend, mak *MAK) error
- func TokensFromMessages(ctx context.Context, model string, messages []smodel.ChatCompletionMessage) int
- func TokensFromString(ctx context.Context, model, text string) int
- func WritePassthroughHeaders(ctx context.Context, pt *EffectivePassthrough, headers http.Header)
- type EffectivePassthrough
- type MAK
Constants ¶
This section is empty.
Variables ¶
View Source
var ReqReservedHeaders = []string{
"authorization", "x-api-key", "api-key", "x-goog-api-key",
"host", "connection", "keep-alive", "transfer-encoding", "upgrade",
"content-length", "content-type", "trace-id",
}
请求保留头(不透传)
View Source
var ResReservedHeaders = []string{
"transfer-encoding", "connection", "keep-alive",
"content-length", "content-encoding", "set-cookie", "strict-transport-security",
}
响应保留头(不透传)
Functions ¶
func AfterHandler ¶
func AfterHandler(ctx context.Context, mak *MAK, after *mcommon.AfterHandler)
后置处理器
func Billing ¶
func Billing(ctx context.Context, mak *MAK, billingData *common.BillingData, billingItems ...string) (spend common.Spend)
计算花费
func ConvChatCompletionsToResponsesRequest ¶
func ConvChatCompletionsToResponsesRequest(ctx context.Context, body []byte) smodel.OpenAIResponsesReq
func ConvResponsesStreamToChatCompletionsResponse ¶
func ConvResponsesStreamToChatCompletionsResponse(ctx context.Context, res smodel.OpenAIResponsesStreamRes) smodel.ChatCompletionResponse
func ConvResponsesToChatCompletionsRequest ¶
func ConvResponsesToChatCompletionsRequest(request *ghttp.Request, isChatCompletions bool) smodel.ChatCompletionRequest
func ConvResponsesToChatCompletionsResponse ¶
func ConvResponsesToChatCompletionsResponse(ctx context.Context, res smodel.OpenAIResponsesRes) smodel.ChatCompletionResponse
func DefaultLogUserPrivacy ¶ added in v2.4.0
func DefaultLogUserPrivacy(logPrivacy *mcommon.LogPrivacy) *mcommon.UserPrivacy
func DefaultUserPrivacy ¶ added in v2.4.0
func DefaultUserPrivacy() *mcommon.UserPrivacy
func GetResolvedSessionKeepConfig ¶ added in v2.3.0
func GetResolvedSessionKeepConfig(mak *MAK) *mcommon.ModelAgentSessionKeep
func HandleMessages ¶
func HandleMessages(messages []smodel.ChatCompletionMessage) []smodel.ChatCompletionMessage
func HandleSessionKeepFailure ¶ added in v2.3.0
会话保持失败处理
func HandleSessionKeepSuccess ¶ added in v2.3.0
会话保持成功处理
func IsMaxRetry ¶
func IsNeedRetry ¶
func MatchTimeRule ¶ added in v2.2.0
func NewAdapterOfficial ¶
func NewAdapterOpenAI ¶
func NewConverter ¶
func NewModerationClient ¶
func NewRealtimeClient ¶
func NormalizeUserPrivacy ¶ added in v2.4.0
func NormalizeUserPrivacy(privacy *mcommon.UserPrivacy, logPrivacy *mcommon.LogPrivacy) *mcommon.UserPrivacy
func TokensFromMessages ¶
func WritePassthroughHeaders ¶ added in v2.4.0
func WritePassthroughHeaders(ctx context.Context, pt *EffectivePassthrough, headers http.Header)
WritePassthroughHeaders 将上游响应头透传写入客户端响应
Types ¶
type EffectivePassthrough ¶ added in v2.4.0
type EffectivePassthrough struct {
ReqParams []string // 请求透传参数
ResParams []string // 响应透传参数
ReqHeaderMode int // 请求头透传模式[1:全量, 2:指定]
ReqHeaderList []string // 请求头透传白名单
ResHeaderMode int // 响应头透传模式[1:全量, 2:指定]
ResHeaderList []string // 响应头透传白名单
}
有效透传配置(Model ∩ ModelAgent 交集)
func GetEffectivePassthrough ¶ added in v2.4.0
func GetEffectivePassthrough(ctx context.Context, m *model.Model, agent *model.ModelAgent) *EffectivePassthrough
计算有效的透传配置, 无ModelAgent时使用Model配置, 有ModelAgent时取交集
type MAK ¶
type MAK struct {
Provider string
Model string
Messages []smodel.ChatCompletionMessage
ReqModel *model.Model
RealModel *model.Model
ModelAgent *model.ModelAgent
Key *model.Key
FallbackModelAgent *model.ModelAgent
FallbackModel *model.Model
AgentTotal int
KeyTotal int
RealKey string
BaseUrl string
Path string
User *model.User
App *model.App
AppKey *model.AppKey
Group *model.Group
Passthrough *EffectivePassthrough // 有效透传配置
}
Click to show internal directories.
Click to hide internal directories.