common

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterHandler

func AfterHandler(ctx context.Context, mak *MAK, after *mcommon.AfterHandler)

后置处理器

func BeforeHandler

func BeforeHandler(ctx context.Context, before *mcommon.BeforeHandler)

前置处理器

func Billing

func Billing(ctx context.Context, mak *MAK, billingData *common.BillingData, billingItems ...string) (spend common.Spend)

计算花费

func CheckIp

func CheckIp(ctx context.Context, ipWhitelist, ipBlacklist []string) error

func ConvChatCompletionsToResponsesRequest

func ConvChatCompletionsToResponsesRequest(ctx context.Context, body []byte) smodel.OpenAIResponsesReq

func ConvQuota

func ConvQuota(quota int, n ...int) float64

转换额度单位

func ConvResponsesToChatCompletionsRequest

func ConvResponsesToChatCompletionsRequest(request *ghttp.Request, isChatCompletions bool) smodel.ChatCompletionRequest

func GetProviderCode

func GetProviderCode(ctx context.Context, providerId string) string

func IsAborted

func IsAborted(err error) bool

func IsMaxRetry

func IsMaxRetry(isEnableModelAgent bool, agentTotal, keyTotal, retry int) bool

func IsNeedRetry

func IsNeedRetry(err error) (isRetry bool, isDisabled bool)

func MatchTimeRule added in v2.2.0

func MatchTimeRule(ctx context.Context, rules []*common.TimeRule) *common.TimeRule

func New

func New() service.ICommon

func NewAdapter

func NewAdapter(ctx context.Context, mak *MAK, isLong bool) (adapter sdk.Adapter)

func NewAdapterOfficial

func NewAdapterOfficial(ctx context.Context, mak *MAK, isLong bool) (adapter sdk.AdapterOfficial)

func NewAdapterOpenAI

func NewAdapterOpenAI(ctx context.Context, mak *MAK, isLong bool) *openai.OpenAI

func NewConverter

func NewConverter(ctx context.Context, provider string) sdk.Converter

func NewModerationClient

func NewModerationClient(ctx context.Context, model *model.Model, key, baseUrl, path string) *sdk.ModerationClient

func NewRealtimeClient

func NewRealtimeClient(ctx context.Context, model *model.Model, key, baseUrl, path string) *sdk.RealtimeClient

func RecordSpend

func RecordSpend(ctx context.Context, spend common.Spend, mak *MAK) error

记录花费

func TokensFromMessages

func TokensFromMessages(ctx context.Context, model string, messages []smodel.ChatCompletionMessage) int

func TokensFromString

func TokensFromString(ctx context.Context, model, text string) int

Types

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
}

func (*MAK) InitMAK

func (mak *MAK) InitMAK(ctx context.Context, retry ...int) (err error)

Jump to

Keyboard shortcuts

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