Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
nicer examples for chat streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Dec 9, 2023
1 parent d66218f commit 6499236
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions examples/chat_no_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ const chatResponse = await client.chat({
messages: [{role: 'user', content: 'What is the best French cheese?'}],
});

console.log('Chat:', chatResponse);

console.log('Chat:', chatResponse.choices[0].message);
console.log('Chat:', chatResponse.choices[0].message.content);
8 changes: 6 additions & 2 deletions examples/chat_with_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ const apiKey = process.env.MISTRAL_API_KEY;
const client = new MistralClient(apiKey);

const chatStreamResponse = await client.chatStream({
model: 'mistral-medium',
model: 'mistral-tiny',
messages: [{role: 'user', content: 'What is the best French cheese?'}],
});

console.log('Chat Stream:');
for await (const chunk of chatStreamResponse) {
console.log('Chat Stream:', JSON.stringify(chunk));
if (chunk.choices[0].delta.content !== undefined) {
const streamText = chunk.choices[0].delta.content;
process.stdout.write(streamText);
}
}
1 change: 0 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ class MistralClient {
true,
safeMode,
);
console.log(request);
const response = await this._request(
'post', 'v1/chat/completions', request,
);
Expand Down

0 comments on commit 6499236

Please sign in to comment.