Skip to content

Commit bed84d4

Browse files
committed
fix: publish RAG error as realtime event to the client
When the RAG server returns a non-200 status (e.g. 413), the error was not sent to the client via realtime, so it could not display it. Now publish an error event before returning.
1 parent c54f628 commit bed84d4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

model/rag/chat.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,21 @@ func Query(inst *instance.Instance, logger logger.Logger, query QueryMessage) er
301301
return err
302302
}
303303
defer res.Body.Close()
304+
msg := chat.Messages[len(chat.Messages)-1]
305+
304306
if res.StatusCode != 200 {
305-
return fmt.Errorf("POST status code: %d", res.StatusCode)
307+
ragErr := fmt.Errorf("POST status code: %d", res.StatusCode)
308+
errorDoc := couchdb.JSONDoc{
309+
Type: consts.ChatEvents,
310+
M: map[string]interface{}{
311+
"_id": msg.ID,
312+
"object": "error",
313+
"message": ragErr.Error(),
314+
},
315+
}
316+
go realtime.GetHub().Publish(inst, realtime.EventCreate, &errorDoc, nil)
317+
return ragErr
306318
}
307-
308-
msg := chat.Messages[len(chat.Messages)-1]
309319
var completion string
310320
var sources []Source
311321

0 commit comments

Comments
 (0)