mistralai / client-js

JS Client library for Mistral AI platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client does not return a response

chanmathew opened this issue · comments

Hi there,

Running the latest version of the SDK 0.1.3, but when I try to init and call the client, it does not return anything.

Here is my code:

const mistral = new MistralClient(env.PUBLIC_MISTRAL_API_KEY)
const response = await mistral.chatStream({
	model: 'mistral-large-latest',
	messages: [{ role: 'system', content: 'Say hello world.' }],
	temperature: 0
})

// response is an empty object {}

I can give this one a try.

chatStream is a generator function

client: MistralClient {
_request: [AsyncFunction: _request],
_makeChatCompletionRequest: [Function: _makeChatCompletionRequest],
listModels: [AsyncFunction: listModels],
chat: [AsyncFunction: chat],
chatStream: [AsyncGeneratorFunction: chatStream],
embeddings: [AsyncFunction: embeddings],
endpoint: 'https://api.mistral.ai',
apiKey: '********',
maxRetries: 5,
timeout: 120,
modelDefault: 'mistral'
}

This is not necessary. You are supposed to use as so:

import MistralClient from '@mistralai/mistralai';
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?'}],
});
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);
}
}