diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-16 14:58:03 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-16 14:58:03 +0300 |
| commit | 1e1df8c204f6771719f85d8402128d72138bb863 (patch) | |
| tree | 20508d35f86625ff5b74b509176111ffde163605 /internal/llm/provider.go | |
| parent | a6a8b84690c50767f714b413496b5aeb45b31c21 (diff) | |
llm: add pluggable provider with OpenAI default; extensive logging; LSP completion integration with TextEdit, param-aware prompts; remove idle gating; label/filter improvements; docs update
Diffstat (limited to 'internal/llm/provider.go')
| -rw-r--r-- | internal/llm/provider.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/llm/provider.go b/internal/llm/provider.go new file mode 100644 index 0000000..fd9d4d3 --- /dev/null +++ b/internal/llm/provider.go @@ -0,0 +1,49 @@ +package llm + +import ( + "context" + "errors" + "log" + "os" +) + +// Message represents a chat-style prompt message. +type Message struct { + Role string + Content string +} + +// Client is a minimal LLM provider interface. +// Future providers (Ollama, etc.) should implement this. +type Client interface { + // Chat sends chat messages and returns the assistant text. + Chat(ctx context.Context, messages []Message, opts ...RequestOption) (string, error) +} + +// Options for a request. Providers may ignore unsupported fields. +type Options struct { + Model string + Temperature float64 + MaxTokens int + Stop []string +} + +// RequestOption mutates Options. +type RequestOption func(*Options) + +func WithModel(model string) RequestOption { return func(o *Options) { o.Model = model } } +func WithTemperature(t float64) RequestOption { return func(o *Options) { o.Temperature = t } } +func WithMaxTokens(n int) RequestOption { return func(o *Options) { o.MaxTokens = n } } +func WithStop(stop ...string) RequestOption { + return func(o *Options) { o.Stop = append([]string{}, stop...) } +} + +// NewDefault returns the default provider using environment configuration. +// Currently this is the OpenAI provider using OPENAI_API_KEY. +func NewDefault(logger *log.Logger) (Client, error) { + apiKey := os.Getenv("OPENAI_API_KEY") + if apiKey == "" { + return nil, errors.New("OPENAI_API_KEY is not set") + } + return newOpenAIFromEnv(apiKey, logger), nil +} |
