GithubHelp home page GithubHelp logo

What about Serverless Functions? about ai HOT 3 CLOSED

vercel avatar vercel commented on July 23, 2024
What about Serverless Functions?

from ai.

Comments (3)

jaredpalmer avatar jaredpalmer commented on July 23, 2024

It works perfectly! Be mindful of costs depending on your provider. Edge functions might be significantly cheaper (and faster).

from ai.

NickHeiner avatar NickHeiner commented on July 23, 2024

I think it would be helpful to add an example to the docs. 😄

I'm fumbling around with it myself, but I'm not able to get something working:

export default async function handler(req: VercelRequest, res: VercelResponse) {
  // Ask OpenAI for a streaming completion given the prompt
  const response = await openai.createCompletion({
    model: 'text-davinci-003',
    stream: true,
    prompt: 'List 20 dog names',
  });
 
  // Convert the response into a friendly text-stream
  const stream = OpenAIStream(response);

  streamToResponse(stream, res);
}

When I run this, I get a short response:

curl --no-buffer http://localhost:3000/api/demo
1. Spot
2. Milo
3. Max
4.⏎ 

Based on what I see in the playground, I think the full response is longer, and I'm doing the streaming wrong, such that it's only returning the first chunk.

image

Maybe --no-buffer is not what I should pass to curl? (Removing that flag doesn't change the behavior I see.) When I visit that endpoint in the browser, I get the same result.

This is the branch in which I'm seeing this, in case it's helpful.

from ai.

NickHeiner avatar NickHeiner commented on July 23, 2024

Actually, never mind – I figured it out. I think the issue is just that I wasn't setting max_tokens in my code, but the Playground defaulted it to 200.

from ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.