codec

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package codec translates provider wire formats through llmprotocol's neutral representation. Codecs are stateless; StreamState belongs to one response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anthropic

type Anthropic struct{}

func (Anthropic) DecodeRequest

func (Anthropic) DecodeRequest(body json.RawMessage, policy llmprotocol.Policy) (RequestResult, error)

func (Anthropic) DecodeResponse

func (Anthropic) DecodeResponse(body json.RawMessage, policy llmprotocol.Policy) (ResponseResult, error)

func (Anthropic) DecodeStreamEvent

func (Anthropic) EncodeRequest

func (Anthropic) EncodeRequest(request llmprotocol.Request, policy llmprotocol.Policy) (WireResult, error)

func (Anthropic) EncodeResponse

func (Anthropic) EncodeResponse(response llmprotocol.Response, policy llmprotocol.Policy) (WireResult, error)

func (Anthropic) EncodeStreamEvent

func (Anthropic) FinishStream

func (Anthropic) Format

func (Anthropic) Format() llmprotocol.Format

type Bedrock

type Bedrock struct{}

Bedrock implements the JSON payloads for Amazon Bedrock Converse. AWS SigV4, URL construction, credentials, and binary event-stream framing remain transport concerns; stream WireEvents use the Bedrock :event-type as Event.

func (Bedrock) DecodeRequest

func (Bedrock) DecodeRequest(body json.RawMessage, policy llmprotocol.Policy) (RequestResult, error)

func (Bedrock) DecodeResponse

func (Bedrock) DecodeResponse(body json.RawMessage, policy llmprotocol.Policy) (ResponseResult, error)

func (Bedrock) EncodeRequest

func (Bedrock) EncodeRequest(request llmprotocol.Request, policy llmprotocol.Policy) (WireResult, error)

func (Bedrock) EncodeResponse

func (Bedrock) EncodeResponse(response llmprotocol.Response, policy llmprotocol.Policy) (WireResult, error)

func (Bedrock) EncodeStreamEvent

func (Bedrock) Format

func (Bedrock) Format() llmprotocol.Format

type BedrockCohereEmbeddings

type BedrockCohereEmbeddings struct{}

BedrockCohereEmbeddings implements the text subset common to Cohere Embed v3 and v4 InvokeModel payloads. Non-float and multimodal representations remain provider extensions and therefore cannot cross formats silently.

func (BedrockCohereEmbeddings) DecodeEmbeddingRequest

func (BedrockCohereEmbeddings) DecodeEmbeddingRequest(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingRequestResult, error)

func (BedrockCohereEmbeddings) DecodeEmbeddingResponse

func (BedrockCohereEmbeddings) DecodeEmbeddingResponse(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingResponseResult, error)

func (BedrockCohereEmbeddings) EncodeEmbeddingRequest

func (BedrockCohereEmbeddings) EncodeEmbeddingRequest(request llmprotocol.EmbeddingRequest, policy llmprotocol.Policy) (WireResult, error)

func (BedrockCohereEmbeddings) EncodeEmbeddingResponse

func (BedrockCohereEmbeddings) EncodeEmbeddingResponse(response llmprotocol.EmbeddingResponse, policy llmprotocol.Policy) (WireResult, error)

func (BedrockCohereEmbeddings) Format

type BedrockTitanEmbeddings

type BedrockTitanEmbeddings struct{}

BedrockTitanEmbeddings implements the InvokeModel payload shared by Amazon Titan Text Embeddings G1 and V2. Model selection remains a transport concern.

func (BedrockTitanEmbeddings) DecodeEmbeddingRequest

func (BedrockTitanEmbeddings) DecodeEmbeddingRequest(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingRequestResult, error)

func (BedrockTitanEmbeddings) DecodeEmbeddingResponse

func (BedrockTitanEmbeddings) DecodeEmbeddingResponse(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingResponseResult, error)

func (BedrockTitanEmbeddings) EncodeEmbeddingRequest

func (BedrockTitanEmbeddings) EncodeEmbeddingRequest(request llmprotocol.EmbeddingRequest, policy llmprotocol.Policy) (WireResult, error)

func (BedrockTitanEmbeddings) EncodeEmbeddingResponse

func (BedrockTitanEmbeddings) EncodeEmbeddingResponse(response llmprotocol.EmbeddingResponse, policy llmprotocol.Policy) (WireResult, error)

func (BedrockTitanEmbeddings) Format

type EmbeddingCodec

type EmbeddingCodec interface {
	Format() llmprotocol.Format
	DecodeEmbeddingRequest(json.RawMessage, llmprotocol.Policy) (EmbeddingRequestResult, error)
	EncodeEmbeddingRequest(llmprotocol.EmbeddingRequest, llmprotocol.Policy) (WireResult, error)
	DecodeEmbeddingResponse(json.RawMessage, llmprotocol.Policy) (EmbeddingResponseResult, error)
	EncodeEmbeddingResponse(llmprotocol.EmbeddingResponse, llmprotocol.Policy) (WireResult, error)
}

type EmbeddingRegistry

type EmbeddingRegistry struct {
	// contains filtered or unexported fields
}

func NewDefaultEmbeddingRegistry

func NewDefaultEmbeddingRegistry() *EmbeddingRegistry

func NewEmbeddingRegistry

func NewEmbeddingRegistry(codecs ...EmbeddingCodec) *EmbeddingRegistry

func (*EmbeddingRegistry) Codec

func (*EmbeddingRegistry) Register

func (r *EmbeddingRegistry) Register(value EmbeddingCodec)

func (*EmbeddingRegistry) TranslateRequest

func (r *EmbeddingRegistry) TranslateRequest(source, target llmprotocol.Format, body json.RawMessage, policy llmprotocol.Policy) (WireResult, error)

func (*EmbeddingRegistry) TranslateResponse

func (r *EmbeddingRegistry) TranslateResponse(source, target llmprotocol.Format, body json.RawMessage, policy llmprotocol.Policy) (WireResult, error)

type EmbeddingRequestResult

type EmbeddingRequestResult struct {
	Request     llmprotocol.EmbeddingRequest
	Diagnostics []llmprotocol.Diagnostic
}

type EmbeddingResponseResult

type EmbeddingResponseResult struct {
	Response    llmprotocol.EmbeddingResponse
	Diagnostics []llmprotocol.Diagnostic
}

type Gemini

type Gemini struct{}

Gemini implements the JSON contract shared by generateContent and streamGenerateContent. The model and operation live in the request URL and are deliberately not part of the encoded body.

func (Gemini) DecodeRequest

func (Gemini) DecodeRequest(body json.RawMessage, policy llmprotocol.Policy) (RequestResult, error)

func (Gemini) DecodeResponse

func (Gemini) DecodeResponse(body json.RawMessage, policy llmprotocol.Policy) (ResponseResult, error)

func (Gemini) DecodeStreamEvent

func (Gemini) EncodeRequest

func (Gemini) EncodeRequest(request llmprotocol.Request, policy llmprotocol.Policy) (WireResult, error)

func (Gemini) EncodeResponse

func (Gemini) EncodeResponse(response llmprotocol.Response, policy llmprotocol.Policy) (WireResult, error)

func (Gemini) EncodeStreamEvent

func (Gemini) EncodeStreamEvent(state *StreamState, event llmprotocol.StreamEvent, policy llmprotocol.Policy) ([]llmprotocol.WireEvent, []llmprotocol.Diagnostic, error)

func (Gemini) Format

func (Gemini) Format() llmprotocol.Format

type GeminiEmbeddings

type GeminiEmbeddings struct{}

GeminiEmbeddings implements models.embedContent and models.batchEmbedContents.

func (GeminiEmbeddings) DecodeEmbeddingRequest

func (GeminiEmbeddings) DecodeEmbeddingRequest(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingRequestResult, error)

func (GeminiEmbeddings) DecodeEmbeddingResponse

func (GeminiEmbeddings) DecodeEmbeddingResponse(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingResponseResult, error)

func (GeminiEmbeddings) EncodeEmbeddingRequest

func (GeminiEmbeddings) EncodeEmbeddingRequest(request llmprotocol.EmbeddingRequest, policy llmprotocol.Policy) (WireResult, error)

func (GeminiEmbeddings) EncodeEmbeddingResponse

func (GeminiEmbeddings) EncodeEmbeddingResponse(response llmprotocol.EmbeddingResponse, policy llmprotocol.Policy) (WireResult, error)

func (GeminiEmbeddings) Format

type OpenAIChat

type OpenAIChat struct{}

func (OpenAIChat) DecodeRequest

func (OpenAIChat) DecodeRequest(body json.RawMessage, policy llmprotocol.Policy) (RequestResult, error)

func (OpenAIChat) DecodeResponse

func (OpenAIChat) DecodeResponse(body json.RawMessage, policy llmprotocol.Policy) (ResponseResult, error)

func (OpenAIChat) DecodeStreamEvent

func (OpenAIChat) EncodeRequest

func (OpenAIChat) EncodeRequest(request llmprotocol.Request, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIChat) EncodeResponse

func (OpenAIChat) EncodeResponse(response llmprotocol.Response, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIChat) EncodeStreamEvent

func (OpenAIChat) FinishStream

func (OpenAIChat) Format

func (OpenAIChat) Format() llmprotocol.Format

type OpenAIEmbeddings

type OpenAIEmbeddings struct{}

OpenAIEmbeddings implements POST /v1/embeddings.

func (OpenAIEmbeddings) DecodeEmbeddingRequest

func (OpenAIEmbeddings) DecodeEmbeddingRequest(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingRequestResult, error)

func (OpenAIEmbeddings) DecodeEmbeddingResponse

func (OpenAIEmbeddings) DecodeEmbeddingResponse(body json.RawMessage, policy llmprotocol.Policy) (EmbeddingResponseResult, error)

func (OpenAIEmbeddings) EncodeEmbeddingRequest

func (OpenAIEmbeddings) EncodeEmbeddingRequest(request llmprotocol.EmbeddingRequest, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIEmbeddings) EncodeEmbeddingResponse

func (OpenAIEmbeddings) EncodeEmbeddingResponse(response llmprotocol.EmbeddingResponse, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIEmbeddings) Format

type OpenAIResponses

type OpenAIResponses struct{}

func (OpenAIResponses) DecodeRequest

func (OpenAIResponses) DecodeRequest(body json.RawMessage, policy llmprotocol.Policy) (RequestResult, error)

func (OpenAIResponses) DecodeResponse

func (OpenAIResponses) DecodeResponse(body json.RawMessage, policy llmprotocol.Policy) (ResponseResult, error)

func (OpenAIResponses) DecodeStreamEvent

func (OpenAIResponses) EncodeRequest

func (OpenAIResponses) EncodeRequest(request llmprotocol.Request, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIResponses) EncodeResponse

func (OpenAIResponses) EncodeResponse(response llmprotocol.Response, policy llmprotocol.Policy) (WireResult, error)

func (OpenAIResponses) EncodeStreamEvent

func (OpenAIResponses) FinishStream

func (OpenAIResponses) Format

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewDefaultRegistry

func NewDefaultRegistry() *Registry

func NewRegistry

func NewRegistry(codecs ...Codec) *Registry

func (*Registry) Codec

func (r *Registry) Codec(format llmprotocol.Format) (Codec, error)

func (*Registry) FinishStream

func (r *Registry) FinishStream(state *StreamState, target llmprotocol.Format, policy llmprotocol.Policy) ([]llmprotocol.WireEvent, []llmprotocol.Diagnostic, error)

func (*Registry) Register

func (r *Registry) Register(c Codec)

func (*Registry) TranslateRequest

func (r *Registry) TranslateRequest(source, target llmprotocol.Format, body json.RawMessage, policy llmprotocol.Policy) (WireResult, error)

func (*Registry) TranslateResponse

func (r *Registry) TranslateResponse(source, target llmprotocol.Format, body json.RawMessage, policy llmprotocol.Policy) (WireResult, error)

func (*Registry) TranslateStreamEvent

func (r *Registry) TranslateStreamEvent(state *StreamState, source, target llmprotocol.Format, event llmprotocol.WireEvent, policy llmprotocol.Policy) ([]llmprotocol.WireEvent, []llmprotocol.Diagnostic, error)

type RequestResult

type RequestResult struct {
	Request     llmprotocol.Request
	Diagnostics []llmprotocol.Diagnostic
}

type ResponseResult

type ResponseResult struct {
	Response    llmprotocol.Response
	Diagnostics []llmprotocol.Diagnostic
}

type StreamState

type StreamState struct {
	Source     llmprotocol.Format
	Target     llmprotocol.Format
	ResponseID string
	Model      string
	Values     map[string]any
}

type WireResult

type WireResult struct {
	Body        json.RawMessage
	Diagnostics []llmprotocol.Diagnostic
}

Jump to

Keyboard shortcuts

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