refactor: refactor chat_handler, add support for Azure and ChatGLM

This commit is contained in:
RockYang
2023-09-04 06:43:15 +08:00
parent d06f94bddd
commit 0cc9cf8b45
34 changed files with 1212 additions and 513 deletions

View File

@@ -6,8 +6,9 @@ type ApiRequest struct {
Temperature float32 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
Stream bool `json:"stream"`
Messages []interface{} `json:"messages"`
Functions []Function `json:"functions"`
Messages []interface{} `json:"messages,omitempty"`
Prompt []interface{} `json:"prompt,omitempty"` // 兼容 ChatGLM
Functions []Function `json:"functions,omitempty"`
}
type Message struct {
@@ -34,12 +35,18 @@ type Delta struct {
// ChatSession 聊天会话对象
type ChatSession struct {
SessionId string `json:"session_id"`
ClientIP string `json:"client_ip"` // 客户端 IP
Username string `json:"username"` // 当前登录的 username
UserId uint `json:"user_id"` // 当前登录的 user ID
ChatId string `json:"chat_id"` // 客户端聊天会话 ID, 多会话模式专用字段
Model string `json:"model"` // GPT 模型
SessionId string `json:"session_id"`
ClientIP string `json:"client_ip"` // 客户端 IP
Username string `json:"username"` // 当前登录的 username
UserId uint `json:"user_id"` // 当前登录的 user ID
ChatId string `json:"chat_id"` // 客户端聊天会话 ID, 多会话模式专用字段
Model ChatModel `json:"model"` // GPT 模型
}
type ChatModel struct {
Id uint `json:"id"`
Platform Platform `json:"platform"`
Value string `json:"value"`
}
type MjTask struct {

View File

@@ -64,6 +64,7 @@ type RedisConfig struct {
Host string
Port int
Password string
DB int
}
func (c RedisConfig) Url() string {
@@ -99,14 +100,31 @@ type Session struct {
// ChatConfig 系统默认的聊天配置
type ChatConfig struct {
ApiURL string `json:"api_url,omitempty"`
Model string `json:"model"` // 默认模型
Temperature float32 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
EnableContext bool `json:"enable_context"` // 是否开启聊天上下文
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
ApiKey string `json:"api_key"`
ContextDeep int `json:"context_deep"` // 上下文深度
OpenAI ModelAPIConfig `json:"open_ai"`
Azure ModelAPIConfig `json:"azure"`
ChatGML ModelAPIConfig `json:"chat_gml"`
EnableContext bool `json:"enable_context"` // 是否开启聊天上下文
EnableHistory bool `json:"enable_history"` // 是否允许保存聊天记录
ContextDeep int `json:"context_deep"` // 上下文深度
}
type Platform string
const OpenAI = Platform("OpenAI")
const Azure = Platform("Azure")
const ChatGML = Platform("ChatGML")
// UserChatConfig 用户的聊天配置
type UserChatConfig struct {
ApiKeys map[Platform]string
}
type ModelAPIConfig struct {
ApiURL string `json:"api_url,omitempty"`
Temperature float32 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
ApiKey string `json:"api_key"`
}
type SystemConfig struct {
@@ -115,6 +133,8 @@ type SystemConfig struct {
Models []string `json:"models"`
UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用
InitImgCalls int `json:"init_img_calls"`
VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数
EnabledRegister bool `json:"enabled_register"`
EnabledMsgService bool `json:"enabled_msg_service"`
EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能
}

View File

@@ -87,11 +87,15 @@ var InnerFunctions = []Function{
},
"ar": {
Type: "string",
Description: "图片长宽比,如 --ar 4:3",
Description: "图片长宽比,默认值 16:9",
},
"niji": {
Type: "string",
Description: "动漫模型版本,例如 --niji 5",
Description: "动漫模型版本,默认值空",
},
"v": {
Type: "string",
Description: "模型版本,默认值: 5.2",
},
},
Required: []string{},