mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
* feat(vertex): added vertex to list of supported providers * added utils files for each provider, consolidated gemini utils, added dynamic verbosity and reasoning fetcher
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
/**
|
|
* Creates a ReadableStream from a Mistral AI streaming response
|
|
* @param mistralStream - The Mistral AI stream object
|
|
* @param onComplete - Optional callback when streaming completes
|
|
* @returns A ReadableStream that yields text chunks
|
|
*/
|
|
export function createReadableStreamFromMistralStream(
|
|
mistralStream: any,
|
|
onComplete?: (content: string, usage?: any) => void
|
|
): ReadableStream {
|
|
let fullContent = ''
|
|
let usageData: any = null
|
|
|
|
return new ReadableStream({
|
|
async start(controller) {
|
|
try {
|
|
for await (const chunk of mistralStream) {
|
|
if (chunk.usage) {
|
|
usageData = chunk.usage
|
|
}
|
|
|
|
const content = chunk.choices[0]?.delta?.content || ''
|
|
if (content) {
|
|
fullContent += content
|
|
controller.enqueue(new TextEncoder().encode(content))
|
|
}
|
|
}
|
|
|
|
if (onComplete) {
|
|
onComplete(fullContent, usageData)
|
|
}
|
|
|
|
controller.close()
|
|
} catch (error) {
|
|
controller.error(error)
|
|
}
|
|
},
|
|
})
|
|
}
|