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

Streaming endpoints #36

Open
zamoshchin opened this issue Jul 19, 2023 · 1 comment
Open

Streaming endpoints #36

zamoshchin opened this issue Jul 19, 2023 · 1 comment

Comments

@zamoshchin
Copy link

zamoshchin commented Jul 19, 2023

I'm getting a 502 (bad gateway) when calling my serverless function (API endpoint) that has a streaming response:

src/routes/api/soap/format.ts

...
export const POST: RequestHandler = async ({ request }) => {
  response = await openai.createChatCompletion({
      model: model,
      messages: [{ role: 'user', content: prompt }],
      stream: true,
    }, { responseType: 'stream' }
  );

  const customReadable = new ReadableStream({
    start(controller) {
      response.data.on('data', (data: Buffer) => {
        // ...etc
      });
    }
  });
  
  return new Response(customReadable, {
    headers: { 'Content-Type': 'text/html; charset=utf-8' },
  });
  ...

This works locally. Any idea what needs to be adjusted on CloudFront or Lambda to allow for streaming output?

@yarbsemaj
Copy link
Owner

Unfortunately, my adapter does not yet support request streaming, Amazon actually added support for request streaming for lambda a few months ago https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/. It’s not something that’s on my horizon to implement, but would appreciate a pull request if you would like to implement

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

No branches or pull requests

2 participants