Skip to content

Commit

Permalink
Add position to io.cozy.ai.chat.events
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Oct 1, 2024
1 parent 6ebb03b commit 902130a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ client > {"method": "SUBSCRIBE",
server > {"event": "CREATED",
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
"type": "io.cozy.ai.chat.events",
"doc": {"object": "delta", "content": "The "}}}
"doc": {"object": "delta", "content": "The ", "position": 0}}}
server > {"event": "CREATED",
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
"type": "io.cozy.ai.chat.events",
"doc": {"object": "delta", "content": "sky "}}}
"doc": {"object": "delta", "content": "sky ", "position": 1}}}
[...]
server > {"event": "CREATED",
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
Expand Down
3 changes: 3 additions & 0 deletions model/rag/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ func Query(inst *instance.Instance, logger logger.Logger, query QueryMessage) er
}

msg := chat.Messages[len(chat.Messages)-1]
position := 0
var completion string
err = foreachSSE(res.Body, func(event map[string]interface{}) {
switch event["object"] {
case "delta", "done":
event["position"] = position
position++
content, _ := event["content"].(string)
completion += content
delta := couchdb.JSONDoc{
Expand Down

0 comments on commit 902130a

Please sign in to comment.