From c758651a509aea6c50d01c740b16e0da798ce606 Mon Sep 17 00:00:00 2001 From: JexSrs Date: Thu, 23 May 2024 00:29:11 +0300 Subject: [PATCH] Fixed mandatory WithStream when stream is false --- functions.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/functions.go b/functions.go index 64195cc..70966c5 100644 --- a/functions.go +++ b/functions.go @@ -98,6 +98,10 @@ func (o *Ollama) newChatFunc() ChatFunc { req.Stream = pointer(false) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + // Include chat history or create a new chat if chatId != nil { chat := o.chats[*chatId] @@ -185,6 +189,10 @@ func (o *Ollama) newGenerateFunc() GenerateFunc { req.Stream = pointer(false) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + var stream func(b []byte) if req.StreamFunc != nil { stream = func(b []byte) { @@ -263,6 +271,10 @@ func (o *Ollama) newCreateModelFunc() CreateModelFunc { f(&req) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + var stream func(b []byte) if req.StreamFunc != nil { stream = func(b []byte) { @@ -384,6 +396,10 @@ func (o *Ollama) newPullModelFunc() PullModelFunc { f(&req) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + var stream func(b []byte) if req.StreamFunc != nil { stream = func(b []byte) { @@ -421,6 +437,10 @@ func (o *Ollama) newPushModelFunc() PushModelFunc { f(&req) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + var stream func(b []byte) if req.StreamFunc != nil { stream = func(b []byte) { @@ -458,6 +478,10 @@ func (o *Ollama) newGenerateEmbeddingsFunc() GenerateEmbeddingsFunc { f(&req) } + if req.StreamBufferSize == nil { + req.StreamBufferSize = pointer(1024) + } + body, err := o.Do("/api/embeddings", req, 0, nil) if err != nil { return nil, err