Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
increase streaming buffer size (#692)
Bruce MacDonald9e2de1bd2c09
diff --git a/api/client.go b/api/client.goindex 87975a9f4..99c1daa1f 100644--- a/api/client.go+++ b/api/client.go@@ -18,9 +18,7 @@ import (const DefaultHost = "127.0.0.1:11434"-var (- envHost = os.Getenv("OLLAMA_HOST")-)+var envHost = os.Getenv("OLLAMA_HOST")type Client struct {Base url.URL@@ -123,6 +121,8 @@ func (c *Client) do(ctx context.Context, method, path string, reqData, respDatareturn nil}+const maxBufferSize = 512 * 1024 // 512KB+func (c *Client) stream(ctx context.Context, method, path string, data any, fn func([]byte) error) error {var buf *bytes.Bufferif data != nil {@@ -151,6 +151,9 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn fdefer response.Body.Close()scanner := bufio.NewScanner(response.Body)+ // increase the buffer size to avoid running out of space+ scanBuf := make([]byte, 0, maxBufferSize)+ scanner.Buffer(scanBuf, maxBufferSize)for scanner.Scan() {var errorResponse struct {Error string `json:"error,omitempty"`diff --git a/llm/llama.go b/llm/llama.goindex f9bb451d0..0d9e8d5dd 100644--- a/llm/llama.go+++ b/llm/llama.go@@ -438,6 +438,8 @@ type PredictRequest struct {Stop []string `json:"stop,omitempty"`}+const maxBufferSize = 512 * 1024 // 512KB+func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string, fn func(api.GenerateResponse)) error {prevConvo, err := llm.Decode(ctx, prevContext)if err != nil {@@ -498,6 +500,9 @@ func (llm *llama) Predict(ctx context.Context, prevContext []int, prompt string,}scanner := bufio.NewScanner(resp.Body)+ // increase the buffer size to avoid running out of space+ buf := make([]byte, 0, maxBufferSize)+ scanner.Buffer(buf, maxBufferSize)for scanner.Scan() {select {case <-ctx.Done():