You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I haven't been able to navigate the type constraints around using mistral.chat.stream . The example in the docs works with 1 message specified in a literal, but when trying to use multiple messages, inputted by the user, in a multi-statement chat... I just can't figure out the types. I have looked at the source/type defs and it seems so complex that I feel I must be missing something simple. Is there an example anywhere that shows how to use it?
For example, this is a very simple extrapolation of the given sample:
import { ChatCompletionStreamRequest, AssistantMessage, UserMessage, UserMessageContent } from '@mistralai/mistralai/models/components';
const msg: UserMessage = {
content: "Who is the best French painter? Answer in one short sentence.",
role: "user",
};
let myval: ChatCompletionStreamRequest = {
model: "mistral-small-latest",
messages: [msg]
};
const result = await mistral.chat.stream(myval);
But Typescript complains...
Type 'UserMessage' is not assignable to type '(SystemMessage & { role: "system"; }) | (UserMessage & { role: "user"; }) | (AssistantMessage & { role: "assistant"; }) | (ToolMessage & { ...; })'.
Type 'UserMessage' is not assignable to type 'UserMessage & { role: "user"; }'.
Type 'UserMessage' is not assignable to type '{ role: "user"; }'.
Types of property 'role' are incompatible.
Type '"user" | undefined' is not assignable to type '"user"'.
Type 'undefined' is not assignable to type '"user"'.
In my app, I need to retrieve a chat from the db, add the latest prompt, and stream an answer back to the browser. I was able to get it working in the old JS client, but I ran into some fetch compatibility problems, so I'm trying to upgrade to the TS client.
Thank you!
The text was updated successfully, but these errors were encountered:
For now I'm using a workaround "any" type. From my sample above:
const msg: UserMessage = {
content: "Who is the best French painter? Answer in one short sentence.",
role: "user",
};
let messageArr: any = [msg];
let myval: ChatCompletionStreamRequest = {
model: "mistral-small-latest",
messages: messageArr
};
const result = await mistral.chat.stream(myval);
Hello! I haven't been able to navigate the type constraints around using mistral.chat.stream . The example in the docs works with 1 message specified in a literal, but when trying to use multiple messages, inputted by the user, in a multi-statement chat... I just can't figure out the types. I have looked at the source/type defs and it seems so complex that I feel I must be missing something simple. Is there an example anywhere that shows how to use it?
For example, this is a very simple extrapolation of the given sample:
But Typescript complains...
In my app, I need to retrieve a chat from the db, add the latest prompt, and stream an answer back to the browser. I was able to get it working in the old JS client, but I ran into some fetch compatibility problems, so I'm trying to upgrade to the TS client.
Thank you!
The text was updated successfully, but these errors were encountered: