pet-ai/server/plugin/volcengine/model/response/llm.go

67 lines
2.5 KiB
Go

package response
import "time"
// Message 聊天消息结构体
type Message struct {
Role string `json:"role"` // 角色: system, user, assistant
Content string `json:"content"` // 消息内容
}
// Choice 响应选择结构体
type Choice struct {
Index int `json:"index"` // 选择索引
Message Message `json:"message,omitempty"` // 完整响应消息(非流式)
Delta Message `json:"delta,omitempty"` // 增量消息(流式)
FinishReason string `json:"finish_reason,omitempty"` // 结束原因: stop, length, content_filter
}
// Usage 使用量统计结构体
type Usage struct {
PromptTokens int `json:"prompt_tokens"` // 输入token数
CompletionTokens int `json:"completion_tokens"` // 输出token数
TotalTokens int `json:"total_tokens"` // 总token数
}
// APIError API错误结构体
type APIError struct {
Code string `json:"code"` // 错误代码
Message string `json:"message"` // 错误消息
Type string `json:"type"` // 错误类型
}
// ChatResponse 聊天响应结构体
type ChatResponse struct {
ID string `json:"id"` // 响应ID
Object string `json:"object"` // 对象类型: chat.completion 或 chat.completion.chunk
Created int64 `json:"created"` // 创建时间戳
Model string `json:"model"` // 使用的模型
Choices []Choice `json:"choices"` // 响应选择列表
Usage *Usage `json:"usage,omitempty"` // 使用量统计(非流式响应)
Error *APIError `json:"error,omitempty"` // 错误信息
}
// StopResponse 停止生成响应结构体
type StopResponse struct {
Success bool `json:"success"` // 是否成功停止
Message string `json:"message"` // 响应消息
RequestID string `json:"request_id"` // 请求ID
StoppedAt int64 `json:"stopped_at"` // 停止时间戳
}
// StreamEvent 流式事件结构体
type StreamEvent struct {
Event string `json:"event"` // 事件类型: message, error, done
Data ChatResponse `json:"data"` // 事件数据
}
// ChatSession 聊天会话管理结构体(用于内部管理)
type ChatSession struct {
RequestID string `json:"request_id"` // 请求ID
UserID uint `json:"user_id"` // 用户ID
Model string `json:"model"` // 使用的模型
StartTime time.Time `json:"start_time"` // 开始时间
IsStreaming bool `json:"is_streaming"` // 是否流式响应
Status string `json:"status"` // 状态: running, completed, stopped, error
}