llm

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OllamaDefaultURL   = "http://localhost:11434"
	OllamaDefaultModel = "llama3.2"
	OpenAIDefaultURL   = "https://api.openai.com/v1"
	OpenAIDefaultModel = "gpt-4o-mini"
)

Defaults used by each backend when llm.model or llm.base_url is not set. core.ResolveBackends applies them, so `inode config show` can print them.

View Source
const ClaudeDefaultModel = string(anthropic.ModelClaudeSonnet5_5)

ClaudeDefaultModel is used when llm.model is not set. Taken from the SDK so the linter flags it when Anthropic deprecates the model.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Classify returns category, tags, sensitivity, and a one-line summary.
	// Called when a note is added without explicit metadata.
	Classify(ctx context.Context, content string, categories []model.Category, tags []string) (ClassifyResult, error)

	// Answer performs RAG generation: query + retrieved notes → structured response.
	// The response carries both the natural-language answer and a flag telling the
	// caller whether the notes were actually useful (so callers can hide "Sources"
	// blocks when the LLM rejected every candidate).
	Answer(ctx context.Context, query string, notes []*model.Note) (AnswerResult, error)

	// Summarize returns a one-line description of the note content.
	Summarize(ctx context.Context, content string) (string, error)
}

Adapter defines the contract for all LLM backends. Implementations: claude.go, ollama.go.

type AnswerResult

type AnswerResult struct {
	Answer      string
	Matched     bool
	UsedNoteIDs []string
}

AnswerResult is the structured output from RAG answer generation.

Matched is true iff the LLM concluded that at least one of the provided notes contained the answer. UsedNoteIDs holds short-prefix IDs of the notes the LLM actually used; the search layer filters the retrieved notes down to these so the CLI only displays sources that contributed.

When Matched is false, UsedNoteIDs is empty and Answer is the LLM's natural-language explanation that the answer is not in the notes.

type ClassifyResult

type ClassifyResult struct {
	Category    string
	Tags        []string
	IsSensitive bool
	Summary     string
}

ClassifyResult is the structured output from LLM classification.

type ClaudeAdapter

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

ClaudeAdapter implements LLMAdapter using the Anthropic Claude API.

func NewClaudeAdapter

func NewClaudeAdapter(apiKey, modelName string) *ClaudeAdapter

NewClaudeAdapter creates a Claude API adapter.

func (*ClaudeAdapter) Answer

func (c *ClaudeAdapter) Answer(ctx context.Context, query string, notes []*model.Note) (AnswerResult, error)

Answer performs RAG generation — retrieved notes as context, Claude answers. Returns a structured result so the caller knows whether the notes were actually useful and which ones the model relied on.

func (*ClaudeAdapter) Classify

func (c *ClaudeAdapter) Classify(ctx context.Context, content string, categories []model.Category, tags []string) (ClassifyResult, error)

Classify sends note content to Claude and returns structured metadata.

func (*ClaudeAdapter) Summarize

func (c *ClaudeAdapter) Summarize(ctx context.Context, content string) (string, error)

Summarize returns a one-line description of note content.

type OllamaAdapter

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

OllamaAdapter implements LLMAdapter using a local Ollama server.

func NewOllamaAdapter

func NewOllamaAdapter(baseURL, modelName string) *OllamaAdapter

NewOllamaAdapter creates an adapter pointed at the given Ollama base URL.

func (*OllamaAdapter) Answer

func (o *OllamaAdapter) Answer(ctx context.Context, query string, notes []*model.Note) (AnswerResult, error)

Answer performs RAG generation using retrieved notes as context. Returns a structured result so the caller knows whether the notes were actually useful and which ones the model relied on.

func (*OllamaAdapter) Classify

func (o *OllamaAdapter) Classify(ctx context.Context, content string, categories []model.Category, tags []string) (ClassifyResult, error)

Classify returns category, tags, sensitivity, and a one-line summary.

func (*OllamaAdapter) Summarize

func (o *OllamaAdapter) Summarize(ctx context.Context, content string) (string, error)

Summarize returns a one-line description of note content.

type OpenAIAdapter

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

OpenAIAdapter implements the LLM Adapter using the OpenAI Chat Completions API. It talks plain HTTP (no SDK dependency) so the binary stays lean and `go install` needs no extra modules, mirroring the Ollama adapter's style, but pointed at OpenAI with Bearer auth and JSON-mode responses.

func NewOpenAIAdapter

func NewOpenAIAdapter(apiKey, modelName, baseURL string) *OpenAIAdapter

NewOpenAIAdapter creates an adapter for the OpenAI Chat Completions API. baseURL defaults to the public API; override it to target Azure OpenAI, a gateway, or a compatible endpoint. modelName defaults to a fast, cheap model.

func (*OpenAIAdapter) Answer

func (o *OpenAIAdapter) Answer(ctx context.Context, query string, notes []*model.Note) (AnswerResult, error)

Answer performs RAG generation using retrieved notes as context. Returns a structured result so the caller knows whether the notes were actually useful and which ones the model relied on.

func (*OpenAIAdapter) Classify

func (o *OpenAIAdapter) Classify(ctx context.Context, content string, categories []model.Category, tags []string) (ClassifyResult, error)

Classify returns category, tags, sensitivity, and a one-line summary.

func (*OpenAIAdapter) Summarize

func (o *OpenAIAdapter) Summarize(ctx context.Context, content string) (string, error)

Summarize returns a one-line description of note content.

Jump to

Keyboard shortcuts

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