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

added error handling code #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions examples/chat_no_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

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

console.log('Chat:', chatResponse.choices[0].message.content);
try {
const chatResponse = await client.chat({
model: 'mistral-tiny',
messages: [{role: 'user', content: 'What is the best French cheese?'}],
});
console.log('Chat:', chatResponse.choices[0].message.content);
} catch (error) {
console.log(error);
}
22 changes: 13 additions & 9 deletions examples/chat_with_streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

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

console.log('Chat Stream:');
for await (const chunk of chatStreamResponse) {
if (chunk.choices[0].delta.content !== undefined) {
const streamText = chunk.choices[0].delta.content;
process.stdout.write(streamText);
console.log('Chat Stream:');
for await (const chunk of chatStreamResponse) {
if (chunk.choices[0].delta.content !== undefined) {
const streamText = chunk.choices[0].delta.content;
process.stdout.write(streamText);
}
}
} catch (error) {
console.log(error);
}
15 changes: 9 additions & 6 deletions examples/embeddings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ for (let i = 0; i < 1; i++) {
input.push('What is the best French cheese?');
}

const embeddingsBatchResponse = await client.embeddings({
model: 'mistral-embed',
input: input,
});

console.log('Embeddings Batch:', embeddingsBatchResponse.data);
try {
const embeddingsBatchResponse = await client.embeddings({
model: 'mistral-embed',
input: input,
});
console.log('Embeddings Batch:', embeddingsBatchResponse.data);
} catch (error) {
console.log(error);
}
13 changes: 8 additions & 5 deletions examples/list_models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const listModelsResponse = await client.listModels();

listModelsResponse.data.forEach((model) => {
console.log('Model:', model);
});
try {
const listModelsResponse = await client.listModels();
listModelsResponse.data.forEach((model) => {
console.log('Model:', model);
});
} catch (error) {
console.log(error);
}