cloudflare / workerd

The JavaScript / Wasm runtime that powers Cloudflare Workers
https://blog.cloudflare.com/workerd-open-source-workers-runtime/
Apache License 2.0
6.11k stars 290 forks source link

Fix AiTextToImageOutput type from UInt8Array -> ReadableStream #2757

Open dochne opened 1 week ago

dochne commented 1 week ago

As noted in https://github.com/cloudflare/workerd/issues/2470 - the response type from env.AI.run with (in my case) @cf/bytedance/stable-diffusion-xl-lightning claims it should return a UInt8Array, but actually returns a ReadableStream.

This is fine when feeding it into a new Response() and returning, but is problematic when trying to use the data in other ways.

You can replicate this with the example model usage here

[ai]
binding = "AI"
export interface Env {
  AI: Ai;
}

export default {
  async fetch(request, env, ctx): Promise<Response> {
  const inputs = {prompt: "cyberpunk cat"};

  const response = await env.AI.run(
    "@cf/bytedance/stable-diffusion-xl-lightning",
    inputs
  );

  // Expected: Uint8Array. Actual: ReadableStream
  console.log(response);
  return new Response("Don't error");
}
github-actions[bot] commented 1 week ago

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

dochne commented 1 week ago

I have read the CLA Document and I hereby sign the CLA