Skip to content

Commit c2d01c8

Browse files
committed
Add more info about the Error Handling
1 parent c34ad20 commit c2d01c8

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

guides/ai/getting_started_with_chat.mdx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,61 @@ for await (const chunk of stream) {
214214
215215
</CodeGroup>
216216
217+
## Error handling
218+
219+
When using the OpenAI SDK with Meilisearch's chat completions endpoint, errors from the streamed responses are natively handled by the official OpenAI SDK. This means you can use the SDK's built-in error handling mechanisms without additional configuration:
220+
221+
<CodeGroup>
222+
223+
```javascript JavaScript
224+
import OpenAI from 'openai';
225+
226+
const client = new OpenAI({
227+
baseURL: 'http://localhost:7700/chats/my-assistant',
228+
apiKey: 'YOUR_MEILISEARCH_API_KEY',
229+
});
230+
231+
try {
232+
const stream = await client.chat.completions.create({
233+
model: 'gpt-3.5-turbo',
234+
messages: [{ role: 'user', content: 'What is Meilisearch?' }],
235+
stream: true,
236+
});
237+
238+
for await (const chunk of stream) {
239+
console.log(chunk.choices[0]?.delta?.content || '');
240+
}
241+
} catch (error) {
242+
// OpenAI SDK automatically handles streaming errors
243+
console.error('Chat completion error:', error);
244+
}
245+
```
246+
247+
```python Python
248+
from openai import OpenAI
249+
250+
client = OpenAI(
251+
base_url="http://localhost:7700/chats/my-assistant",
252+
api_key="YOUR_MEILISEARCH_API_KEY"
253+
)
254+
255+
try:
256+
stream = client.chat.completions.create(
257+
model="gpt-3.5-turbo",
258+
messages=[{"role": "user", "content": "What is Meilisearch?"}],
259+
stream=True,
260+
)
261+
262+
for chunk in stream:
263+
if chunk.choices[0].delta.content is not None:
264+
print(chunk.choices[0].delta.content, end="")
265+
except Exception as error:
266+
# OpenAI SDK automatically handles streaming errors
267+
print(f"Chat completion error: {error}")
268+
```
269+
270+
</CodeGroup>
271+
217272
## Next steps
218273
219274
- Explore [advanced chat API features](/reference/api/chats)

reference/api/settings.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,6 @@ Partially update the index chat settings for an index.
30283028
"matchingStrategy": <String>,
30293029
"attributesToSearchOn": <String>,
30303030
"rankingScoreThreshold": <Float>,
3031-
"limit": <Integer>,
30323031
}
30333032
}
30343033
```

0 commit comments

Comments
 (0)