ai
ai copied to clipboard
Documentation basic example for Mistral does not work
Description
I was trying to launch example from this page https://sdk.vercel.ai/docs/guides/providers/mistral But it didn't work for me. The API key is correct but it seems that my POST handler does not respond. Even if I put some console.log at the very beginning of route handler - it won't be executed. It seems that the problem is in client. When I remove Mistral client creation at least route starts to respond.
Code example
import { OpenAIStream, StreamingTextResponse } from 'ai';
// Note: There are no types for the Mistral API client yet. // @ts-ignore import MistralClient from '@mistralai/mistralai';
const client = new MistralClient(process.env.MISTRAL_API_KEY || '');
export async function POST(req: Request) {
console.log('~~~ START POST HANDLER');
// Extract the messages
from the body of the request
const { messages } = await req.json();
const response = await client.chatStream({ model: 'mistral-tiny', stream: true, max_tokens: 1000, messages, });
// Convert the response into a friendly text-stream. The Mistral client responses are // compatible with the Vercel AI SDK OpenAIStream adapter. const stream = OpenAIStream(response);
// Respond with the stream return new StreamingTextResponse(stream); }
Additional context
No response
same, broken using edge
runtime in backend API route: Error [TypeError]: edgeFunction is not a function
switch to nodejs
runtime and does not error, but just stalls loading forever, no response, no console logs, very odd.
Same issue here. I don't think the JS client is returning anything, see bug I opened here: https://github.com/mistralai/client-js/issues/50
We have a new provider architecture since v3.1 - please checkout this page: https://sdk.vercel.ai/providers/ai-sdk-providers/mistral