this repo has no description

Switch to streamed output

Changed files
+6 -2
src
+6 -2
src/rewrite.ts
···
import { debug } from 'debug';
import { createFallback } from 'ai-fallback';
-
import { generateText } from 'ai';
+
import { streamText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';
import { createOllama } from 'ollama-ai-provider';
import * as fs from 'node:fs/promises';
···
}
} catch {}
log('prompting to rewrite', url.pathname);
-
const { text } = await generateText({
+
const { textStream } = streamText({
model: createFallback({
models: [
ollama('mistral-small3.1:24b'),
···
system: SYSTEM_PROMPT.trim(),
prompt: input,
});
+
const output = [];
+
for await (const chunk of textStream)
+
output.push(chunk);
+
const text = output.join('');
await fs.writeFile(cacheFile, text, 'utf-8');
return text;
}