Argument of type 'AiTextGenerationOutput | ReadableStream<any>' is not assignable to parameter of type 'BodyInit | null | undefined'. Type '{ response?: string | undefined; }' is not assignable to type 'BodyInit | null | undefined'.Object literal may only specify known properties, and 'sessionOptions' does not exist in type 'AiOptions'.sessionOptions appears to not be a thing anymore, since it looks like 1.1.0, released almost a month ago. And the other error seems to just be bad types/code in the docs.UInt8Array being returned, but in some cases, it seems to be the raw ReadableStream<UInt8Array> from the underlying Fetcher that is used.Response object which can take either without any issue or error. But it is important if you want to do any other work that directly re-stream it back out the worker.stream option from text-gen for instances where you return directly a ReadableStream to remove the buffering (if desired)?Argument of type 'AiTextGenerationOutput | ReadableStream<any>' is not assignable to parameter of type 'BodyInit | null | undefined'. Type '{ response?: string | undefined; }' is not assignable to type 'BodyInit | null | undefined'.Object literal may only specify known properties, and 'sessionOptions' does not exist in type 'AiOptions'.sessionOptions1.1.0UInt8ArrayReadableStream<UInt8Array>FetcherReadableStreamimport { Ai } from '@cloudflare/ai'
interface Env {
AI: Fetcher;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const ai = new Ai(env.AI, { sessionOptions: { ctx }});
const number = Math.random();
const response = await ai.run('@cf/mistral/mistral-7b-instruct-v0.1', {
prompt: `I have ${number} apples. How many apples do I have?"`,
stream: true
});
return new Response(response);
},
};