 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package claude provides request translation functionality for Anthropic to OpenAI API. It handles parsing and transforming Anthropic API requests into OpenAI Chat Completions API format, extracting model information, system instructions, message contents, and tool declarations. The package performs JSON data transformation to ensure compatibility between Anthropic API format and OpenAI API's expected format.
Package claude provides response translation functionality for OpenAI to Anthropic API. This package handles the conversion of OpenAI Chat Completions API responses into Anthropic API-compatible JSON format, transforming streaming events and non-streaming responses into the format expected by Anthropic API clients. It supports both streaming and non-streaming modes, handling text content, tool calls, and usage metadata appropriately.
Index ¶
- func ClaudeTokenCount(ctx context.Context, count int64) string
- func ConvertClaudeRequestToOpenAI(modelName string, inputRawJSON []byte, stream bool) []byte
- func ConvertOpenAIResponseToClaude(_ context.Context, _ string, ...) []string
- func ConvertOpenAIResponseToClaudeNonStream(_ context.Context, _ string, ...) string
- type ConvertOpenAIResponseToAnthropicParams
- type ToolCallAccumulator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaudeTokenCount ¶ added in v6.2.33
func ConvertClaudeRequestToOpenAI ¶
ConvertClaudeRequestToOpenAI parses and transforms an Anthropic API request into OpenAI Chat Completions API format. It extracts the model name, system instruction, message contents, and tool declarations from the raw JSON request and returns them in the format expected by the OpenAI API.
func ConvertOpenAIResponseToClaude ¶
func ConvertOpenAIResponseToClaude(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertOpenAIResponseToClaude converts OpenAI streaming response format to Anthropic API format. This function processes OpenAI streaming chunks and transforms them into Anthropic-compatible JSON responses. It handles text content, tool calls, and usage metadata, outputting responses that match the Anthropic API format.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the OpenAI API.
- param: A pointer to a parameter object for the conversion.
Returns:
- []string: A slice of strings, each containing an Anthropic-compatible JSON response.
func ConvertOpenAIResponseToClaudeNonStream ¶
func ConvertOpenAIResponseToClaudeNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string
ConvertOpenAIResponseToClaudeNonStream converts a non-streaming OpenAI response to a non-streaming Anthropic response.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the OpenAI API.
- param: A pointer to a parameter object for the conversion.
Returns:
- string: An Anthropic-compatible JSON response.
Types ¶
type ConvertOpenAIResponseToAnthropicParams ¶
type ConvertOpenAIResponseToAnthropicParams struct {
	MessageID string
	Model     string
	CreatedAt int64
	// Content accumulator for streaming
	ContentAccumulator strings.Builder
	// Tool calls accumulator for streaming
	ToolCallsAccumulator map[int]*ToolCallAccumulator
	// Track if text content block has been started
	TextContentBlockStarted bool
	// Track finish reason for later use
	FinishReason string
	// Track if content blocks have been stopped
	ContentBlocksStopped bool
	// Track if message_delta has been sent
	MessageDeltaSent bool
	// Track if message_start has been sent
	MessageStarted bool
}
    ConvertOpenAIResponseToAnthropicParams holds parameters for response conversion