diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-17 09:05:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-17 09:05:45 +0300 |
| commit | d5fbb6ef5957894eb5be0854bdb328a6774abddb (patch) | |
| tree | 7558a3d1c70db85d54f3367a5c81c28e7260392b /internal/llm/provider.go | |
| parent | 5d9e197a394089f66539320e77abb3f3689b3381 (diff) | |
cli: stream responses in hexai when supported (OpenAI, Ollama)
- Add llm.Streamer optional interface
- Implement ChatStream for OpenAI (SSE) and Ollama (JSON stream)
- CLI uses streaming; LSP unchanged (non-streaming)
- README: document streaming behavior for CLI
Diffstat (limited to 'internal/llm/provider.go')
| -rw-r--r-- | internal/llm/provider.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/internal/llm/provider.go b/internal/llm/provider.go index dda3d16..3e3023e 100644 --- a/internal/llm/provider.go +++ b/internal/llm/provider.go @@ -15,12 +15,22 @@ type Message struct { // 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) - // Name returns the provider's short name (e.g., "openai", "ollama"). - Name() string - // DefaultModel returns the configured default model name. - DefaultModel() string + // Chat sends chat messages and returns the assistant text. + Chat(ctx context.Context, messages []Message, opts ...RequestOption) (string, error) + // Name returns the provider's short name (e.g., "openai", "ollama"). + Name() string + // DefaultModel returns the configured default model name. + DefaultModel() string +} + +// Streamer is an optional interface that providers may implement to support +// token-by-token streaming responses. Callers can type-assert to Streamer and +// fall back to Client.Chat when not implemented. +type Streamer interface { + // ChatStream sends chat messages and invokes onDelta with incremental text + // chunks as they are produced by the model. Implementations should call + // onDelta with empty strings sparingly (prefer only non-empty chunks). + ChatStream(ctx context.Context, messages []Message, onDelta func(string), opts ...RequestOption) error } // Options for a request. Providers may ignore unsupported fields. |
