Merge remote-tracking branch 'yvan/main'
# Conflicts: # server/go.mod # server/go.sum
This commit is contained in:
@@ -11,6 +11,10 @@ type PetAiAssistantConversations struct {
|
||||
UserId *int `json:"userId" form:"userId" gorm:"comment:用户ID;column:user_id;size:20;" binding:"required"` //用户ID
|
||||
MessageContent *string `json:"messageContent" form:"messageContent" gorm:"comment:消息内容;column:message_content;" binding:"required"` //消息内容
|
||||
Role *string `json:"role" form:"role" gorm:"comment:发送者角色:user-用户,assistant-AI助手;column:role;size:20;" binding:"required"` //发送者角色:user-用户,assistant-AI助手
|
||||
SessionId *string `json:"sessionId" form:"sessionId" gorm:"comment:会话ID;column:session_id;size:64;"` //会话ID
|
||||
IsSensitive *bool `json:"isSensitive" form:"isSensitive" gorm:"comment:是否包含敏感词;column:is_sensitive;default:false;"` //是否包含敏感词
|
||||
TokenCount *int `json:"tokenCount" form:"tokenCount" gorm:"comment:Token消耗数量;column:token_count;default:0;"` //Token消耗数量
|
||||
ResponseTime *int `json:"responseTime" form:"responseTime" gorm:"comment:响应时间(ms);column:response_time;default:0;"` //响应时间(ms)
|
||||
}
|
||||
|
||||
// TableName petAiAssistantConversations表 PetAiAssistantConversations自定义表名 pet_ai_assistant_conversations
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
)
|
||||
|
||||
// ChatRequest 宠物助手聊天请求结构体
|
||||
type ChatRequest struct {
|
||||
Message string `json:"message" binding:"required" validate:"required,min=1,max=2000"` // 用户消息内容,必填,1-2000字符
|
||||
SessionId string `json:"sessionId" validate:"omitempty,uuid4"` // 会话ID,可选,UUID格式
|
||||
Stream bool `json:"stream"` // 是否流式响应,默认false
|
||||
Temperature float64 `json:"temperature" validate:"omitempty,min=0,max=2"` // 温度参数,控制随机性,范围0-2
|
||||
MaxTokens int `json:"maxTokens" validate:"omitempty,min=1,max=4000"` // 最大生成token数,范围1-4000
|
||||
Model string `json:"model" validate:"omitempty,min=1,max=100"` // 模型名称,可选
|
||||
TopP float64 `json:"topP" validate:"omitempty,min=0,max=1"` // 核采样参数,范围0-1
|
||||
}
|
||||
|
||||
// ChatHistoryRequest 获取聊天历史请求结构体
|
||||
type ChatHistoryRequest struct {
|
||||
SessionId string `json:"sessionId" form:"sessionId" validate:"omitempty,uuid4"` // 会话ID,可选,UUID格式
|
||||
request.PageInfo // 分页信息
|
||||
}
|
||||
|
||||
// ClearHistoryRequest 清空聊天历史请求结构体
|
||||
type ClearHistoryRequest struct {
|
||||
SessionId string `json:"sessionId" form:"sessionId" validate:"omitempty,uuid4"` // 会话ID,可选,不传则清空所有会话
|
||||
}
|
||||
|
||||
// SessionsRequest 获取会话列表请求结构体
|
||||
type SessionsRequest struct {
|
||||
request.PageInfo // 分页信息
|
||||
}
|
||||
|
||||
// StopGenerationRequest 停止生成请求结构体
|
||||
type StopGenerationRequest struct {
|
||||
RequestId string `json:"requestId" binding:"required" validate:"required,uuid4"` // 请求ID,必填,UUID格式
|
||||
}
|
||||
|
||||
// RegenerateRequest 重新生成回复请求结构体
|
||||
type RegenerateRequest struct {
|
||||
SessionId string `json:"sessionId" binding:"required" validate:"required,uuid4"` // 会话ID,必填
|
||||
MessageId uint `json:"messageId" binding:"required" validate:"required,min=1"` // 要重新生成的消息ID
|
||||
Temperature float64 `json:"temperature" validate:"omitempty,min=0,max=2"` // 温度参数
|
||||
MaxTokens int `json:"maxTokens" validate:"omitempty,min=1,max=4000"` // 最大token数
|
||||
}
|
||||
|
||||
// FeedbackRequest 用户反馈请求结构体
|
||||
type FeedbackRequest struct {
|
||||
MessageId uint `json:"messageId" binding:"required" validate:"required,min=1"` // 消息ID,必填
|
||||
FeedbackType string `json:"feedbackType" binding:"required" validate:"required,oneof=like dislike"` // 反馈类型:like/dislike
|
||||
Comment string `json:"comment" validate:"omitempty,max=500"` // 反馈评论,可选,最多500字符
|
||||
}
|
||||
|
||||
// ExportHistoryRequest 导出聊天历史请求结构体
|
||||
type ExportHistoryRequest struct {
|
||||
SessionId string `json:"sessionId" form:"sessionId" validate:"omitempty,uuid4"` // 会话ID,可选
|
||||
Format string `json:"format" form:"format" validate:"omitempty,oneof=json txt markdown"` // 导出格式:json/txt/markdown
|
||||
StartTime string `json:"startTime" form:"startTime" validate:"omitempty,datetime=2006-01-02"` // 开始时间,可选
|
||||
EndTime string `json:"endTime" form:"endTime" validate:"omitempty,datetime=2006-01-02"` // 结束时间,可选
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/pet"
|
||||
)
|
||||
|
||||
// ChatResponse 宠物助手聊天响应结构体
|
||||
type ChatResponse struct {
|
||||
ID uint `json:"id"` // 消息ID
|
||||
Message string `json:"message"` // AI回复消息内容
|
||||
SessionId string `json:"sessionId"` // 会话ID
|
||||
IsSensitive bool `json:"isSensitive"` // 是否包含敏感词
|
||||
TokenCount int `json:"tokenCount"` // Token消耗数量
|
||||
ResponseTime int64 `json:"responseTime"` // 响应时间(毫秒)
|
||||
RequestId string `json:"requestId,omitempty"` // 请求ID,用于流式响应管理
|
||||
Model string `json:"model,omitempty"` // 使用的模型名称
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
FinishReason string `json:"finishReason,omitempty"` // 完成原因:stop/length/content_filter
|
||||
}
|
||||
|
||||
// StreamEvent 流式事件结构体
|
||||
type StreamEvent struct {
|
||||
Event string `json:"event"` // 事件类型: message, error, done, start
|
||||
Data interface{} `json:"data"` // 事件数据
|
||||
}
|
||||
|
||||
// StreamMessageData 流式消息数据结构体
|
||||
type StreamMessageData struct {
|
||||
Delta string `json:"delta"` // 增量消息内容
|
||||
SessionId string `json:"sessionId"` // 会话ID
|
||||
RequestId string `json:"requestId"` // 请求ID
|
||||
}
|
||||
|
||||
// StreamErrorData 流式错误数据结构体
|
||||
type StreamErrorData struct {
|
||||
Error string `json:"error"` // 错误信息
|
||||
Code string `json:"code"` // 错误代码
|
||||
RequestId string `json:"requestId"` // 请求ID
|
||||
}
|
||||
|
||||
// StreamDoneData 流式完成数据结构体
|
||||
type StreamDoneData struct {
|
||||
Message string `json:"message"` // 完整消息内容
|
||||
SessionId string `json:"sessionId"` // 会话ID
|
||||
RequestId string `json:"requestId"` // 请求ID
|
||||
TokenCount int `json:"tokenCount"` // Token消耗数量
|
||||
ResponseTime int64 `json:"responseTime"` // 响应时间(毫秒)
|
||||
IsSensitive bool `json:"isSensitive"` // 是否包含敏感词
|
||||
FinishReason string `json:"finishReason"` // 完成原因
|
||||
}
|
||||
|
||||
// ChatHistoryResponse 聊天历史响应结构体
|
||||
type ChatHistoryResponse struct {
|
||||
List []pet.PetAiAssistantConversations `json:"list"` // 对话记录列表
|
||||
Total int64 `json:"total"` // 总记录数
|
||||
Page int `json:"page"` // 当前页码
|
||||
PageSize int `json:"pageSize"` // 每页大小
|
||||
}
|
||||
|
||||
// SessionInfo 会话信息结构体
|
||||
type SessionInfo struct {
|
||||
SessionId string `json:"sessionId"` // 会话ID
|
||||
LastUpdated time.Time `json:"lastUpdated"` // 最后更新时间
|
||||
MessageCount int `json:"messageCount"` // 消息数量
|
||||
FirstMessage string `json:"firstMessage"` // 第一条消息内容(用作会话标题)
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
// SessionsResponse 会话列表响应结构体
|
||||
type SessionsResponse struct {
|
||||
List []SessionInfo `json:"list"` // 会话列表
|
||||
Total int64 `json:"total"` // 总会话数
|
||||
Page int `json:"page"` // 当前页码
|
||||
PageSize int `json:"pageSize"` // 每页大小
|
||||
}
|
||||
|
||||
// TokenUsage Token使用情况结构体
|
||||
type TokenUsage struct {
|
||||
PromptTokens int `json:"promptTokens"` // 输入token数
|
||||
CompletionTokens int `json:"completionTokens"` // 输出token数
|
||||
TotalTokens int `json:"totalTokens"` // 总token数
|
||||
}
|
||||
|
||||
// ModelInfo 模型信息结构体
|
||||
type ModelInfo struct {
|
||||
Name string `json:"name"` // 模型名称
|
||||
Description string `json:"description"` // 模型描述
|
||||
MaxTokens int `json:"maxTokens"` // 最大token数
|
||||
Available bool `json:"available"` // 是否可用
|
||||
}
|
||||
|
||||
// ModelsResponse 可用模型列表响应结构体
|
||||
type ModelsResponse struct {
|
||||
Models []ModelInfo `json:"models"` // 模型列表
|
||||
}
|
||||
|
||||
// StatsResponse 统计信息响应结构体
|
||||
type StatsResponse struct {
|
||||
TotalSessions int64 `json:"totalSessions"` // 总会话数
|
||||
TotalMessages int64 `json:"totalMessages"` // 总消息数
|
||||
TotalTokens int64 `json:"totalTokens"` // 总token消耗
|
||||
LastChatTime *time.Time `json:"lastChatTime"` // 最后聊天时间
|
||||
AverageResponse float64 `json:"averageResponse"` // 平均响应时间(毫秒)
|
||||
SensitiveCount int64 `json:"sensitiveCount"` // 敏感词触发次数
|
||||
PopularQuestions []string `json:"popularQuestions"` // 热门问题
|
||||
}
|
||||
|
||||
// ExportResponse 导出响应结构体
|
||||
type ExportResponse struct {
|
||||
FileName string `json:"fileName"` // 文件名
|
||||
FileSize int64 `json:"fileSize"` // 文件大小(字节)
|
||||
DownloadUrl string `json:"downloadUrl"` // 下载链接
|
||||
ExpiresAt int64 `json:"expiresAt"` // 过期时间戳
|
||||
}
|
||||
|
||||
// HealthResponse 健康检查响应结构体
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status"` // 服务状态:healthy/unhealthy
|
||||
LLMService string `json:"llmService"` // LLM服务状态
|
||||
SensitiveFilter string `json:"sensitiveFilter"` // 敏感词过滤状态
|
||||
Database string `json:"database"` // 数据库状态
|
||||
LastChecked time.Time `json:"lastChecked"` // 最后检查时间
|
||||
ResponseTime int64 `json:"responseTime"` // 响应时间(毫秒)
|
||||
ActiveSessions int `json:"activeSessions"` // 活跃会话数
|
||||
QueuedRequests int `json:"queuedRequests"` // 排队请求数
|
||||
}
|
||||
Reference in New Issue
Block a user