Documentation
¶
Index ¶
- Constants
- func AnthropicSingleBetaMessage(c *gin.Context, resp *anthropic.BetaMessage, responseModel string) error
- func AnthropicSingleMessage(c *gin.Context, resp *anthropic.Message, responseModel string) error
- func AnthropicToOpenAIStream(c *gin.Context, req *anthropic.BetaMessageNewParams, ...) (int, int, error)
- func BuildErrorEvent(message, errorType, code string) map[string]interface{}
- func FilterOpenAIProtocolFields(extras map[string]interface{}) map[string]interface{}
- func FilterSpecialFields(extras map[string]interface{}) map[string]interface{}
- func GenerateObfuscationString() string
- func HandleAnthropic(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func HandleAnthropicBeta(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func HandleAnthropicToGoogleStreamResponse(c *gin.Context, ...) error
- func HandleAnthropicToOpenAIResponsesStream(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func HandleGoogleToAnthropicBetaStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], ...) (*protocol.TokenUsage, error)
- func HandleGoogleToAnthropicStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], ...) (*protocol.TokenUsage, error)
- func HandleGoogleToOpenAIStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], ...) error
- func HandleOpenAIChatStream(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func HandleOpenAIChatToResponsesStream(c *gin.Context, stream *openaistream.Stream[openai.ChatCompletionChunk], ...) (*protocol.TokenUsage, error)
- func HandleOpenAIResponsesStream(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func HandleOpenAIResponsesStreamToAnthropic(c *gin.Context, ...) (*protocol.TokenUsage, error)
- func HandleOpenAIToAnthropicBetaStream(c *gin.Context, req *openai.ChatCompletionNewParams, ...) (*protocol.TokenUsage, error)
- func HandleOpenAIToAnthropicStreamResponse(c *gin.Context, req *openai.ChatCompletionNewParams, ...) (*protocol.TokenUsage, error)
- func HandleOpenAIToGoogleStreamResponse(c *gin.Context, stream *openaistream.Stream[openai.ChatCompletionChunk], ...) error
- func HandleResponsesToAnthropicBetaAssembly(c *gin.Context, ...) (*protocol.TokenUsage, error)
- func HandleResponsesToAnthropicBetaStream(c *gin.Context, ...) (*protocol.TokenUsage, error)
- func HandleResponsesToAnthropicV1Assembly(c *gin.Context, ...) (*protocol.TokenUsage, error)
- func HandleResponsesToAnthropicV1Stream(c *gin.Context, ...) (*protocol.TokenUsage, error)
- func HandleResponsesToOpenAIChatStream(hc *protocol.HandleContext, ...) (*protocol.TokenUsage, error)
- func MarshalAndSendErrorEvent(c *gin.Context, message, errorType, code string)
- func NewExampleTool() openai.ChatCompletionToolUnionParam
- func OpenAISSE(c *gin.Context, v any)
- func OpenAISSEDone(c *gin.Context)
- func RegisterGuardrailsBlock(c *gin.Context, toolID string, index int, message string)
- func SendFinishEvent(c *gin.Context)
- func SendForwardingError(c *gin.Context, err error)
- func SendInternalError(c *gin.Context, errMsg string)
- func SendInvalidRequestBodyError(c *gin.Context, err error)
- func SendSSErrorEvent(c *gin.Context, message, errorType string)
- func SendSSErrorEventJSON(c *gin.Context, errorJSON []byte)
- func SendStreamingError(c *gin.Context, err error)
- type StreamEventRecorder
Constants ¶
const (
// OpenAI extra field names that map to Anthropic content blocks
OpenaiFieldReasoningContent = "reasoning_content"
)
Variables ¶
This section is empty.
Functions ¶
func AnthropicSingleBetaMessage ¶ added in v0.260414.2000
func AnthropicSingleBetaMessage(c *gin.Context, resp *anthropic.BetaMessage, responseModel string) error
AnthropicSingleBetaMessage emits a single assembled Anthropic beta message using SSE events.
func AnthropicSingleMessage ¶ added in v0.260414.2000
AnthropicSingleMessage emits a single assembled Anthropic v1 message using SSE events.
func AnthropicToOpenAIStream ¶
func AnthropicToOpenAIStream(c *gin.Context, req *anthropic.BetaMessageNewParams, stream *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion], responseModel string, disableStreamUsage bool) (int, int, error)
AnthropicToOpenAIStream processes Anthropic streaming events and converts them to OpenAI format Returns inputTokens, outputTokens, and error for usage tracking
func BuildErrorEvent ¶
BuildErrorEvent builds a standard error event map
func FilterOpenAIProtocolFields ¶
FilterOpenAIProtocolFields removes OpenAI protocol fields that should NOT appear in Anthropic message_delta. These fields are already properly handled via content_block events and should not be duplicated.
func FilterSpecialFields ¶
FilterSpecialFields removes special fields that have dedicated content blocks e.g., reasoning_content is handled as thinking block, not merged into text_delta
func GenerateObfuscationString ¶
func GenerateObfuscationString() string
GenerateObfuscationString generates a random string similar to "KOJz1A"
func HandleAnthropic ¶ added in v0.260414.2000
func HandleAnthropic(hc *protocol.HandleContext, streamResp *anthropicstream.Stream[anthropic.MessageStreamEventUnion]) (*protocol.TokenUsage, error)
HandleAnthropic handles Anthropic v1 streaming response. Returns (UsageStat, error)
func HandleAnthropicBeta ¶ added in v0.260414.2000
func HandleAnthropicBeta(hc *protocol.HandleContext, streamResp *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]) (*protocol.TokenUsage, error)
HandleAnthropicBeta handles Anthropic v1 beta streaming response. Returns (UsageStat, error)
func HandleAnthropicToGoogleStreamResponse ¶
func HandleAnthropicToGoogleStreamResponse(c *gin.Context, stream *anthropicstream.Stream[anthropic.MessageStreamEventUnion], responseModel string) error
HandleAnthropicToGoogleStreamResponse processes Anthropic streaming events and converts them to Google format
func HandleAnthropicToOpenAIResponsesStream ¶
func HandleAnthropicToOpenAIResponsesStream( hc *protocol.HandleContext, stream *anthropicstream.Stream[anthropic.MessageStreamEventUnion], responseModel string, ) (*protocol.TokenUsage, error)
HandleAnthropicToOpenAIResponsesStream converts Anthropic streaming events to OpenAI Responses API format.
Returns (UsageStat, error) for usage tracking and error handling.
func HandleGoogleToAnthropicBetaStreamResponse ¶
func HandleGoogleToAnthropicBetaStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], responseModel string) (*protocol.TokenUsage, error)
HandleGoogleToAnthropicBetaStreamResponse processes Google streaming events and converts them to Anthropic beta format. Returns UsageStat containing token usage information for tracking.
func HandleGoogleToAnthropicStreamResponse ¶
func HandleGoogleToAnthropicStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], responseModel string) (*protocol.TokenUsage, error)
HandleGoogleToAnthropicStreamResponse processes Google streaming events and converts them to Anthropic format. Returns UsageStat containing token usage information for tracking.
func HandleGoogleToOpenAIStreamResponse ¶
func HandleGoogleToOpenAIStreamResponse(c *gin.Context, stream iter.Seq2[*genai.GenerateContentResponse, error], responseModel string) error
HandleGoogleToOpenAIStreamResponse processes Google streaming events and converts them to OpenAI format
func HandleOpenAIChatStream ¶
func HandleOpenAIChatStream(hc *protocol.HandleContext, streamResp *openaistream.Stream[openai.ChatCompletionChunk], req *openai.ChatCompletionNewParams) (*protocol.TokenUsage, error)
HandleOpenAIChatStream handles OpenAI chat streaming response. Returns (UsageStat, error)
func HandleOpenAIChatToResponsesStream ¶
func HandleOpenAIChatToResponsesStream(c *gin.Context, stream *openaistream.Stream[openai.ChatCompletionChunk], responseModel string) (*protocol.TokenUsage, error)
HandleOpenAIChatToResponsesStream converts OpenAI Chat Completions streaming to Responses API format. Returns UsageStat containing token usage information for tracking.
func HandleOpenAIResponsesStream ¶
func HandleOpenAIResponsesStream(hc *protocol.HandleContext, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
HandleOpenAIResponsesStream handles OpenAI Responses API streaming response. Returns (UsageStat, error)
func HandleOpenAIResponsesStreamToAnthropic ¶
func HandleOpenAIResponsesStreamToAnthropic(c *gin.Context, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
HandleOpenAIResponsesStreamToAnthropic handles OpenAI Responses API streaming response and transforms it to Anthropic message format. This is used for ChatGPT backend API providers when the original request was in Anthropic format. Returns (TokenUsage, error)
func HandleOpenAIToAnthropicBetaStream ¶
func HandleOpenAIToAnthropicBetaStream(c *gin.Context, req *openai.ChatCompletionNewParams, stream *openaistream.Stream[openai.ChatCompletionChunk], responseModel string) (*protocol.TokenUsage, error)
HandleOpenAIToAnthropicBetaStream processes OpenAI streaming events and converts them to Anthropic beta format. Returns UsageStat containing token usage information for tracking.
func HandleOpenAIToAnthropicStreamResponse ¶
func HandleOpenAIToAnthropicStreamResponse(c *gin.Context, req *openai.ChatCompletionNewParams, stream *openaistream.Stream[openai.ChatCompletionChunk], responseModel string) (*protocol.TokenUsage, error)
HandleOpenAIToAnthropicStreamResponse processes OpenAI streaming events and converts them to Anthropic format. Returns UsageStat containing token usage information for tracking.
func HandleOpenAIToGoogleStreamResponse ¶
func HandleOpenAIToGoogleStreamResponse(c *gin.Context, stream *openaistream.Stream[openai.ChatCompletionChunk], responseModel string) error
HandleOpenAIToGoogleStreamResponse processes OpenAI streaming events and converts them to Google format This handler writes Google-format streaming responses to the gin.Context
func HandleResponsesToAnthropicBetaAssembly ¶
func HandleResponsesToAnthropicBetaAssembly(c *gin.Context, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
func HandleResponsesToAnthropicBetaStream ¶
func HandleResponsesToAnthropicBetaStream(c *gin.Context, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
HandleResponsesToAnthropicBetaStream processes OpenAI Responses API streaming events and converts them to Anthropic beta format. This is a thin wrapper that uses the shared core logic with beta event senders. Returns UsageStat containing token usage information for tracking.
func HandleResponsesToAnthropicV1Assembly ¶
func HandleResponsesToAnthropicV1Assembly(c *gin.Context, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
func HandleResponsesToAnthropicV1Stream ¶
func HandleResponsesToAnthropicV1Stream(c *gin.Context, stream *openaistream.Stream[responses.ResponseStreamEventUnion], responseModel string) (*protocol.TokenUsage, error)
HandleResponsesToAnthropicV1Stream processes OpenAI Responses API streaming events and converts them to Anthropic v1 format. This is a thin wrapper that uses the shared core logic with v1 event senders. Returns UsageStat containing token usage information for tracking.
func HandleResponsesToOpenAIChatStream ¶ added in v0.260409.1540
func HandleResponsesToOpenAIChatStream( hc *protocol.HandleContext, stream *responsesstream.Stream[responses.ResponseStreamEventUnion], responseModel string, ) (*protocol.TokenUsage, error)
HandleResponsesToOpenAIChatStream converts Responses API streaming to Chat Completions format. Returns TokenUsage containing token usage information for tracking.
func MarshalAndSendErrorEvent ¶
MarshalAndSendErrorEvent marshals and sends an error event
func NewExampleTool ¶
func NewExampleTool() openai.ChatCompletionToolUnionParam
func OpenAISSE ¶ added in v0.260414.2000
OpenAISSE marshals v to JSON and writes it as an OpenAI-style SSE data line, then flushes. MENTION: Must keep extra space after "data:" to match OpenAI wire format.
func OpenAISSEDone ¶ added in v0.260414.2000
OpenAISSEDone writes the SSE [DONE] terminator and flushes.
func RegisterGuardrailsBlock ¶
RegisterGuardrailsBlock registers a tool_use block that should be intercepted.
func SendFinishEvent ¶
SendFinishEvent sends a message_stop event to indicate completion
func SendForwardingError ¶
SendForwardingError sends an error response for request forwarding failures
func SendInternalError ¶
SendInternalError sends an error response for internal errors
func SendInvalidRequestBodyError ¶
SendInvalidRequestBodyError sends an error response for invalid request body
func SendSSErrorEvent ¶
SendSSErrorEvent sends an error event through SSE
func SendSSErrorEventJSON ¶
SendSSErrorEventJSON sends a JSON error event through SSE
func SendStreamingError ¶
SendStreamingError sends an error response for streaming request failures
Types ¶
type StreamEventRecorder ¶
type StreamEventRecorder interface {
RecordRawMapEvent(eventType string, event map[string]interface{})
}
StreamEventRecorder is an interface for recording stream events during protocol conversion
Source Files
¶
- anthropic_constant.go
- anthropic_guardrails.go
- anthropic_helper.go
- anthropic_passthrough.go
- anthropic_single_message.go
- anthropic_to_openai.go
- anthropic_to_openai_responses.go
- any_to_google.go
- google_to_any.go
- openai_chat_to_responses.go
- openai_constant.go
- openai_helper.go
- openai_passthrough.go
- openai_responses_to_chat.go
- openai_to_anthropic.go
- openai_to_anthropic_beta.go
- sse_helper.go
- tool_example.go