llmkit

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package llmkit provides three public entry points for LLM access: construct protocol-neutral Request and Event IR directly, use Codec to translate raw protocol payloads, or use Client for end-to-end HTTP calls. Stream failures that happen after Client.Call returns are delivered as an EventError followed by channel close. ErrorStageStream is available for stream-stage failures surfaced before a channel is returned; it does not introduce a second error channel.

Package llmkit provides the public LLM access API.

Index

Constants

View Source
const (
	BuiltinToolFallbackDrop        = convert.BuiltinToolFallbackDrop
	BuiltinToolFallbackError       = convert.BuiltinToolFallbackError
	BuiltinToolFallbackPassthrough = convert.BuiltinToolFallbackPassthrough
	BuiltinToolFallbackFunction    = convert.BuiltinToolFallbackFunction
)
View Source
const (
	DroppedToolReasonCrossProtocolIncompatible   = convert.DroppedToolReasonCrossProtocolIncompatible
	DroppedToolReasonFunctionFallbackUnsupported = convert.DroppedToolReasonFunctionFallbackUnsupported
)
View Source
const (
	ProtocolOpenAIChat      = ir.ProtocolOpenAIChat
	ProtocolOpenAIResponses = ir.ProtocolOpenAIResponses
	ProtocolClaudeMessages  = ir.ProtocolClaudeMessages
	ProtocolClaude          = ir.ProtocolClaude
	ProtocolGemini          = ir.ProtocolGemini
	ProtocolUnknown         = ir.ProtocolUnknown

	RoleSystem    = ir.RoleSystem
	RoleUser      = ir.RoleUser
	RoleAssistant = ir.RoleAssistant
	RoleTool      = ir.RoleTool
	RoleDeveloper = ir.RoleDeveloper

	ContentTypeText       = ir.ContentTypeText
	ContentTypeImage      = ir.ContentTypeImage
	ContentTypeAudio      = ir.ContentTypeAudio
	ContentTypeToolUse    = ir.ContentTypeToolUse
	ContentTypeToolResult = ir.ContentTypeToolResult
	ContentTypeThinking   = ir.ContentTypeThinking
	ContentTypeInputText  = ir.ContentTypeInputText
	ContentTypeOutputText = ir.ContentTypeOutputText
	ContentTypeImageURL   = ir.ContentTypeImageURL
	ContentTypeFunction   = ir.ContentTypeFunction

	ImageSourceBase64 = ir.ImageSourceBase64
	ImageSourceURL    = ir.ImageSourceURL

	EventStreamStart            = ir.EventStreamStart
	EventContentDelta           = ir.EventContentDelta
	EventToolCallDelta          = ir.EventToolCallDelta
	EventThinkingDelta          = ir.EventThinkingDelta
	EventUsage                  = ir.EventUsage
	EventDone                   = ir.EventDone
	EventError                  = ir.EventError
	EventRawPassthrough         = ir.EventRawPassthrough
	EventContentBlockStop       = ir.EventContentBlockStop
	EventSignatureDelta         = ir.EventSignatureDelta
	EventToolCallStart          = ir.EventToolCallStart
	EventToolCallArgumentsDelta = ir.EventToolCallArgumentsDelta
	EventToolCallEnd            = ir.EventToolCallEnd
)

Variables

View Source
var (
	ErrUnsupportedEndpoint = errors.New("llmkit: unsupported endpoint")
	ErrUnsupportedProtocol = errors.New("llmkit: unsupported protocol")
	ErrNilDecodedRequest   = errors.New("llmkit: protocol handler returned a nil request")
)
View Source
var (
	ErrFunctionToolMissingName            = convert.ErrFunctionToolMissingName
	ErrBuiltinToolUnsupported             = convert.ErrBuiltinToolUnsupported
	ErrNamespacedFunctionMissingNamespace = convert.ErrNamespacedFunctionMissingNamespace
	ErrNamespacedFunctionMissingName      = convert.ErrNamespacedFunctionMissingName
	ErrNamespacedFunctionNotFunction      = convert.ErrNamespacedFunctionNotFunction
	ErrNamespacedFunctionNameCollision    = convert.ErrNamespacedFunctionNameCollision
)

Functions

This section is empty.

Types

type BuiltinToolFallbackPolicy

type BuiltinToolFallbackPolicy = convert.BuiltinToolFallbackPolicy

func NormalizeBuiltinToolFallback

func NormalizeBuiltinToolFallback(value string) BuiltinToolFallbackPolicy

type CallOptions

type CallOptions struct {
	HTTPClient HTTPDoer
	Conversion ConversionOptions
}

type Client

type Client interface {
	Call(context.Context, Request, Target, CallOptions) (<-chan Event, error)
}

func NewClient

func NewClient(options ClientOptions) Client

type ClientOptions

type ClientOptions struct {
	Codec      Codec
	HTTPClient HTTPDoer
}

type Codec

type Codec interface {
	DecodeRequest(DecodeRequestInput) (DecodedRequest, error)
	EncodeRequest(EncodeRequestInput) (EncodedRequest, error)
	DecodeResponse(context.Context, DecodeResponseInput) (<-chan Event, error)
	EncodeResponse(context.Context, EncodeResponseInput) (<-chan EncodedChunk, error)
}

func NewCodec

func NewCodec() Codec

type ContentBlock

type ContentBlock = ir.ContentBlock

type ContentType

type ContentType = ir.ContentType

type ConversionOptions

type ConversionOptions struct {
	BuiltinToolFallback BuiltinToolFallbackPolicy
	RequestFields       RequestFieldPermissions
	OnDroppedTools      func([]DroppedTool)
}

type ConversionState

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

type DecodeRequestInput

type DecodeRequestInput struct {
	Method  string
	Path    string
	Headers map[string][]string
	Body    []byte
}

type DecodeResponseInput

type DecodeResponseInput struct {
	Protocol   Protocol
	StatusCode int
	Headers    map[string][]string
	Body       io.Reader
	Stream     bool
	State      ConversionState
}

type DecodedRequest

type DecodedRequest struct {
	Protocol Protocol
	Request  Request
}

type DeltaPayload

type DeltaPayload = ir.DeltaPayload

type DroppedTool

type DroppedTool = convert.DroppedTool

type EncodeRequestInput

type EncodeRequestInput struct {
	Request Request
	Target  Target
	Options ConversionOptions
}

type EncodeResponseInput

type EncodeResponseInput struct {
	Protocol Protocol
	Events   <-chan Event
	Stream   bool
}

type EncodedChunk

type EncodedChunk struct {
	Data []byte
	Err  error
}

type EncodedRequest

type EncodedRequest struct {
	Method  string
	Path    string
	Headers map[string][]string
	Body    []byte
	State   ConversionState
}

type Error

type Error struct {
	Stage      ErrorStage
	StatusCode int
	Retryable  bool
	Cause      error
	// contains filtered or unexported fields
}

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() error

type ErrorPayload

type ErrorPayload = ir.ErrorPayload

type ErrorStage

type ErrorStage string
const (
	ErrorStageEncode   ErrorStage = "encode"
	ErrorStageConnect  ErrorStage = "connect"
	ErrorStageUpstream ErrorStage = "upstream"
	ErrorStageDecode   ErrorStage = "decode"
	// ErrorStageStream is available to callers that surface a stream failure
	// before returning an event channel. Once a channel exists, stream failures
	// remain EventError followed by channel close.
	ErrorStageStream ErrorStage = "stream"
)

type Event

type Event = ir.Event

type EventType

type EventType = ir.EventType

type HTTPDoer

type HTTPDoer interface {
	Do(*http.Request) (*http.Response, error)
}

type Message

type Message = ir.Message

type Protocol

type Protocol = ir.Protocol

type RawSSEEvent

type RawSSEEvent = ir.RawSSEEvent

type Request

type Request = ir.Request

type RequestFieldPermissions

type RequestFieldPermissions = convert.RequestFieldPermissions

func DefaultRequestFieldPermissions

func DefaultRequestFieldPermissions() RequestFieldPermissions

type Role

type Role = ir.Role

type StreamingToolCall

type StreamingToolCall = ir.StreamingToolCall

type Target

type Target struct {
	Protocol     Protocol
	BaseURL      string
	EndpointPath string
	APIKey       string
	Model        string
	Headers      map[string][]string
}

type Tool

type Tool = ir.Tool

type ToolCall

type ToolCall = ir.ToolCall

type ToolCallDelta

type ToolCallDelta = ir.ToolCallDelta

type ToolChoice

type ToolChoice = ir.ToolChoice

type Usage

type Usage = ir.Usage

Directories

Path Synopsis
internal
protocol/claude
Package claude implements the Anthropic Claude Messages API protocol codec.
Package claude implements the Anthropic Claude Messages API protocol codec.
protocol/openai/chat
Package chat implements the OpenAI Chat Completions protocol codec.
Package chat implements the OpenAI Chat Completions protocol codec.
protocol/openai/responses
Package responses implements the OpenAI Responses API protocol codec.
Package responses implements the OpenAI Responses API protocol codec.
Package ir defines the protocol-agnostic intermediate representation used by LLM protocol codecs.
Package ir defines the protocol-agnostic intermediate representation used by LLM protocol codecs.

Jump to

Keyboard shortcuts

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