Add streaming infrastructure: - SSE line parser handling multi-line data, comments, [DONE] sentinel - Generic Stream[T] pull-based iterator (no goroutines, no channel leaks) - doStream() HTTP helper for streaming endpoints - ChatCompleteStream() method - 28 new tests: SSE edge cases, iterator behavior, httptest integration
28 lines
905 B
Go
28 lines
905 B
Go
package mistral
|
|
|
|
import (
|
|
"context"
|
|
|
|
"somegit.dev/vikingowl/mistral-go-sdk/chat"
|
|
)
|
|
|
|
// ChatComplete sends a chat completion request and returns the full response.
|
|
func (c *Client) ChatComplete(ctx context.Context, req *chat.CompletionRequest) (*chat.CompletionResponse, error) {
|
|
var resp chat.CompletionResponse
|
|
if err := c.doJSON(ctx, "POST", "/v1/chat/completions", req, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
// ChatCompleteStream sends a chat completion request and returns a stream
|
|
// of completion chunks. The caller must call Close() on the returned stream.
|
|
func (c *Client) ChatCompleteStream(ctx context.Context, req *chat.CompletionRequest) (*Stream[chat.CompletionChunk], error) {
|
|
req.SetStream(true)
|
|
resp, err := c.doStream(ctx, "POST", "/v1/chat/completions", req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return newStream[chat.CompletionChunk](resp.Body), nil
|
|
}
|