Documentation
¶
Overview ¶
Package llm adapts langchaingo models for the agent loop and single-shot module tasks.
Index ¶
- Constants
- Variables
- func AgentEnabled(name string) bool
- func AgentModelName(name string) string
- func Complete(ctx context.Context, model llms.Model, systemPrompt string, ...) (string, error)
- func DeepSeekThinkingHTTPClientForTest(base http.RoundTripper) *http.Client
- func GenerateWithTemplate(ctx context.Context, modelName string, template ChatTemplate, ...) (string, error)
- func GetOrCreateModel(ctx context.Context, modelName string) (llms.Model, string, error)
- func LLMGenerate(ctx context.Context, modelName, prompt string) (string, error)
- func NewModel(ctx context.Context, modelName string) (llms.Model, string, error)
- func ProviderForModel(modelName string) string
- func ReasoningCallOptions(modelName string, maxTokens int) []llms.CallOption
- func ResetModelPoolForTest()
- func SetModelCreatorForTest(fn modelCreatorFn)
- func SupportsReasoningStream(modelName string) bool
- type AssistantResult
- type ChatTemplate
- type FakeModel
- type ResponseScript
- type StreamOptions
- type Usage
Constants ¶
const ( AgentChat = "chat" AgentBillClassify = "bill_classify" AgentExtractTags = "extract_tags" AgentSimilarTags = "similar_tags" AgentNewsSummary = "news_summary" AgentRepoReviewComment = "repo_review_comment" )
Agent name constants identify logical agent roles for LLM helpers.
const ( ProviderOpenAI = "openai" ProviderOpenAICompatible = "openai_compatible" ProviderGemini = "gemini" ProviderAnthropic = "anthropic" )
Model provider constants match config.models provider values.
Variables ¶
var ErrAborted = errors.New("agent llm: aborted")
ErrAborted indicates the LLM call was cancelled.
Functions ¶
func AgentEnabled ¶
AgentEnabled reports whether a named agent is configured with a model and enabled.
func AgentModelName ¶
AgentModelName returns the configured model for a named agent when enabled.
func Complete ¶
func Complete( ctx context.Context, model llms.Model, systemPrompt string, messages []llms.MessageContent, modelName string, maxTokens int, ) (string, error)
Complete performs a non-streaming completion for auxiliary tasks such as summarization.
func DeepSeekThinkingHTTPClientForTest ¶ added in v0.94.0
func DeepSeekThinkingHTTPClientForTest(base http.RoundTripper) *http.Client
DeepSeekThinkingHTTPClientForTest exposes the DeepSeek thinking HTTP client for tests.
func GenerateWithTemplate ¶
func GenerateWithTemplate(ctx context.Context, modelName string, template ChatTemplate, data map[string]any) (string, error)
GenerateWithTemplate performs a single-shot completion using the given prompt template.
func GetOrCreateModel ¶
GetOrCreateModel returns a cached langchaingo model for the given model name.
func LLMGenerate ¶
LLMGenerate performs a single-shot completion using BaseTemplate and the given model.
func NewModel ¶
NewModel creates a langchaingo model from flowbot model configuration. Provider reasoning is enabled per request in StreamAssistant via ReasoningCallOptions because langchaingo exposes extended thinking through GenerateContent call options.
func ProviderForModel ¶ added in v0.94.0
ProviderForModel returns the configured provider name for a model.
func ReasoningCallOptions ¶ added in v0.94.0
func ReasoningCallOptions(modelName string, maxTokens int) []llms.CallOption
ReasoningCallOptions returns per-request call options that enable provider reasoning streams. Langchaingo applies extended thinking through GenerateContent options rather than model construction.
func ResetModelPoolForTest ¶
func ResetModelPoolForTest()
ResetModelPoolForTest clears cached langchaingo models.
func SetModelCreatorForTest ¶
func SetModelCreatorForTest(fn modelCreatorFn)
SetModelCreatorForTest overrides model construction used by GetOrCreateModel.
func SupportsReasoningStream ¶ added in v0.94.0
SupportsReasoningStream reports whether a model should use reasoning stream callbacks.
Types ¶
type AssistantResult ¶
type AssistantResult struct {
Content string
ToolCalls []llms.ToolCall
ModelName string
StopReason string
Usage *Usage
}
AssistantResult is the normalized output of a streaming assistant request.
func StreamAssistant ¶
func StreamAssistant( ctx context.Context, model llms.Model, systemPrompt string, messages []llms.MessageContent, opts StreamOptions, ) (AssistantResult, error)
StreamAssistant performs a streaming LLM call and assembles the assistant result.
type ChatTemplate ¶
type ChatTemplate interface {
Format(ctx context.Context, data map[string]any) ([]llms.MessageContent, error)
}
ChatTemplate formats prompt data into langchaingo messages.
func BaseTemplate ¶
func BaseTemplate() ChatTemplate
BaseTemplate returns a minimal template without chat history for single-shot tasks.
func DefaultMultiChatTemplate ¶
func DefaultMultiChatTemplate() ChatTemplate
DefaultMultiChatTemplate returns the same template as DefaultTemplate for multi-turn chat.
func DefaultTemplate ¶
func DefaultTemplate() ChatTemplate
DefaultTemplate returns a chat template with language-aware system prompt and history support.
type FakeModel ¶
type FakeModel struct {
// contains filtered or unexported fields
}
FakeModel implements llms.Model with a queue of scripted responses.
func NewFakeModel ¶
func NewFakeModel(responses ...ResponseScript) *FakeModel
NewFakeModel creates a fake model with the given response sequence.
func (*FakeModel) Call ¶
func (f *FakeModel) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)
Call implements the deprecated llms.Model Call method.
func (*FakeModel) GenerateContent ¶
func (f *FakeModel) GenerateContent(ctx context.Context, _ []llms.MessageContent, options ...llms.CallOption) (*llms.ContentResponse, error)
GenerateContent returns the next scripted response.
type ResponseScript ¶
type ResponseScript struct {
Content string
// Chunks, when non-empty, are emitted one-by-one via StreamingFunc instead of Content as a single chunk.
Chunks []string
// ReasoningChunks are emitted via StreamingReasoningFunc when configured.
ReasoningChunks []string
ToolCalls []llms.ToolCall
Err error
}
ResponseScript describes one scripted model response for tests.