Documentation
¶
Index ¶
- func ForwardAnthropicV1(fc *ForwardContext, wrapper *client.AnthropicClient, ...) (*anthropic.Message, context.CancelFunc, error)
- func ForwardAnthropicV1Beta(fc *ForwardContext, wrapper *client.AnthropicClient, ...) (*anthropic.BetaMessage, context.CancelFunc, error)
- func ForwardAnthropicV1BetaStream(fc *ForwardContext, wrapper *client.AnthropicClient, ...) (*anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion], ...)
- func ForwardAnthropicV1Stream(fc *ForwardContext, wrapper *client.AnthropicClient, ...) (*anthropicstream.Stream[anthropic.MessageStreamEventUnion], context.CancelFunc, ...)
- func ForwardGoogle(fc *ForwardContext, wrapper *client.GoogleClient, model string, ...) (*genai.GenerateContentResponse, context.CancelFunc, error)
- func ForwardGoogleStream(fc *ForwardContext, wrapper *client.GoogleClient, model string, ...) (iter.Seq2[*genai.GenerateContentResponse, error], context.CancelFunc, error)
- func ForwardOpenAIChat(fc *ForwardContext, wrapper *client.OpenAIClient, ...) (*openai.ChatCompletion, context.CancelFunc, error)
- func ForwardOpenAIChatStream(fc *ForwardContext, wrapper *client.OpenAIClient, ...) (*openaistream.Stream[openai.ChatCompletionChunk], context.CancelFunc, error)
- func ForwardOpenAIEmbeddings(fc *ForwardContext, wrapper *client.OpenAIClient, ...) (*openai.CreateEmbeddingResponse, context.CancelFunc, error)
- func ForwardOpenAIResponses(fc *ForwardContext, wrapper *client.OpenAIClient, ...) (*responses.Response, context.CancelFunc, error)
- func ForwardOpenAIResponsesStream(fc *ForwardContext, wrapper *client.OpenAIClient, ...) (*openaistream.Stream[responses.ResponseStreamEventUnion], context.CancelFunc, ...)
- type ForwardContext
- func (fc *ForwardContext) Complete(ctx context.Context, resp interface{}, err error)
- func (fc *ForwardContext) PrepareContext(req interface{}) (context.Context, context.CancelFunc)
- func (fc *ForwardContext) WithAfterRequest(hook func(context.Context, interface{}, error)) *ForwardContext
- func (fc *ForwardContext) WithBeforeRequest(hook func(context.Context, interface{}) (context.Context, error)) *ForwardContext
- func (fc *ForwardContext) WithTimeout(timeout time.Duration) *ForwardContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForwardAnthropicV1 ¶
func ForwardAnthropicV1(fc *ForwardContext, wrapper *client.AnthropicClient, req *anthropic.MessageNewParams) (*anthropic.Message, context.CancelFunc, error)
ForwardAnthropicV1 sends a non-streaming Anthropic v1 message request.
func ForwardAnthropicV1Beta ¶
func ForwardAnthropicV1Beta(fc *ForwardContext, wrapper *client.AnthropicClient, req *anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, context.CancelFunc, error)
ForwardAnthropicV1Beta sends a non-streaming Anthropic v1 beta message request.
func ForwardAnthropicV1BetaStream ¶
func ForwardAnthropicV1BetaStream(fc *ForwardContext, wrapper *client.AnthropicClient, req *anthropic.BetaMessageNewParams) (*anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion], context.CancelFunc, error)
ForwardAnthropicV1BetaStream sends a streaming Anthropic v1 beta message request. Note: Set BaseCtx via WithBaseCtx() to support client cancellation.
func ForwardAnthropicV1Stream ¶
func ForwardAnthropicV1Stream(fc *ForwardContext, wrapper *client.AnthropicClient, req *anthropic.MessageNewParams) (*anthropicstream.Stream[anthropic.MessageStreamEventUnion], context.CancelFunc, error)
ForwardAnthropicV1Stream sends a streaming Anthropic v1 message request. Note: Set BaseCtx via WithBaseCtx() to support client cancellation.
func ForwardGoogle ¶
func ForwardGoogle(fc *ForwardContext, wrapper *client.GoogleClient, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, context.CancelFunc, error)
ForwardGoogle sends a non-streaming Google Generative AI request.
func ForwardGoogleStream ¶
func ForwardGoogleStream(fc *ForwardContext, wrapper *client.GoogleClient, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (iter.Seq2[*genai.GenerateContentResponse, error], context.CancelFunc, error)
ForwardGoogleStream sends a streaming Google Generative AI request. Note: Pass request context (c.Request.Context()) as baseCtx in NewForwardContext for client cancellation support.
func ForwardOpenAIChat ¶
func ForwardOpenAIChat(fc *ForwardContext, wrapper *client.OpenAIClient, req *openai.ChatCompletionNewParams) (*openai.ChatCompletion, context.CancelFunc, error)
ForwardOpenAIChat sends a non-streaming OpenAI chat completion request. IMPORTANT: All transformations (protocol conversion + vendor-specific) should be applied by the transform chain BEFORE calling this function.
func ForwardOpenAIChatStream ¶
func ForwardOpenAIChatStream(fc *ForwardContext, wrapper *client.OpenAIClient, req *openai.ChatCompletionNewParams) (*openaistream.Stream[openai.ChatCompletionChunk], context.CancelFunc, error)
ForwardOpenAIChatStream sends a streaming OpenAI chat completion request. IMPORTANT: All transformations (protocol conversion + vendor-specific) should be applied by the transform chain BEFORE calling this function. Note: Pass request context (c.Request.Context()) as baseCtx in NewForwardContext for client cancellation support.
func ForwardOpenAIEmbeddings ¶
func ForwardOpenAIEmbeddings(fc *ForwardContext, wrapper *client.OpenAIClient, req *openai.EmbeddingNewParams) (*openai.CreateEmbeddingResponse, context.CancelFunc, error)
ForwardOpenAIEmbeddings sends an OpenAI embeddings request. Embeddings have no streaming and skip the chat transform chain.
func ForwardOpenAIResponses ¶
func ForwardOpenAIResponses(fc *ForwardContext, wrapper *client.OpenAIClient, params responses.ResponseNewParams) (*responses.Response, context.CancelFunc, error)
ForwardOpenAIResponses sends a non-streaming OpenAI Responses API request.
func ForwardOpenAIResponsesStream ¶
func ForwardOpenAIResponsesStream(fc *ForwardContext, wrapper *client.OpenAIClient, params responses.ResponseNewParams) (*openaistream.Stream[responses.ResponseStreamEventUnion], context.CancelFunc, error)
ForwardOpenAIResponsesStream sends a streaming OpenAI Responses API request. Note: Pass request context (c.Request.Context()) as baseCtx in NewForwardContext for client cancellation support.
Types ¶
type ForwardContext ¶
type ForwardContext struct {
// Required dependencies
Provider *typ.Provider
BaseCtx context.Context // Base context (e.g., request context for cancellation support)
// Optional configuration
Timeout time.Duration
// Hooks (chainable - multiple hooks can be added)
BeforeRequestHooks []func(ctx context.Context, req interface{}) (context.Context, error)
AfterRequestHooks []func(ctx context.Context, resp interface{}, err error)
}
ForwardContext provides dependencies for forward functions. It uses the builder pattern for optional configuration and hooks.
func NewForwardContext ¶
func NewForwardContext(baseCtx context.Context, provider *typ.Provider) *ForwardContext
NewForwardContext creates a new ForwardContext with required dependencies. The timeout is set to the provider's default timeout. baseCtx is the base context for the request:
- Use context.Background() for non-streaming requests
- Use c.Request.Context() for streaming requests to support client cancellation
func (*ForwardContext) Complete ¶
func (fc *ForwardContext) Complete(ctx context.Context, resp interface{}, err error)
Complete calls all AfterRequest hooks (if set) with the response and error. Hooks are called in the order they were added. This should be called after the request completes, regardless of success or failure.
func (*ForwardContext) PrepareContext ¶
func (fc *ForwardContext) PrepareContext(req interface{}) (context.Context, context.CancelFunc)
PrepareContext prepares the final context for the request. It applies the BeforeRequest hooks and adds the scenario to the context. It also sets up the timeout and returns a cancel function. If BaseCtx is not set, it uses context.Background() as the base.
The order of operations matches the original implementation: 1. Apply BeforeRequest hooks 2. Add timeout
func (*ForwardContext) WithAfterRequest ¶
func (fc *ForwardContext) WithAfterRequest(hook func(context.Context, interface{}, error)) *ForwardContext
WithAfterRequest adds a hook that is called after the request completes. Multiple hooks can be added and will be called in order. Each hook receives the response and any error that occurred.
func (*ForwardContext) WithBeforeRequest ¶
func (fc *ForwardContext) WithBeforeRequest(hook func(context.Context, interface{}) (context.Context, error)) *ForwardContext
WithBeforeRequest adds a hook that is called before the request is sent. Multiple hooks can be added and will be called in order. Each hook can modify the context and return an error to abort the request.
func (*ForwardContext) WithTimeout ¶
func (fc *ForwardContext) WithTimeout(timeout time.Duration) *ForwardContext
WithTimeout sets the timeout for the request. If not set, the provider's default timeout is used.