llm,doc
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package request
|
||||
|
||||
// Message 聊天消息结构体
|
||||
type Message struct {
|
||||
Role string `json:"role" form:"role" binding:"required"` // 角色: system, user, assistant
|
||||
Content string `json:"content" form:"content" binding:"required"` // 消息内容
|
||||
}
|
||||
|
||||
// ChatRequest 聊天请求结构体
|
||||
type ChatRequest struct {
|
||||
Messages []Message `json:"messages" form:"messages" binding:"required"` // 对话消息列表
|
||||
Model string `json:"model" form:"model"` // 模型名称,如果为空则使用默认模型
|
||||
Stream bool `json:"stream" form:"stream"` // 是否流式响应,默认false
|
||||
Temperature float64 `json:"temperature" form:"temperature"` // 温度参数,控制随机性,范围0-1
|
||||
MaxTokens int `json:"max_tokens" form:"max_tokens"` // 最大生成token数
|
||||
TopP float64 `json:"top_p" form:"top_p"` // 核采样参数
|
||||
RequestID string `json:"request_id,omitempty" form:"request_id,omitempty"` // 请求ID,用于流式响应管理
|
||||
}
|
||||
|
||||
// StopRequest 停止生成请求结构体
|
||||
type StopRequest struct {
|
||||
RequestID string `json:"request_id" form:"request_id" binding:"required"` // 要停止的请求ID
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user