From d5fbb6ef5957894eb5be0854bdb328a6774abddb Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 17 Aug 2025 09:05:45 +0300 Subject: 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 --- internal/llm/provider.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'internal/llm/provider.go') 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. -- cgit v1.2.3