CloudflareAI for better streaming

This commit is contained in:
Dhravya 2024-04-13 01:53:50 -07:00
parent ad422c6b66
commit f0b2412a8b
2 changed files with 6 additions and 2 deletions

View file

@ -139,7 +139,8 @@ export async function POST(request: Request, _: CloudflareVectorizeStore, embedd
// );
// return response;
const ai = new Ai(env?.AI);
const output: AiTextGenerationOutput = (await ai.run('@hf/thebloke/mistral-7b-instruct-v0.1-awq', {
// @ts-ignore
const output: AiTextGenerationOutput = (await ai.run('@hf/mistralai/mistral-7b-instruct-v0.2', {
prompt,
stream: true,
})) as ReadableStream;

View file

@ -374,7 +374,10 @@ export function Chat({
loading={i === chatHistory.length - 1 ? isLoading : false}
sources={msg.answer.sources}
>
{msg.answer.parts.map((part) => part.text).join(" ")}
{msg.answer.parts
.map((part) => part.text)
.join("")
.replace("</s>", "")}
</ChatAnswer>
</ChatMessage>
))}