common

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIp added in v0.5.0

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

func ConvChatCompletionsToResponsesRequest added in v1.5.0

func ConvChatCompletionsToResponsesRequest(request *ghttp.Request) sdkm.OpenAIResponsesReq

func ConvResponsesStreamToChatCompletionsResponse added in v1.5.0

func ConvResponsesStreamToChatCompletionsResponse(ctx context.Context, res sdkm.OpenAIResponsesStreamRes) sdkm.ChatCompletionResponse

func ConvResponsesToChatCompletionsRequest added in v1.5.0

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

func ConvResponsesToChatCompletionsResponse added in v1.5.0

func ConvResponsesToChatCompletionsResponse(ctx context.Context, res sdkm.OpenAIResponsesRes) sdkm.ChatCompletionResponse

func GetCompletionTokens added in v0.5.0

func GetCompletionTokens(ctx context.Context, model, completion string) int

func GetCorpCode added in v0.3.0

func GetCorpCode(ctx context.Context, corpId string) string

func GetImageGenerationQuota added in v1.5.0

func GetImageGenerationQuota(model *model.Model, quality, size string) (generationQuota mcommon.GenerationQuota)

func GetMidjourneyQuota added in v0.4.0

func GetMidjourneyQuota(model *model.Model, request *ghttp.Request, path string) (mcommon.MidjourneyQuota, error)

func GetMultimodalAudioTokens added in v0.5.0

func GetMultimodalAudioTokens(ctx context.Context, model string, messages []sdkm.ChatCompletionMessage, reqModel *model.Model) (textTokens, audioTokens int)

func GetMultimodalSearchTokens added in v1.4.0

func GetMultimodalSearchTokens(ctx context.Context, webSearchOptions any, reqModel *model.Model) (searchTokens int)

func GetMultimodalTokens added in v0.4.0

func GetMultimodalTokens(ctx context.Context, model string, multiContent []interface{}, reqModel *model.Model) (textTokens, imageTokens int)

func GetPromptTokens added in v0.5.0

func GetPromptTokens(ctx context.Context, model string, messages []sdkm.ChatCompletionMessage) int

func HandleMessages added in v0.4.0

func HandleMessages(messages []sdkm.ChatCompletionMessage) []sdkm.ChatCompletionMessage

func IsAborted added in v0.3.0

func IsAborted(err error) bool

func IsMaxRetry added in v0.3.0

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

func IsNeedRetry added in v0.3.0

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

func New

func New() service.ICommon

func NewAnthropicClient added in v1.1.0

func NewAnthropicClient(ctx context.Context, model *model.Model, key, baseURL, path string) (*anthropic.Client, error)

func NewClient added in v0.3.0

func NewClient(ctx context.Context, corp string, model *model.Model, key, baseURL, path string) (sdk.Client, error)

func NewGoogleClient added in v1.1.0

func NewGoogleClient(ctx context.Context, model *model.Model, key, baseURL, path string) (*google.Client, error)

func NewOpenAIClient added in v1.5.0

func NewOpenAIClient(ctx context.Context, model *model.Model, key, baseURL, path string) (*openai.Client, error)

func NewRealtimeClient added in v0.5.0

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

Types

type ApplicationDefaultCredentials added in v0.5.0

type ApplicationDefaultCredentials struct {
	Type                    string `json:"type"`
	ProjectId               string `json:"project_id"`
	PrivateKeyId            string `json:"private_key_id"`
	PrivateKey              string `json:"private_key"`
	ClientEmail             string `json:"client_email"`
	ClientId                string `json:"client_id"`
	AuthUri                 string `json:"auth_uri"`
	TokenUri                string `json:"token_uri"`
	AuthProviderX509CertUrl string `json:"auth_provider_x509_cert_url"`
	ClientX509CertUrl       string `json:"client_x509_cert_url"`
	UniverseDomain          string `json:"universe_domain"`
}

type MAK added in v0.5.0

type MAK struct {
	Corp               string
	Model              string
	Messages           []sdkm.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.Key
	Group              *model.Group
}

func (*MAK) InitMAK added in v0.5.0

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