saw-go/proto/im.go

135 lines
6.4 KiB
Go
Raw Normal View History

package proto
import (
"github.com/ollama/ollama/api"
"github.com/openai/openai-go"
"gorm.io/gorm"
)
type AIQueueMessage struct {
Type string `json:"type"` //声明不同消息类型
ID uint `json:"id"` //消息id
Msg api.GenerateResponse `json:"msg"` //原始消息
}
type WSMessage struct {
Code int `json:"code"` //返回码,0表示成功 其它状态码
Type string `json:"type"` //接收及发送消息类型
2025-05-12 13:57:38 +08:00
ErrorMsg string `json:"error_msg"` //错误信息
Msg AIQueueMessage `json:"msg"` //消息内容,只进行转发,不做处理
SessionID int `json:"session_id"` //应用层会话id
ToID int `json:"to_id"` //接收者id
}
type WSMessageReq struct {
Type string `json:"type"` //接收及发送消息类型
Function string `json:"function"` //功能名称
Msg string `json:"msg"` //消息内容,只进行转发,不做处理
SessionID int `json:"session_id"` //应用层会话id
ToID int `json:"to_id"` //接收者id
ModelID uint `json:"model_id"` //模型id
IsImage bool `json:"is_image"` //是否为图片(图片消息)如果是图片消息则msg为图片消息结构为{"img_url":"","text":""}
IsFile bool `json:"is_file"` //是否为文件(文件消息)如果是文件消息则msg为文件消息结构为{"file_url":"","text":""}
IsKBase bool `json:"is_kbase"` //是否为知识库消息
KBaseID uint `json:"kbase_id"` //知识库id,为知识库消息时必传
KBaseType string `json:"kbase_type"` //知识库模式1为query 2为chat
Temperature float32 `json:"temperature"` //温度,默认0.5,核采样阈值。取值越高随机性越强,即相同的问题得到的不同答案的可能性越大
TopP float32 `json:"top_p"` //doubao 模型的top_p参数
TopK float32 `json:"top_k"` //spark 模型的top_k参数
}
type ModelParam struct {
2025-05-10 14:12:12 +08:00
Model string `json:"model"` //模型名称
Domain string `json:"domain"` //domain参数spark需要
Url string `json:"url"` //模型地址
APPID string `json:"appid"` //应用id
APISecret string `json:"apiSecret"` //应用密钥
APIKey string `json:"apiKey"` //应用key
System string `json:"system"` //系统参数
AccessKey string `json:"access_key"` //accessKey参数
2025-05-10 15:26:03 +08:00
SecretKey string `json:"secret_key"` //secretKey参数
//其他参数
Temperature float32 `json:"temperature"` //温度,默认0.5,核采样阈值。取值越高随机性越强,即相同的问题得到的不同答案的可能性越大
MaxTokens int `json:"maxTokens"` //最大生成长度,默认4096
TopK float32 `json:"topK"` //取概率最大的前k个词
TopP float32 `json:"topP"` //取
}
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
}
}
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使用数量
}
type IMParamContext struct {
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"` //模型类型
QuestionMessageID int `json:"question_message_id"` //问题消息id,用于后面的消息token消耗保存
Question string `json:"question"` //问题
Channel string `json:"channel"` //消息队列
IsHasImage bool `json:"is_has_image"` //是否有图片
}
2025-03-31 19:30:46 +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 {
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"` //问题文本
}
type SendMessageForeignAIRRequest struct {
ModelParam ModelParam `json:"model_param" form:"model_param"` //模型参数
IMParamContext IMParamContext `json:"im_param_context" form:"im_param_context"` //上下文参数
ChatCompletionMessageParamUnion []openai.ChatCompletionMessageParamUnion `json:"chat_completion_message_param_union" form:"chat_completion_message_param_union"` //消息内容
PlatForm string `json:"platform" form:"platform"` //平台名称
}
type ReceiveMessageForeignAIRRequest struct {
ModelParam ModelParam `json:"model_param" form:"model_param"` //模型参数
IMParamContext IMParamContext `json:"im_param_context" form:"im_param_context"` //上下文参数
PlatForm string `json:"platform" form:"platform"` //平台名称
ChatCompletionChunk openai.ChatCompletionChunk `json:"chat_completion_chunk" form:"chat_completion_chunk"` //消息内容
}