Documentation
¶
Index ¶
- func ParseSystemPrompt(raw json.RawMessage) (string, error)
- type ClaudeRequest
- type ClaudeResponse
- type ContentBlock
- type ImageSource
- type Message
- type Metadata
- type OutputConfig
- type ServerToolUse
- type StreamProcessor
- func (p *StreamProcessor) EmitBlock(block map[string]any) error
- func (p *StreamProcessor) EmitCitedText(text string, citations []map[string]any) error
- func (p *StreamProcessor) EmitError(err error) error
- func (p *StreamProcessor) EmitErrorType(errorType string, err error) error
- func (p *StreamProcessor) EmitServerToolUse(id string, name string, input any) error
- func (p *StreamProcessor) EmitThinking(thinking string, signature string) error
- func (p *StreamProcessor) EmitToolCall(id string, name string, arguments json.RawMessage) error
- func (p *StreamProcessor) Finish(stopReason string) error
- func (p *StreamProcessor) FinishThinking(signature string) error
- func (p *StreamProcessor) MessageID() string
- func (p *StreamProcessor) ProcessEvent(event gemini.Event) error
- func (p *StreamProcessor) SetConversationID(conversationID string)
- func (p *StreamProcessor) SetModel(model string)
- type StreamingState
- type ThinkingConfig
- type Tool
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSystemPrompt ¶
func ParseSystemPrompt(raw json.RawMessage) (string, error)
Types ¶
type ClaudeRequest ¶
type ClaudeRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
System json.RawMessage `json:"system,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
Stream bool `json:"stream"`
MaxTokens *int `json:"max_tokens,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
Thinking *ThinkingConfig `json:"thinking,omitempty"`
OutputConfig *OutputConfig `json:"output_config,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
}
type ClaudeResponse ¶
type ClaudeResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Model string `json:"model"`
Content []ContentBlock `json:"content"`
StopReason string `json:"stop_reason"`
StopSequence *string `json:"stop_sequence,omitempty"`
Usage *Usage `json:"usage,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
}
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input *map[string]interface{} `json:"input,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
Content json.RawMessage `json:"content,omitempty"`
IsError *bool `json:"is_error,omitempty"`
Source *ImageSource `json:"source,omitempty"`
Data string `json:"data,omitempty"`
Citations []map[string]any `json:"citations,omitempty"`
}
func ParseMessageContent ¶
func ParseMessageContent(raw json.RawMessage) ([]ContentBlock, string, error)
type ImageSource ¶
type Message ¶
type Message struct {
Role string `json:"role"`
Content json.RawMessage `json:"content"`
}
type OutputConfig ¶
type OutputConfig struct {
Effort string `json:"effort,omitempty"`
}
OutputConfig 表示 Claude 输出强度配置
type ServerToolUse ¶ added in v0.1.3
type ServerToolUse struct {
WebSearchRequests int `json:"web_search_requests"`
}
ServerToolUse 统计服务端工具的调用次数
type StreamProcessor ¶
type StreamProcessor struct {
// contains filtered or unexported fields
}
StreamProcessor 将规范事件编码为 Claude SSE
func NewStreamProcessor ¶
func NewStreamProcessor(model string, writer io.Writer, messageIDs ...string) *StreamProcessor
NewStreamProcessor 创建 Claude SSE 编码器
func (*StreamProcessor) EmitBlock ¶ added in v0.1.3
func (p *StreamProcessor) EmitBlock(block map[string]any) error
EmitBlock 以一对 content_block_start 与 content_block_stop 输出完整内容块,例如 web_search_tool_result
func (*StreamProcessor) EmitCitedText ¶ added in v0.1.3
func (p *StreamProcessor) EmitCitedText(text string, citations []map[string]any) error
EmitCitedText 输出一个带引用的文本块,引用以 citations_delta 先于正文发送
func (*StreamProcessor) EmitError ¶
func (p *StreamProcessor) EmitError(err error) error
EmitError 输出 Claude 流式错误
func (*StreamProcessor) EmitErrorType ¶ added in v0.1.3
func (p *StreamProcessor) EmitErrorType(errorType string, err error) error
EmitErrorType 以指定错误类型输出 Claude 流式错误
func (*StreamProcessor) EmitServerToolUse ¶ added in v0.1.3
func (p *StreamProcessor) EmitServerToolUse(id string, name string, input any) error
EmitServerToolUse 输出一次服务端工具调用块,输入以 input_json_delta 发送
func (*StreamProcessor) EmitThinking ¶
func (p *StreamProcessor) EmitThinking(thinking string, signature string) error
EmitThinking 输出带代理签名的完整思考块
func (*StreamProcessor) EmitToolCall ¶
func (p *StreamProcessor) EmitToolCall(id string, name string, arguments json.RawMessage) error
EmitToolCall 输出完整 Claude 工具调用块
func (*StreamProcessor) Finish ¶
func (p *StreamProcessor) Finish(stopReason string) error
Finish 完成 Claude SSE 消息
func (*StreamProcessor) FinishThinking ¶
func (p *StreamProcessor) FinishThinking(signature string) error
FinishThinking 完成当前思考块并输出签名
func (*StreamProcessor) MessageID ¶
func (p *StreamProcessor) MessageID() string
MessageID 返回当前 Claude 消息标识
func (*StreamProcessor) ProcessEvent ¶
func (p *StreamProcessor) ProcessEvent(event gemini.Event) error
ProcessEvent 消费一个 Gemini 规范事件
func (*StreamProcessor) SetConversationID ¶
func (p *StreamProcessor) SetConversationID(conversationID string)
SetConversationID 设置最终消息携带的显式会话标识
func (*StreamProcessor) SetModel ¶
func (p *StreamProcessor) SetModel(model string)
SetModel 设置校验后的实际模型
type StreamingState ¶
type StreamingState struct {
MessageID string
Model string
MessageStartSent bool
MessageStopSent bool
BlockIndex int
CurrentBlockType string
Usage *gemini.Usage
ConversationID string
// WebSearchRequests 为 message_delta usage.server_tool_use 的搜索次数
WebSearchRequests int
}
StreamingState 保存 Claude SSE 的输出状态
func NewStreamingState ¶
func NewStreamingState(model string) *StreamingState
NewStreamingState 创建 Claude SSE 状态
type ThinkingConfig ¶
type Tool ¶
type Tool struct {
Type *string `json:"type,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema,omitempty"`
}
func (Tool) IsWebSearch ¶
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheReadInputTokens *int `json:"cache_read_input_tokens,omitempty"`
CacheCreationInputTokens *int `json:"cache_creation_input_tokens,omitempty"`
ServerToolUse *ServerToolUse `json:"server_tool_use,omitempty"`
}