2025-03-22 15:39:13 +08:00
|
|
|
|
package proto
|
|
|
|
|
|
|
2025-03-25 13:26:51 +08:00
|
|
|
|
import (
|
|
|
|
|
|
"github.com/ollama/ollama/api"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
)
|
2025-03-22 17:11:42 +08:00
|
|
|
|
|
2025-03-22 15:39:13 +08:00
|
|
|
|
type AIQueueMessage struct {
|
2025-03-22 17:11:42 +08:00
|
|
|
|
Type string `json:"type"` //声明不同消息类型
|
|
|
|
|
|
ID uint `json:"id"` //消息id
|
|
|
|
|
|
Msg api.GenerateResponse `json:"msg"` //原始消息
|
2025-03-22 15:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type WSMessage struct {
|
2025-03-22 17:11:42 +08:00
|
|
|
|
Type string `json:"type"` //接收及发送消息类型
|
|
|
|
|
|
Msg AIQueueMessage `json:"msg"` //消息内容,只进行转发,不做处理
|
|
|
|
|
|
SessionID int `json:"session_id"` //应用层会话id
|
|
|
|
|
|
ToID int `json:"to_id"` //接收者id
|
2025-03-22 15:39:13 +08:00
|
|
|
|
}
|
2025-03-22 15:44:19 +08:00
|
|
|
|
|
2025-03-22 17:11:42 +08:00
|
|
|
|
type WSMessageReq struct {
|
|
|
|
|
|
Type string `json:"type"` //接收及发送消息类型
|
2025-03-24 13:36:42 +08:00
|
|
|
|
Function string `json:"function"` //功能名称
|
2025-03-22 17:11:42 +08:00
|
|
|
|
Msg string `json:"msg"` //消息内容,只进行转发,不做处理
|
|
|
|
|
|
SessionID int `json:"session_id"` //应用层会话id
|
|
|
|
|
|
ToID int `json:"to_id"` //接收者id
|
2025-03-31 14:11:32 +08:00
|
|
|
|
ModelID uint `json:"model_id"` //模型id
|
2025-03-31 19:30:46 +08:00
|
|
|
|
IsImage bool `json:"is_image"` //是否为图片(图片消息),如果是图片消息,则msg为图片消息结构为{"img_url":"","text":""}
|
2025-04-07 18:00:24 +08:00
|
|
|
|
IsFile bool `json:"is_file"` //是否为文件(文件消息),如果是文件消息,则msg为文件消息结构为{"file_url":"","text":""}
|
2025-04-09 14:53:16 +08:00
|
|
|
|
IsKBase bool `json:"is_kbase"` //是否为知识库消息
|
|
|
|
|
|
KBaseID uint `json:"kbase_id"` //知识库id,为知识库消息时必传
|
2025-03-22 17:11:42 +08:00
|
|
|
|
}
|
2025-03-24 14:47:53 +08:00
|
|
|
|
|
|
|
|
|
|
type ModelParam struct {
|
|
|
|
|
|
Model string `json:"model"` //模型名称
|
2025-03-24 19:57:28 +08:00
|
|
|
|
Domain string `json:"domain"` //domain参数,spark需要
|
2025-03-24 14:47:53 +08:00
|
|
|
|
Url string `json:"url"` //模型地址
|
|
|
|
|
|
APPID string `json:"appid"` //应用id
|
|
|
|
|
|
APISecret string `json:"apiSecret"` //应用密钥
|
|
|
|
|
|
APIKey string `json:"apiKey"` //应用key
|
2025-03-28 10:51:56 +08:00
|
|
|
|
System string `json:"system"` //
|
|
|
|
|
|
//其他参数
|
|
|
|
|
|
Temperature float64 `json:"temperature"` //温度,默认0.5,核采样阈值。取值越高随机性越强,即相同的问题得到的不同答案的可能性越大
|
|
|
|
|
|
MaxTokens int `json:"maxTokens"` //最大生成长度,默认4096
|
|
|
|
|
|
TopK float64 `json:"topK"` //取概率最大的前k个词
|
|
|
|
|
|
TopP float64 `json:"topP"` //取
|
2025-03-24 14:47:53 +08:00
|
|
|
|
}
|
2025-03-25 13:26:51 +08:00
|
|
|
|
|
2025-03-28 16:08:01 +08:00
|
|
|
|
func (m *ModelParam) SetDefaultParams() {
|
|
|
|
|
|
if m.Temperature == 0 {
|
|
|
|
|
|
m.Temperature = DefaultTemperature
|
|
|
|
|
|
}
|
|
|
|
|
|
if m.MaxTokens == 0 {
|
|
|
|
|
|
m.MaxTokens = DefaultMaxTokens
|
|
|
|
|
|
}
|
|
|
|
|
|
if m.TopK == 0 {
|
|
|
|
|
|
m.TopK = DefaultTopK
|
|
|
|
|
|
}
|
|
|
|
|
|
if m.TopP == 0 {
|
|
|
|
|
|
m.TopP = DefaultTopP
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 13:26:51 +08:00
|
|
|
|
type SessionResponse struct {
|
|
|
|
|
|
gorm.Model
|
2025-03-30 14:33:52 +08:00
|
|
|
|
UserID int `gorm:"column:user_id"` //只能由用户创建
|
|
|
|
|
|
Name string `gorm:"column:name"`
|
|
|
|
|
|
Context []int `gorm:"column:context;type:json"` //会话上下文
|
|
|
|
|
|
MsgCount int `gorm:"column:msg_count"` //消息数量
|
|
|
|
|
|
TokenUsage uint `gorm:"column:token_usage"` //token使用数量
|
2025-03-25 13:26:51 +08:00
|
|
|
|
}
|
2025-03-28 11:23:45 +08:00
|
|
|
|
|
|
|
|
|
|
type IMParamContext struct {
|
2025-04-01 14:28:12 +08:00
|
|
|
|
UserID int `json:"user_id"` //用户id
|
|
|
|
|
|
SessionID int `json:"session_id"` //会话id
|
|
|
|
|
|
FunctionID int `json:"function_id"` //功能id
|
|
|
|
|
|
ModelID int `json:"model_id"` //模型id
|
|
|
|
|
|
ModelType string `json:"model_type"` //模型类型
|
|
|
|
|
|
Question string `json:"question"` //问题
|
|
|
|
|
|
Channel string `json:"channel"` //消息队列
|
|
|
|
|
|
IsHasImage bool `json:"is_has_image"` //是否有图片
|
2025-03-28 11:23:45 +08:00
|
|
|
|
}
|
2025-03-31 19:30:46 +08:00
|
|
|
|
|
2025-04-01 19:36:29 +08:00
|
|
|
|
type ImageMsgContent struct {
|
|
|
|
|
|
ImgName string `json:"img_name"` //图片名称
|
|
|
|
|
|
ImgUrl string `json:"img_url"` //图片url
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-31 19:30:46 +08:00
|
|
|
|
// 用户向模型发送图片的消息结构
|
|
|
|
|
|
type UserImageMsg struct {
|
2025-04-01 19:36:29 +08:00
|
|
|
|
ImageContent []ImageMsgContent `json:"image_content"` //图片内容
|
|
|
|
|
|
Text string `json:"text"` //问题文本
|
2025-03-31 19:30:46 +08:00
|
|
|
|
}
|
2025-04-07 17:34:03 +08:00
|
|
|
|
|
|
|
|
|
|
type UserFileResponse struct {
|
|
|
|
|
|
ID int `json:"ID"` //文件ID
|
|
|
|
|
|
FileID int `json:"FileID"` //文件ID
|
|
|
|
|
|
UserFileName string `json:"UserFileName"` //用户文件名称
|
|
|
|
|
|
FileStoreName string `json:"file_store_name"` //文件存储名称
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type FileMessageContent struct {
|
|
|
|
|
|
FileContent UserFileResponse `json:"file_content"` //文件内容
|
|
|
|
|
|
FileType string `json:"file_type"` //文件类型
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type UserFileMessage struct {
|
|
|
|
|
|
FileContent []FileMessageContent `json:"file_content"` //文件内容
|
|
|
|
|
|
Text string `json:"text"` //问题文本
|
|
|
|
|
|
}
|