endpointspec

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package endpointspec defines the EndpointSpec which is to bundle the translator, tracing and most importantly request and response types for different API endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletionsEndpointSpec

type ChatCompletionsEndpointSpec struct{}

ChatCompletionsEndpointSpec implements EndpointSpec for /v1/chat/completions.

func (ChatCompletionsEndpointSpec) GetTranslator

func (ChatCompletionsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIChatCompletionTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ChatCompletionsEndpointSpec) ParseBody

func (ChatCompletionsEndpointSpec) ParseBody(
	body []byte,
	costConfigured bool,
) (internalapi.OriginalModel, *openai.ChatCompletionRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type CompletionsEndpointSpec

type CompletionsEndpointSpec struct{}

CompletionsEndpointSpec implements EndpointSpec for /v1/completions.

func (CompletionsEndpointSpec) GetTranslator

func (CompletionsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAICompletionTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (CompletionsEndpointSpec) ParseBody

func (CompletionsEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.CompletionRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type EmbeddingsEndpointSpec

type EmbeddingsEndpointSpec struct{}

EmbeddingsEndpointSpec implements EndpointSpec for /v1/embeddings.

func (EmbeddingsEndpointSpec) GetTranslator

func (EmbeddingsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIEmbeddingTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (EmbeddingsEndpointSpec) ParseBody

func (EmbeddingsEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.EmbeddingRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type ImageGenerationEndpointSpec

type ImageGenerationEndpointSpec struct{}

ImageGenerationEndpointSpec implements EndpointSpec for /v1/images/generations.

func (ImageGenerationEndpointSpec) GetTranslator

func (ImageGenerationEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIImageGenerationTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ImageGenerationEndpointSpec) ParseBody

func (ImageGenerationEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.ImageGenerationRequest, bool, []byte, error)

type MessagesEndpointSpec

type MessagesEndpointSpec struct{}

MessagesEndpointSpec implements EndpointSpec for /v1/messages.

func (MessagesEndpointSpec) GetTranslator

func (MessagesEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.AnthropicMessagesTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (MessagesEndpointSpec) ParseBody

func (MessagesEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *anthropic.MessagesRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type RerankEndpointSpec

type RerankEndpointSpec struct{}

RerankEndpointSpec implements EndpointSpec for /v2/rerank.

func (RerankEndpointSpec) GetTranslator

func (RerankEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.CohereRerankTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (RerankEndpointSpec) ParseBody

func (RerankEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *cohereschema.RerankV2Request, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type ResponsesEndpointSpec

type ResponsesEndpointSpec struct{}

ResponsesEndpointSpec implements EndpointSpec for /v1/responses.

func (ResponsesEndpointSpec) GetTranslator

func (ResponsesEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIResponsesTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ResponsesEndpointSpec) ParseBody

func (ResponsesEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.ResponseRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

type Spec

type Spec[ReqT, RespT, RespChunkT any] interface {
	// ParseBody parses the request body and returns the original model,
	// the parsed request, whether the request is streaming, any mutated body,
	// and an error if parsing fails.
	//
	// Parameters:
	// * body: The raw request body as a byte slice.
	// * costConfigured: A boolean indicating if cost metrics are configured.
	//
	// Returns:
	// * originalModel: The original model specified in the request.
	// * req: The parsed request of type ReqT.
	// * stream: A boolean indicating if the request is for streaming responses.
	// * mutatedBody: The possibly mutated request body as a byte slice. Or nil if no mutation is needed.
	// * err: An error if parsing fails.
	ParseBody(body []byte, costConfigured bool) (originalModel internalapi.OriginalModel, req *ReqT, stream bool, mutatedBody []byte, err error)
	// GetTranslator selects the appropriate translator based on the output API schema
	// and an optional model name override.
	//
	// Parameters:
	// * out: The output API schema for which the translator is needed.
	// * modelNameOverride: An optional model name to override the one specified in the request.
	//
	// Returns:
	// * translator: The selected translator of type Translator[ReqT, RespT, RespChunkT].
	// * err: An error if translator selection fails.
	GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.Translator[ReqT, tracingapi.Span[RespT, RespChunkT]], error)
}

Spec defines methods for parsing request bodies and selecting translators for different API endpoints.

Type Parameters: * ReqT: The request type. * RespT: The response type. * RespChunkT: The chunk type for streaming responses.

This must be implemented by specific endpoint handlers to provide custom logic for parsing and translation.

Jump to

Keyboard shortcuts

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