llm

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripCodeFences

func StripCodeFences(s string) string

StripCodeFences removes markdown code fences (```json ... ```) that some models wrap around JSON responses. Returns the original string if no fences found.

Types

type AnthropicClient

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

AnthropicClient wraps the Anthropic Go SDK and implements LLMClient.

func NewAnthropicClient

func NewAnthropicClient(apiKey string) *AnthropicClient

NewAnthropicClient creates an AnthropicClient authenticated with apiKey.

func (*AnthropicClient) Complete

func (a *AnthropicClient) Complete(ctx context.Context, model, systemPrompt, userMessage string, maxTokens int) (string, error)

Complete sends a single-turn request to the Anthropic Messages API and returns the first text block from the response.

type GatewayClient

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

GatewayClient sends completions through an OpenAI-compatible HTTP gateway. It implements LLMClient.

func NewGatewayClient

func NewGatewayClient(baseURL, token string) *GatewayClient

NewGatewayClient creates a GatewayClient that POSTs to baseURL/v1/chat/completions authenticated with token.

func (*GatewayClient) Complete

func (g *GatewayClient) Complete(ctx context.Context, model, systemPrompt, userMessage string, maxTokens int) (string, error)

Complete sends a single-turn request to the gateway and returns the model reply.

type LLMClient

type LLMClient interface {
	Complete(ctx context.Context, model, systemPrompt, userMessage string, maxTokens int) (string, error)
}

LLMClient is the interface for sending a single-turn completion to a language model. All implementations must be safe for concurrent use.

func NewClient

func NewClient(cfg config.ClaudeConfig) LLMClient

NewClient returns the appropriate LLMClient based on cfg.

Priority:

  1. GatewayURL + GatewayToken set → GatewayClient (OpenAI-compatible gateway)
  2. APIKey set → AnthropicClient (direct Anthropic SDK)
  3. Neither set → nil (no LLM available; callers must guard against this)

Jump to

Keyboard shortcuts

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