diff --git a/chat.go b/chat.go index ef2ab79..5d8b77b 100644 --- a/chat.go +++ b/chat.go @@ -276,6 +276,8 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { for iteration := range raw.Iterations { debug("iteration %d of %d", iteration+1, raw.Iterations) + response.Send(StartChunk()) + if len(request.Tools) > 0 && iteration == raw.Iterations-1 { debug("no more tool calls") @@ -341,6 +343,8 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { tool.AsAssistantToolCall(message), tool.AsToolMessage(), ) + + response.Send(EndChunk()) } } diff --git a/stream.go b/stream.go index 8338fc5..493fe0c 100644 --- a/stream.go +++ b/stream.go @@ -13,7 +13,7 @@ import ( type Chunk struct { Type string `json:"type"` - Text any `json:"text"` + Text any `json:"text,omitempty"` } type Stream struct { @@ -72,6 +72,18 @@ func IDChunk(id string) Chunk { } } +func EndChunk() Chunk { + return Chunk{ + Type: "end", + } +} + +func StartChunk() Chunk { + return Chunk{ + Type: "start", + } +} + func ErrorChunk(err error) Chunk { return Chunk{ Type: "error",