forwarding

package
v0.260507.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardAnthropicV1

ForwardAnthropicV1 sends a non-streaming Anthropic v1 message request.

func ForwardAnthropicV1Beta

ForwardAnthropicV1Beta sends a non-streaming Anthropic v1 beta message request.

func ForwardAnthropicV1BetaStream

ForwardAnthropicV1BetaStream sends a streaming Anthropic v1 beta message request. Note: Set BaseCtx via WithBaseCtx() to support client cancellation.

func ForwardAnthropicV1Stream

ForwardAnthropicV1Stream sends a streaming Anthropic v1 message request. Note: Set BaseCtx via WithBaseCtx() to support client cancellation.

func ForwardGoogle

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

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

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL