Skip to content

Commit 4937c07

Browse files
committed
Add some missing documentation for AI
1 parent 1551825 commit 4937c07

1 file changed

Lines changed: 49 additions & 13 deletions

File tree

docs/ai.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ In practice, when files are uploaded/modified/deleted, the trigger will create
3535
a job for the index worker (with debounce). The index worker will look at the
3636
changed feed, and will call the RAG for each entry in the changes feed.
3737

38+
By default, only text-based files are indexed. Images, videos, and audio files
39+
can be indexed by enabling the following feature flags:
40+
41+
- `rag.index.image.enabled`
42+
- `rag.index.video.enabled`
43+
- `rag.index.audio.enabled`
44+
3845
## openRAG
3946

4047
Some openRAG API are directly exposed through cozy-stack.
@@ -46,15 +53,17 @@ This route directly follows the [openAI chat completion AI](https://platform.ope
4653

4754
#### Request
4855

56+
```http
4957
POST /ai/v1/chat/completions HTTP/1.1
5058
Content-Type: application/json
59+
```
5160

5261
```json
5362
{
5463
"messages": [
5564
{ "role": "user", "content": "Hello there, what's in your mind?" }
5665
],
57-
"temperature": 0.3
66+
"temperature": 0.3
5867
}
5968
```
6069

@@ -152,10 +161,19 @@ Content-Type: application/json
152161

153162
```json
154163
{
155-
"q": "Why the sky is blue?"
164+
"q": "Why the sky is blue?",
165+
"stream": true,
166+
"websearch": false,
167+
"assistantID": "abc123"
156168
}
157169
```
158170

171+
- `q` is the user's message (required).
172+
- `stream` enables streaming the response via SSE deltas (defaults to `true`).
173+
- `websearch` enables web search for the query (defaults to `false`).
174+
- `assistantID` associates the conversation with an `io.cozy.ai.chat.assistants`
175+
document (optional). When set, the response includes a `relationships` block.
176+
159177
#### Response
160178

161179
```http
@@ -177,21 +195,31 @@ Content-Type: application/vnd.api+json
177195
"content": "Why the sky is blue?",
178196
"createdAt": "2024-09-24T13:24:07.576Z"
179197
}
180-
]
198+
],
199+
"relationships": {
200+
"assistant": {
201+
"data": {
202+
"id":"b2e1a4144c123ec694697d996102983a",
203+
"type":"io.cozy.ai.chat.assistants"
204+
}
205+
}
206+
},
207+
"cozyMetadata": {
208+
"createdAt": "2024-09-24T13:24:07.576Z",
209+
"createdOn": "http://cozy.localhost:8080/",
210+
"doctypeVersion": "1",
211+
"metadataVersion": 1,
212+
"updatedAt": "2024-09-24T13:24:07.576Z"
213+
}
181214
}
182-
},
183-
"cozyMetadata": {
184-
"createdAt": "2024-09-24T13:24:07.576Z",
185-
"createdOn": "http://cozy.localhost:8080/",
186-
"doctypeVersion": "1",
187-
"metadataVersion": 1,
188-
"updatedAt": "2024-09-24T13:24:07.576Z"
189215
}
190216
}
191217
```
192218

193219
### Real-time via websockets
194220

221+
#### Messages flow example
222+
195223
```
196224
client > {"method": "AUTH", "payload": "token"}
197225
client > {"method": "SUBSCRIBE",
@@ -208,13 +236,21 @@ server > {"event": "CREATED",
208236
server > {"event": "CREATED",
209237
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
210238
"type": "io.cozy.ai.chat.events",
211-
"doc": {"object": "generated"}}}
239+
"doc": {"object": "sources", "content": [{"id": "827f0fbb928b375cc457c732a4013aa7", "doctype": "io.cozy.files"}]}}}
212240
server > {"event": "CREATED",
213241
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
214242
"type": "io.cozy.ai.chat.events",
215-
"doc": {"object": "sources", "content": [{"id": "827f0fbb928b375cc457c732a4013aa7", "doctype": "io.cozy.files"}]}}}
243+
"doc": {"object": "done"}}}
244+
```
245+
246+
#### Error message
247+
248+
If an error occurs while processing the AI response (e.g. the LLM is
249+
unavailable), an error event is sent instead:
250+
251+
```
216252
server > {"event": "CREATED",
217253
"payload": {"id": "eb17c3205bf1013ddea018c04daba326",
218254
"type": "io.cozy.ai.chat.events",
219-
"doc": {"object": "done"}}}
255+
"doc": {"object": "error", "message": "I don't want to talk today"}}}
220256
```

0 commit comments

Comments
 (0)