Documentation
¶
Overview ¶
Package claude provides request translation functionality for Claude API. It handles parsing and transforming Claude API requests into the internal client format, extracting model information, system instructions, message contents, and tool declarations. The package also performs JSON data cleaning and transformation to ensure compatibility between Claude API format and the internal client's expected format.
Package claude provides response translation functionality for Claude API. This package handles the conversion of backend client responses into Claude-compatible Server-Sent Events (SSE) format, implementing a sophisticated state machine that manages different response types including text content, thinking processes, and function calls. The translation ensures proper sequencing of SSE events and maintains state across multiple response chunks to provide a seamless streaming experience.
Index ¶
- func ClaudeTokenCount(ctx context.Context, count int64) string
- func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool) []byte
- func ConvertGeminiResponseToClaude(_ context.Context, _ string, ...) []string
- func ConvertGeminiResponseToClaudeNonStream(_ context.Context, _ string, ...) string
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertClaudeRequestToGemini ¶
ConvertClaudeRequestToGemini parses a Claude API request and returns a complete Gemini CLI request body (as JSON bytes) ready to be sent via SendRawMessageStream. All JSON transformations are performed using gjson/sjson.
Parameters:
- modelName: The name of the model.
- rawJSON: The raw JSON request from the Claude API.
- stream: A boolean indicating if the request is for a streaming response.
Returns:
- []byte: The transformed request in Gemini CLI format.
func ConvertGeminiResponseToClaude ¶
func ConvertGeminiResponseToClaude(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertGeminiResponseToClaude performs sophisticated streaming response format conversion. This function implements a complex state machine that translates backend client responses into Claude-compatible Server-Sent Events (SSE) format. It manages different response types and handles state transitions between content blocks, thinking processes, and function calls.
Response type states: 0=none, 1=content, 2=thinking, 3=function The function maintains state across multiple calls to ensure proper SSE event sequencing.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the Gemini API.
- param: A pointer to a parameter object for the conversion.
Returns:
- []string: A slice of strings, each containing a Claude-compatible JSON response.
func ConvertGeminiResponseToClaudeNonStream ¶
func ConvertGeminiResponseToClaudeNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string
ConvertGeminiResponseToClaudeNonStream converts a non-streaming Gemini response to a non-streaming Claude response.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the Gemini API.
- param: A pointer to a parameter object for the conversion.
Returns:
- string: A Claude-compatible JSON response.