Skip to content

Commit f962ce4

Browse files
authored
Fix: only append abort message when error is cancelled (#996)
Signed-off-by: Daishan Peng <[email protected]>
1 parent 9d5e315 commit f962ce4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/openai/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
689689
for {
690690
response, err := stream.Recv()
691691
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
692-
if len(partialMessage.Content) > 0 && partialMessage.Content[0].Text == "" {
692+
if len(partialMessage.Content) > 0 && partialMessage.Content[0].Text == "" && errors.Is(err, context.Canceled) {
693693
// Place a text holder if LLM doesn't respond or user cancel the stream before it can produce any response.
694694
// In anthropic models it will yield an error about non-empty message for assistant message
695695
partialMessage.Content[0].Text = "User aborted the chat or chat finished before LLM can respond"

0 commit comments

Comments
 (0)