Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AiTextToImageOutput type from UInt8Array -> ReadableStream #2757

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

dochne
Copy link
Contributor

@dochne dochne commented Sep 20, 2024

As noted in #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");
}

@dochne dochne requested review from a team as code owners September 20, 2024 15:43
@dochne dochne requested review from mikea and fhanau September 20, 2024 15:43
Copy link

github-actions bot commented Sep 20, 2024

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

@dochne
Copy link
Contributor Author

dochne commented Sep 20, 2024

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

github-actions bot added a commit that referenced this pull request Sep 20, 2024
types/defines/ai.d.ts Outdated Show resolved Hide resolved
@fhanau fhanau requested a review from G4brym September 20, 2024 15:45
@dario-piotrowicz dario-piotrowicz merged commit 0241b66 into cloudflare:main Sep 30, 2024
11 checks passed
@dario-piotrowicz
Copy link
Member

Thanks a bunch again for the fix @dochne 🫶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants