service

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterApp

func RegisterApp(i IApp)

func RegisterAudio added in v0.5.0

func RegisterAudio(i IAudio)

func RegisterAuth

func RegisterAuth(i IAuth)

func RegisterChat

func RegisterChat(i IChat)

func RegisterCommon

func RegisterCommon(i ICommon)

func RegisterCorp added in v0.3.0

func RegisterCorp(i ICorp)

func RegisterDashboard added in v0.2.0

func RegisterDashboard(i IDashboard)

func RegisterEmbedding added in v0.4.0

func RegisterEmbedding(i IEmbedding)

func RegisterFile added in v0.5.0

func RegisterFile(i IFile)

func RegisterImage

func RegisterImage(i IImage)

func RegisterKey

func RegisterKey(i IKey)

func RegisterMidjourney

func RegisterMidjourney(i IMidjourney)

func RegisterModel

func RegisterModel(i IModel)

func RegisterModelAgent

func RegisterModelAgent(i IModelAgent)

func RegisterModeration added in v0.5.0

func RegisterModeration(i IModeration)

func RegisterRealtime added in v0.5.0

func RegisterRealtime(i IRealtime)

func RegisterSession

func RegisterSession(i ISession)

func RegisterUser

func RegisterUser(i IUser)

Types

type IApp

type IApp interface {
	// 根据应用ID获取应用信息
	GetApp(ctx context.Context, appId int) (*model.App, error)
	// 应用列表
	List(ctx context.Context) ([]*model.App, error)
	// 应用花费额度
	SpendQuota(ctx context.Context, appId int, spendQuota int, currentQuota int) error
	// 应用已用额度
	UsedQuota(ctx context.Context, appId int, quota int) error
	// 保存应用信息到缓存
	SaveCacheApp(ctx context.Context, app *model.App) error
	// 获取缓存中的应用信息
	GetCacheApp(ctx context.Context, appId int) (*model.App, error)
	// 更新缓存中的应用信息
	UpdateCacheApp(ctx context.Context, app *entity.App)
	// 移除缓存中的应用信息
	RemoveCacheApp(ctx context.Context, appId int)
	// 保存应用额度到缓存
	SaveCacheAppQuota(ctx context.Context, appId int, quota int) error
	// 获取缓存中的应用额度
	GetCacheAppQuota(ctx context.Context, appId int) int
	// 保存应用密钥信息到缓存
	SaveCacheAppKey(ctx context.Context, key *model.Key) error
	// 获取缓存中的应用密钥信息
	GetCacheAppKey(ctx context.Context, secretKey string) (*model.Key, error)
	// 更新缓存中的应用密钥信息
	UpdateCacheAppKey(ctx context.Context, key *entity.Key)
	// 移除缓存中的应用密钥信息
	RemoveCacheAppKey(ctx context.Context, secretKey string)
	// 应用密钥花费额度
	AppKeySpendQuota(ctx context.Context, secretKey string, spendQuota int, currentQuota int) error
	// 应用密钥已用额度
	AppKeyUsedQuota(ctx context.Context, secretKey string, quota int) error
	// 保存应用密钥额度到缓存
	SaveCacheAppKeyQuota(ctx context.Context, secretKey string, quota int) error
	// 获取缓存中的应用密钥额度
	GetCacheAppKeyQuota(ctx context.Context, secretKey string) int
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
	// 应用密钥变更订阅
	SubscribeKey(ctx context.Context, msg string) error
}

func App

func App() IApp

type IAudio added in v0.5.0

type IAudio interface {
	// Speech
	Speech(ctx context.Context, params sdkm.SpeechRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.SpeechResponse, err error)
	// Transcriptions
	Transcriptions(ctx context.Context, params *v1.TranscriptionsReq, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.AudioResponse, err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, audioReq *model.AudioReq, audioRes *model.AudioRes, retryInfo *mcommon.Retry, retry ...int)
}

func Audio added in v0.5.0

func Audio() IAudio

type IAuth

type IAuth interface {
	// 身份核验
	Authenticator(ctx context.Context, secretKey string) error
	// 核验密钥
	VerifySecretKey(ctx context.Context, secretKey string) error
}

func Auth

func Auth() IAuth

type IChat

type IChat interface {
	// Completions
	Completions(ctx context.Context, params sdkm.ChatCompletionRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.ChatCompletionResponse, err error)
	// CompletionsStream
	CompletionsStream(ctx context.Context, params sdkm.ChatCompletionRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, completionsReq *sdkm.ChatCompletionRequest, completionsRes *model.CompletionsRes, retryInfo *mcommon.Retry, isSmartMatch bool, retry ...int)
	// SmartCompletions
	SmartCompletions(ctx context.Context, params sdkm.ChatCompletionRequest, reqModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.ChatCompletionResponse, err error)
}

func Chat

func Chat() IChat

type ICommon

type ICommon interface {
	// 解析密钥
	ParseSecretKey(ctx context.Context, secretKey string) (int, int, error)
	// 记录错误次数和禁用
	RecordError(ctx context.Context, model *model.Model, key *model.Key, modelAgent *model.ModelAgent)
	// 记录使用额度
	RecordUsage(ctx context.Context, totalTokens int, key string) error
	GetUserTotalTokens(ctx context.Context) (int, error)
	GetAppTotalTokens(ctx context.Context) (int, error)
	GetKeyTotalTokens(ctx context.Context) (int, error)
	GetUserUsageKey(ctx context.Context) string
	GetAppTotalTokensField(ctx context.Context) string
	GetKeyTotalTokensField(ctx context.Context) string
}

func Common

func Common() ICommon

type ICorp added in v0.3.0

type ICorp interface {
	// 根据公司ID获取公司信息
	GetCorp(ctx context.Context, id string) (*model.Corp, error)
	// 公司列表
	List(ctx context.Context) ([]*model.Corp, error)
	// 根据公司ID获取公司信息并保存到缓存
	GetCorpAndSaveCache(ctx context.Context, id string) (*model.Corp, error)
	// 保存公司到缓存
	SaveCache(ctx context.Context, corp *model.Corp) error
	// 保存公司列表到缓存
	SaveCacheList(ctx context.Context, corps []*model.Corp) error
	// 获取缓存中的公司信息
	GetCacheCorp(ctx context.Context, id string) (*model.Corp, error)
	// 获取缓存中的公司列表
	GetCacheList(ctx context.Context, ids ...string) ([]*model.Corp, error)
	// 更新缓存中的公司列表
	UpdateCacheCorp(ctx context.Context, newData *entity.Corp)
	// 移除缓存中的公司列表
	RemoveCacheCorp(ctx context.Context, id string)
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
}

func Corp added in v0.3.0

func Corp() ICorp

type IDashboard added in v0.2.0

type IDashboard interface {
	// Subscription
	Subscription(ctx context.Context) (*model.DashboardSubscriptionRes, error)
	// Usage
	Usage(ctx context.Context) (*model.DashboardUsageRes, error)
}

func Dashboard added in v0.2.0

func Dashboard() IDashboard

type IEmbedding added in v0.4.0

type IEmbedding interface {
	// Embeddings
	Embeddings(ctx context.Context, params sdkm.EmbeddingRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.EmbeddingResponse, err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, completionsReq *sdkm.EmbeddingRequest, completionsRes *model.CompletionsRes, retryInfo *mcommon.Retry, retry ...int)
}

func Embedding added in v0.4.0

func Embedding() IEmbedding

type IFile added in v0.5.0

type IFile interface {
	// Files
	Files(ctx context.Context, params model.FileFilesReq) ([]byte, error)
}

func File added in v0.5.0

func File() IFile

type IImage

type IImage interface {
	// Generations
	Generations(ctx context.Context, params sdkm.ImageRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.ImageResponse, err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, imageReq *sdkm.ImageRequest, imageRes *model.ImageRes, retryInfo *mcommon.Retry, retry ...int)
}

func Image

func Image() IImage

type IKey

type IKey interface {
	// 根据secretKey获取密钥信息
	GetKey(ctx context.Context, secretKey string) (*model.Key, error)
	// 根据模型ID获取密钥列表
	GetModelKeys(ctx context.Context, id string) ([]*model.Key, error)
	// 密钥列表
	List(ctx context.Context, typ int) ([]*model.Key, error)
	// 挑选模型密钥
	PickModelKey(ctx context.Context, m *model.Model) (int, *model.Key, error)
	// 移除模型密钥
	RemoveModelKey(ctx context.Context, m *model.Model, key *model.Key)
	// 记录错误模型密钥
	RecordErrorModelKey(ctx context.Context, m *model.Model, key *model.Key)
	// 禁用模型密钥
	DisabledModelKey(ctx context.Context, key *model.Key, disabledReason string)
	// 保存模型密钥列表到缓存
	SaveCacheModelKeys(ctx context.Context, id string, keys []*model.Key) error
	// 获取缓存中的模型密钥列表
	GetCacheModelKeys(ctx context.Context, id string) ([]*model.Key, error)
	// 新增模型密钥到缓存列表中
	CreateCacheModelKey(ctx context.Context, key *entity.Key)
	// 更新缓存中的模型密钥
	UpdateCacheModelKey(ctx context.Context, oldData *entity.Key, newData *entity.Key)
	// 移除缓存中的模型密钥
	RemoveCacheModelKey(ctx context.Context, key *entity.Key)
	// 密钥已用额度
	UsedQuota(ctx context.Context, key string, quota int) error
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
}

func Key

func Key() IKey

type IMidjourney

type IMidjourney interface {
	// 任务提交
	Submit(ctx context.Context, request *ghttp.Request, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.MidjourneyResponse, err error)
	// 任务查询
	Task(ctx context.Context, request *ghttp.Request, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.MidjourneyResponse, err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, response model.MidjourneyResponse, retryInfo *mcommon.Retry, retry ...int)
}

func Midjourney

func Midjourney() IMidjourney

type IModel

type IModel interface {
	// 根据model获取模型信息
	GetModel(ctx context.Context, m string) (*model.Model, error)
	// 根据模型ID获取模型信息
	GetModelById(ctx context.Context, id string) (*model.Model, error)
	// 根据model和secretKey获取模型信息
	GetModelBySecretKey(ctx context.Context, m string, secretKey string) (*model.Model, error)
	// 模型列表
	List(ctx context.Context, ids []string) ([]*model.Model, error)
	// 全部模型列表
	ListAll(ctx context.Context) ([]*model.Model, error)
	// 根据模型ID获取模型信息并保存到缓存
	GetModelAndSaveCache(ctx context.Context, id string) (*model.Model, error)
	// 获取模型列表并保存到缓存
	GetModelListAndSaveCacheList(ctx context.Context, ids []string) ([]*model.Model, error)
	// 保存模型到缓存
	SaveCache(ctx context.Context, m *model.Model) error
	// 保存模型列表到缓存
	SaveCacheList(ctx context.Context, models []*model.Model) error
	// 获取缓存中的模型列表
	GetCacheList(ctx context.Context, ids ...string) ([]*model.Model, error)
	// 获取缓存中的模型信息
	GetCacheModel(ctx context.Context, id string) (*model.Model, error)
	// 更新缓存中的模型列表
	UpdateCacheModel(ctx context.Context, oldData *entity.Model, newData *entity.Model)
	// 移除缓存中的模型列表
	RemoveCacheModel(ctx context.Context, id string)
	// 获取目标模型
	GetTargetModel(ctx context.Context, model *model.Model, messages []sdkm.ChatCompletionMessage) (targetModel *model.Model, err error)
	// 获取后备模型
	GetFallbackModel(ctx context.Context, model *model.Model) (fallbackModel *model.Model, err error)
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
}

func Model

func Model() IModel

type IModelAgent

type IModelAgent interface {
	// 根据模型代理ID获取模型代理信息
	GetModelAgentById(ctx context.Context, id string) (*model.ModelAgent, error)
	// 模型代理列表
	List(ctx context.Context, ids []string) ([]*model.ModelAgent, error)
	// 全部模型代理列表
	ListAll(ctx context.Context) ([]*model.ModelAgent, error)
	// 根据模型代理ID获取密钥列表
	GetModelAgentKeys(ctx context.Context, id string) ([]*model.Key, error)
	// 挑选模型代理
	PickModelAgent(ctx context.Context, m *model.Model) (int, *model.ModelAgent, error)
	// 移除模型代理
	RemoveModelAgent(ctx context.Context, m *model.Model, modelAgent *model.ModelAgent)
	// 记录错误模型代理
	RecordErrorModelAgent(ctx context.Context, m *model.Model, modelAgent *model.ModelAgent)
	// 禁用模型代理
	DisabledModelAgent(ctx context.Context, modelAgent *model.ModelAgent, disabledReason string)
	// 挑选模型代理密钥
	PickModelAgentKey(ctx context.Context, modelAgent *model.ModelAgent) (int, *model.Key, error)
	// 移除模型代理密钥
	RemoveModelAgentKey(ctx context.Context, modelAgent *model.ModelAgent, key *model.Key)
	// 记录错误模型代理密钥
	RecordErrorModelAgentKey(ctx context.Context, modelAgent *model.ModelAgent, key *model.Key)
	// 禁用模型代理密钥
	DisabledModelAgentKey(ctx context.Context, key *model.Key, disabledReason string)
	// 保存模型代理列表到缓存
	SaveCacheList(ctx context.Context, modelAgents []*model.ModelAgent) error
	// 获取缓存中的模型代理列表
	GetCacheList(ctx context.Context, ids ...string) ([]*model.ModelAgent, error)
	// 新增模型代理到缓存列表中
	CreateCacheModelAgent(ctx context.Context, newData *model.ModelAgent)
	// 更新缓存中的模型代理列表
	UpdateCacheModelAgent(ctx context.Context, oldData *model.ModelAgent, newData *model.ModelAgent)
	// 移除缓存中的模型代理
	RemoveCacheModelAgent(ctx context.Context, modelAgent *model.ModelAgent)
	// 保存模型代理密钥列表到缓存
	SaveCacheModelAgentKeys(ctx context.Context, id string, keys []*model.Key) error
	// 获取缓存中的模型代理密钥列表
	GetCacheModelAgentKeys(ctx context.Context, id string) ([]*model.Key, error)
	// 新增模型代理密钥到缓存列表中
	CreateCacheModelAgentKey(ctx context.Context, key *entity.Key)
	// 更新缓存中的模型代理密钥
	UpdateCacheModelAgentKey(ctx context.Context, oldData *entity.Key, newData *entity.Key)
	// 移除缓存中的模型代理密钥
	RemoveCacheModelAgentKey(ctx context.Context, key *entity.Key)
	// 获取缓存中的模型代理信息
	GetCacheModelAgent(ctx context.Context, id string) (*model.ModelAgent, error)
	// 根据模型代理ID获取模型代理信息并保存到缓存
	GetModelAgentAndSaveCache(ctx context.Context, id string) (*model.ModelAgent, error)
	// 保存模型代理到缓存
	SaveCache(ctx context.Context, modelAgent *model.ModelAgent) error
	// 获取后备模型代理
	GetFallbackModelAgent(ctx context.Context, model *model.Model) (fallbackModelAgent *model.ModelAgent, err error)
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
}

func ModelAgent

func ModelAgent() IModelAgent

type IModeration added in v0.5.0

type IModeration interface {
	// Moderations
	Moderations(ctx context.Context, params sdkm.ModerationRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (response sdkm.ModerationResponse, err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, completionsReq *sdkm.ModerationRequest, completionsRes *model.CompletionsRes, retryInfo *mcommon.Retry, retry ...int)
}

func Moderation added in v0.5.0

func Moderation() IModeration

type IRealtime added in v0.5.0

type IRealtime interface {
	// Realtime
	Realtime(ctx context.Context, r *ghttp.Request, params model.RealtimeRequest, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, retry ...int) (err error)
	// 保存日志
	SaveLog(ctx context.Context, reqModel *model.Model, realModel *model.Model, fallbackModelAgent *model.ModelAgent, fallbackModel *model.Model, key *model.Key, completionsReq *sdkm.ChatCompletionRequest, completionsRes *model.CompletionsRes, retryInfo *mcommon.Retry, isSmartMatch bool, retry ...int)
}

func Realtime added in v0.5.0

func Realtime() IRealtime

type ISession

type ISession interface {
	// 保存会话
	Save(ctx context.Context, secretKey string) error
	// 保存应用和密钥是否限制额度
	SaveIsLimitQuota(ctx context.Context, app bool, key bool)
	// 获取用户ID
	GetUserId(ctx context.Context) int
	// 获取应用ID
	GetAppId(ctx context.Context) int
	// 获取密钥
	GetSecretKey(ctx context.Context) string
	// 获取应用是否限制额度
	GetAppIsLimitQuota(ctx context.Context) bool
	// 获取密钥是否限制额度
	GetKeyIsLimitQuota(ctx context.Context) bool
	// 保存用户信息到会话中
	SaveUser(ctx context.Context, user *model.User)
	// 获取会话中的用户信息
	GetUser(ctx context.Context) *model.User
	// 保存应用信息到会话中
	SaveApp(ctx context.Context, app *model.App)
	// 获取会话中的应用信息
	GetApp(ctx context.Context) *model.App
	// 保存密钥信息到会话中
	SaveKey(ctx context.Context, key *model.Key)
	// 获取会话中的密钥信息
	GetKey(ctx context.Context) *model.Key
	// 记录错误模型代理ID到会话中
	RecordErrorModelAgent(ctx context.Context, id string)
	// 获取会话中的错误模型代理Ids
	GetErrorModelAgents(ctx context.Context) []string
	// 记录错误密钥ID到会话中
	RecordErrorKey(ctx context.Context, id string)
	// 获取会话中的错误密钥Ids
	GetErrorKeys(ctx context.Context) []string
}

func Session

func Session() ISession

type IUser

type IUser interface {
	// 根据用户ID获取用户信息
	GetUser(ctx context.Context, userId int) (*model.User, error)
	// 用户列表
	List(ctx context.Context) ([]*model.User, error)
	// 用户花费额度
	SpendQuota(ctx context.Context, userId int, spendQuota int, currentQuota int) error
	// 保存用户信息到缓存
	SaveCacheUser(ctx context.Context, user *model.User) error
	// 获取缓存中的用户信息
	GetCacheUser(ctx context.Context, userId int) (*model.User, error)
	// 更新缓存中的用户信息
	UpdateCacheUser(ctx context.Context, user *entity.User)
	// 移除缓存中的用户信息
	RemoveCacheUser(ctx context.Context, userId int)
	// 保存用户额度到缓存
	SaveCacheUserQuota(ctx context.Context, userId int, quota int) error
	// 获取缓存中的用户额度
	GetCacheUserQuota(ctx context.Context, userId int) int
	// 变更订阅
	Subscribe(ctx context.Context, msg string) error
}

func User

func User() IUser

Jump to

Keyboard shortcuts

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