ai/config.go
2024-11-03 11:30:14 +08:00

166 lines
3.2 KiB
Go

package ai
import (
"github.com/ssgo/u"
)
var confAes = u.NewAes([]byte("?GQ$0K0GgLdO=f+~L68PLm$uhKr4'=tV"), []byte("VFs7@sK61cj^f?HZ"))
var keysIsSet = false
func SetSSKey(key, iv []byte) {
if !keysIsSet {
confAes = u.NewAes(key, iv)
keysIsSet = true
}
}
const (
TypeText = "text"
TypeImage = "image"
TypeVideo = "video"
RoleSystem = "system"
RoleUser = "user"
RoleAssistant = "assistant"
RoleTool = "tool"
ToolFunction = "function"
ToolRetrieval = "retrieval"
ToolWebSearch = "webSearch"
ToolCodeInterpreter = "codeInterpreter"
ToolDrawingTool = "drawingTool"
ToolWebBrowser = "webBrowser"
)
type AIConfig struct {
ApiKey string
Endpoint string
Extra map[string]any
}
type AILoadConfig struct {
Agent string
ApiKey string
apiKey string
Endpoint string
Chat map[string]*ChatConfig
Embedding map[string]*EmbeddingConfig
Image map[string]*ImageConfig
Video map[string]*VideoConfig
Edit map[string]*map[string]any
Scan map[string]*map[string]any
Asr map[string]*AsrConfig
Tts map[string]*TtsConfig
Extra map[string]any
}
type ChatConfig struct {
Model string
MaxTokens int
Temperature float64
TopP float64
Tools map[string]any
SystemPrompt string
Extra map[string]any
}
type ChatMessage struct {
Role string
Contents []ChatMessageContent
}
type ChatMessageContent struct {
Type string // text, image, audio, video
Content string
}
type ChatResult struct {
Result string
AskTokens int64
AnswerTokens int64
TotalTokens int64
UsedTime int64
}
type EmbeddingConfig struct {
Model string
Extra map[string]any
}
type EmbeddingResult struct {
Result []byte
AskTokens int64
AnswerTokens int64
TotalTokens int64
UsedTime int64
}
type ImageConfig struct {
Prompt string
GenerateCount int
Model string
SystemPrompt string
NegativePrompt string
Style string
Quality string
Ref []string
Cref float32 // 角色参考权重 0~1
Sref float32 // 风格参考权重 0~1
Scale float32 // 影响文本描述的程度 0~1
Steps int // 采样步数 1~50
Width int // 图片宽度
Height int // 图片高度
Extra map[string]any
}
type ImageResult struct {
Results []string
UsedTime int64
}
type StringResult struct {
Result string
UsedTime int64
}
type VideoConfig struct {
Prompt string
GenerateCount int
Model string
SystemPrompt string
NegativePrompt string
Ref []string
Width int
Height int
Extra map[string]any
}
type VideoResult struct {
Results []string
Previews []string
IsProcessing bool
UsedTime int64
}
type ScanResult struct {
Result string
Detail map[string]any
UsedTime int64
}
type AsrConfig struct {
Uid string
Format string
Codec string
Rate int
Bits int
Channel int
Language string
Itn bool
Punc bool
Ddc bool
Extra map[string]any
}
type TtsConfig struct {
Extra map[string]any
}