llm

package
v2026.930.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ProtocolOpenAI    = apitype.ProtocolOpenAI
	ProtocolAnthropic = apitype.ProtocolAnthropic

	FinishReasonStop          = apitype.FinishReasonStop
	FinishReasonToolCalls     = apitype.FinishReasonToolCalls
	FinishReasonLength        = apitype.FinishReasonLength
	FinishReasonContentFilter = apitype.FinishReasonContentFilter
)
View Source
const AnthropicAPIVersion = anthropic.APIVersion
View Source
const AnthropicOAuthBeta = anthropic.OAuthBeta

Variables

View Source
var ErrCircuitOpen = errors.New("provider temporarily unavailable")
View Source
var ErrStreamAccumulatorRejected = stream.ErrStreamAccumulatorRejected

Functions

func AnthropicMessagesURL

func AnthropicMessagesURL(base string) string

func ApplyChatReasoning

func ApplyChatReasoning(cfg *config.Root, p *openai.ChatCompletionNewParams, forceDisable bool)

func ApplyChatReasoningWithEffort added in v2026.716.0

func ApplyChatReasoningWithEffort(cfg *config.Root, p *openai.ChatCompletionNewParams, forceDisable bool, override string)

func ApplyMaxResponseTokens

func ApplyMaxResponseTokens(cfg *config.Root, p *openai.ChatCompletionNewParams)

func ApplyProviderSimpleParams

func ApplyProviderSimpleParams(proto Protocol, cfg *config.Root, openaiParams *openai.ChatCompletionNewParams, forceDisable bool)

func ApplyProviderTurnParams

func ApplyProviderTurnParams(proto Protocol, cfg *config.Root, openaiParams *openai.ChatCompletionNewParams, forceDisable bool)

func ApplyProviderTurnParamsWithEffort added in v2026.716.0

func ApplyProviderTurnParamsWithEffort(proto Protocol, cfg *config.Root, openaiParams *openai.ChatCompletionNewParams, forceDisable bool, effort string)

func ApplyReasoningDisable

func ApplyReasoningDisable(p *openai.ChatCompletionNewParams)

func ApplySimpleReasoning

func ApplySimpleReasoning(cfg *config.Root, p *openai.ChatCompletionNewParams, forceDisable bool)

func BackoffDelay

func BackoffDelay(policy config.APIResiliencePolicy, attempt int, retryAfter time.Duration, rng *rand.Rand) time.Duration

func BackspaceOverAtomicReplToken added in v2026.606.3

func BackspaceOverAtomicReplToken(line []rune, pos int) ([]rune, int, bool)

func BackspaceOverImgTag added in v2026.602.2

func BackspaceOverImgTag(line []rune, pos int) ([]rune, int, bool)

func BuildUserContentParts

func BuildUserContentParts(content string, imageFiles map[int]string) []openai.ChatCompletionContentPartUnionParam

func CanonicalizeUserLineForStorage added in v2026.602.2

func CanonicalizeUserLineForStorage(line string, imageFiles map[int]string) string

func CountTurnPrompt added in v2026.611.1

func CountTurnPrompt(req TurnRequest) int64

func DeleteForwardOverAtomicReplToken added in v2026.606.3

func DeleteForwardOverAtomicReplToken(line []rune, pos int) ([]rune, int, bool)

func DeleteForwardOverImgTag added in v2026.602.2

func DeleteForwardOverImgTag(line []rune, pos int) ([]rune, int, bool)

func HostKeyFromBaseURL

func HostKeyFromBaseURL(baseURL string) string

func ImagePlaceholder

func ImagePlaceholder(seq int, imagePath string) string

func JumpLeftOverAtomicReplToken added in v2026.606.3

func JumpLeftOverAtomicReplToken(line []rune, pos int) int

func JumpLeftOverImgTag

func JumpLeftOverImgTag(line []rune, pos int) int

func JumpRightOverAtomicReplToken added in v2026.606.3

func JumpRightOverAtomicReplToken(line []rune, pos int) int

func JumpRightOverImgTag

func JumpRightOverImgTag(line []rune, pos int) int

func LastAssistantIndex

func LastAssistantIndex(msgs []chatstore.Message) int

func MessageForAPI

func MessageForAPI(m chatstore.Message, includeReasoning bool) chatstore.Message

func MessageParams

func MessageParams(system string, msgs []chatstore.Message, imageFiles map[int]string) []openai.ChatCompletionMessageParamUnion

MessageParams builds OpenAI API message params from chatstore messages. If imageFiles is non-nil and contains entries for [img-<n>] placeholders found in user messages, those placeholders are replaced with image content parts.

func MessagesForAPI

func MessagesForAPI(msgs []chatstore.Message) []chatstore.Message

func ModelID

func ModelID(s string) shared.ChatModel

func NewResilientHTTPClient

func NewResilientHTTPClient(policy config.APIResiliencePolicy) *http.Client

func NormalizeREPLBuffer added in v2026.602.2

func NormalizeREPLBuffer(line []rune, pos int) ([]rune, int)

func OpenAIClientFromBackend

func OpenAIClientFromBackend(b CompletionBackend) (openai.Client, bool)

func ParseCursorToolEventFromChunkRawJSON added in v2026.606.0

func ParseCursorToolEventFromChunkRawJSON(raw string) string

func PopulateAssistantTurnUsage

func PopulateAssistantTurnUsage(dst *chatstore.Message, system string, msgsPrior []chatstore.Message, u UsageStats)

func PromptDisplaySplit

func PromptDisplaySplit(system string, msgs []chatstore.Message, apiPromptTokens int64) (contextTok int64, lastUserTok int64)

func RetryMessage

func RetryMessage(attempt, max int, err error, wait time.Duration) string

func UsagePromptParts

func UsagePromptParts(system string, msgs []chatstore.Message, promptTokens int64, cachedPromptTokens int64) (contextTok int64, lastUserTok int64, contextEstimated bool)

func UsageTokensDisplayParts

func UsageTokensDisplayParts(system string, msgs []chatstore.Message, u UsageStats, turnCount int) (contextTok, lastUserTok int64, contextEstimated bool, reasoningTok, responseTok, totalTok int64)

func UserFacingAPIError

func UserFacingAPIError(err error) string

Types

type AnthropicAuth

type AnthropicAuth = anthropic.Auth

func AnthropicAuthFromAPIKey

func AnthropicAuthFromAPIKey(token string) AnthropicAuth

func AnthropicAuthFromOAuthBearer

func AnthropicAuthFromOAuthBearer(token string) AnthropicAuth

type AnthropicBackend

type AnthropicBackend = anthropic.Backend

func NewAnthropicBackend

func NewAnthropicBackend(baseURL string, auth AnthropicAuth) *AnthropicBackend

func NewAnthropicBackendWithClient

func NewAnthropicBackendWithClient(baseURL string, auth AnthropicAuth, client *http.Client) *AnthropicBackend

type AnthropicUsagePayload

type AnthropicUsagePayload = anthropic.UsagePayload

type AssistantToolCall

type AssistantToolCall = apitype.AssistantToolCall

type AssistantTurnResult

type AssistantTurnResult = apitype.AssistantTurnResult

func StreamAssistantTurn

func StreamAssistantTurn(ctx context.Context, client openai.Client, params openai.ChatCompletionNewParams, contentOut io.Writer, opts StreamOpts) (AssistantTurnResult, error)

type CircuitRegistry

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

func NewCircuitRegistry

func NewCircuitRegistry() *CircuitRegistry

func (*CircuitRegistry) IsOpen

func (c *CircuitRegistry) IsOpen(hostKey string) bool

func (*CircuitRegistry) Reset

func (c *CircuitRegistry) Reset(hostKey string)

func (*CircuitRegistry) Trip

func (c *CircuitRegistry) Trip(hostKey string, openFor time.Duration)

type CompletionBackend

type CompletionBackend = apitype.CompletionBackend

func NewCompletionBackend

func NewCompletionBackend(ctx context.Context, cfg *config.Root, p *config.Provider) (CompletionBackend, error)

type ErrorClass

type ErrorClass int
const (
	ErrorPermanent ErrorClass = iota
	ErrorRetryable
	ErrorCircuitOpen
)

func ClassifyAPIError

func ClassifyAPIError(err error, circuitOpen bool) (ErrorClass, int, time.Duration)

type OpenAIBackend

type OpenAIBackend struct {
	Client openai.Client
}

func (*OpenAIBackend) CompleteText

func (b *OpenAIBackend) CompleteText(ctx context.Context, req SimpleCompletionRequest) (string, error)

func (*OpenAIBackend) ListModels

func (b *OpenAIBackend) ListModels(ctx context.Context) ([]string, error)

func (*OpenAIBackend) Protocol

func (b *OpenAIBackend) Protocol() Protocol

func (*OpenAIBackend) StreamText

func (b *OpenAIBackend) StreamText(ctx context.Context, req SimpleCompletionRequest, contentOut io.Writer, opts StreamOpts) (string, UsageStats, error)

func (*OpenAIBackend) StreamTurn

func (b *OpenAIBackend) StreamTurn(ctx context.Context, req TurnRequest, contentOut io.Writer, opts StreamOpts) (AssistantTurnResult, error)

type Protocol

type Protocol = apitype.Protocol

type ProviderHTTPError

type ProviderHTTPError = transport.ProviderHTTPError

func NewProviderHTTPError

func NewProviderHTTPError(status int, message string, retryAfter time.Duration) *ProviderHTTPError

type ResilientBackend

type ResilientBackend struct {
	Inner         CompletionBackend
	HostKey       string
	Policy        config.APIResiliencePolicy
	Circuits      *CircuitRegistry
	SidecarRevive func(context.Context, error)
	// contains filtered or unexported fields
}

func NewResilientBackend

func NewResilientBackend(inner CompletionBackend, hostKey string, policy config.APIResiliencePolicy, circuits *CircuitRegistry) *ResilientBackend

func (*ResilientBackend) CompleteText

func (b *ResilientBackend) CompleteText(ctx context.Context, req SimpleCompletionRequest) (string, error)

func (*ResilientBackend) ListModels

func (b *ResilientBackend) ListModels(ctx context.Context) ([]string, error)

func (*ResilientBackend) Protocol

func (b *ResilientBackend) Protocol() Protocol

func (*ResilientBackend) StreamText

func (b *ResilientBackend) StreamText(ctx context.Context, req SimpleCompletionRequest, contentOut io.Writer, opts StreamOpts) (string, UsageStats, error)

func (*ResilientBackend) StreamTurn

func (b *ResilientBackend) StreamTurn(ctx context.Context, req TurnRequest, contentOut io.Writer, opts StreamOpts) (AssistantTurnResult, error)

type SimpleCompletionRequest

type SimpleCompletionRequest = apitype.SimpleCompletionRequest

type StreamOpts

type StreamOpts = apitype.StreamOpts

type ToolDef

type ToolDef = apitype.ToolDef

func ToolDefsFromOpenAI

func ToolDefsFromOpenAI(tools []openai.ChatCompletionToolUnionParam) []ToolDef

type TurnRequest

type TurnRequest = apitype.TurnRequest

type UsageStats

type UsageStats = apitype.UsageStats

func AggregateConsecutiveTurnUsage

func AggregateConsecutiveTurnUsage(usages []UsageStats) UsageStats

func NormalizeAnthropicUsage

func NormalizeAnthropicUsage(u AnthropicUsagePayload) UsageStats

func StreamText

func StreamText(ctx context.Context, client openai.Client, params openai.ChatCompletionNewParams, contentOut io.Writer, opts StreamOpts) (string, UsageStats, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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