65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
// Filename: internal/models/request.go
|
|
package models
|
|
|
|
// GeminiRequest 对应客户端发来的JSON请求体
|
|
type GeminiRequest struct {
|
|
Contents []GeminiContent `json:"contents"`
|
|
GenerationConfig GenerationConfig `json:"generationConfig,omitempty"`
|
|
SafetySettings []SafetySetting `json:"safetySettings,omitempty"`
|
|
Tools []Tool `json:"tools,omitempty"`
|
|
}
|
|
|
|
// GeminiContent 包含角色和内容部分
|
|
type GeminiContent struct {
|
|
Role string `json:"role,omitempty"`
|
|
Parts []Part `json:"parts"`
|
|
}
|
|
|
|
// Part 代表内容的一个组成部分 (文本或内联数据)
|
|
type Part struct {
|
|
Text string `json:"text,omitempty"`
|
|
InlineData *InlineData `json:"inlineData,omitempty"`
|
|
}
|
|
|
|
// InlineData 用于多模态输入,如图像
|
|
type InlineData struct {
|
|
MimeType string `json:"mimeType"`
|
|
Data string `json:"data"` // Base64-encoded data
|
|
}
|
|
|
|
// GenerationConfig 控制模型的生成行为
|
|
type GenerationConfig struct {
|
|
Temperature float32 `json:"temperature,omitempty"`
|
|
TopP float32 `json:"topP,omitempty"`
|
|
TopK int `json:"topK,omitempty"`
|
|
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
|
StopSequences []string `json:"stopSequences,omitempty"`
|
|
}
|
|
|
|
// SafetySetting 定义安全过滤的阈值
|
|
type SafetySetting struct {
|
|
Category string `json:"category"`
|
|
Threshold string `json:"threshold"`
|
|
}
|
|
|
|
// Tool 定义模型可以调用的外部工具
|
|
type Tool struct {
|
|
FunctionDeclarations any `json:"functionDeclarations,omitempty"`
|
|
}
|
|
|
|
// ========= 用于智能网关流式响应解析的模型 =========
|
|
// GeminiSSEPayload 是用于解析SSE(Server-Sent Events)事件中data字段的结构体
|
|
// 它代表了从上游接收到的一个数据块。
|
|
type GeminiSSEPayload struct {
|
|
Candidates []*Candidate `json:"candidates"`
|
|
}
|
|
|
|
// Candidate 包含了模型生成的内容和会话的结束原因
|
|
type Candidate struct {
|
|
// Content 里面包含了本次返回的具体文本内容
|
|
Content *GeminiContent `json:"content"`
|
|
// FinishReason 告知我们流结束的原因,例如 "STOP", "MAX_TOKENS" 等。
|
|
// 这是我们智能重试逻辑判断的核心依据。
|
|
FinishReason string `json:"finishReason"`
|
|
}
|