llm

package
v0.20260520.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStreamAccumulatorRejected = errors.New("chat completion stream accumulator rejected chunk")

Functions

func ApplyChatReasoning

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

func ApplyMaxResponseTokens

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

func ApplyReasoningDisable

func ApplyReasoningDisable(p *openai.ChatCompletionNewParams)

func BuildUserContentParts

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

func ImagePlaceholder

func ImagePlaceholder(seq int) string

ImagePlaceholder returns the placeholder string for a given image sequence number.

func JumpLeftOverImgTag

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

JumpLeftOverImgTag treats an [img-<n>] tag as a single atomic unit: if the cursor lies anywhere inside the tag (start < pos <= end), it jumps to start (before the tag). Spaces around the tag are never considered part of the placeholder.

func JumpRightOverImgTag

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

JumpRightOverImgTag treats an [img-<n>] tag as a single atomic unit: if the cursor lies anywhere inside the tag (start <= pos < end), it jumps to end (after the tag). Spaces around the tag are never considered part of the placeholder.

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 ModelID

func ModelID(s string) shared.ChatModel

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 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)

Types

type AssistantToolCall

type AssistantToolCall struct {
	ID        string
	Name      string
	Arguments string
}

type AssistantTurnResult

type AssistantTurnResult struct {
	Content       string
	ReasoningText string
	ToolCalls     []AssistantToolCall
	Usage         UsageStats
}

func StreamAssistantTurn

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

type StreamOpts

type StreamOpts struct {
	ShowThinking  bool
	ReasoningSink io.Writer
	OnDelta       func(channel, text string)
}

type UsageStats

type UsageStats struct {
	PromptTokens       int64
	CachedPromptTokens int64
	ReasoningTokens    int64
	ResponseTokens     int64
	TotalTokens        int64
	OutputTPS          float64
	TTFTSecs           float64
	PromptTPS          float64
	TurnWallSecs       float64
	ThoughtSecs        float64
}

func AggregateConsecutiveTurnUsage

func AggregateConsecutiveTurnUsage(usages []UsageStats) UsageStats

func StreamText

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

Jump to

Keyboard shortcuts

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