Comments (3)
It works perfectly! Be mindful of costs depending on your provider. Edge functions might be significantly cheaper (and faster).
from ai.
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.
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.
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)
- Bug in `streamUI` and `createStreamableUI` HOT 2
- Make `Message` `createdAt` key required HOT 1
- Streamable UI slow to update error HOT 4
- Provider APIs (`doStream`, et al.) are not usable outside of AI SDK
- Cannot use `name` field in Chat Completion messages (CoreMessage, LanguageModelV1Message)
- Registry not accepting google provider HOT 2
- Error in implementing in nodejs HOT 6
- getMutableAIState(key [keyof AI Context]) update() and done() didn't change object reference
- useAssistant: option to ignore annotations in text deltas
- Bedrock: can't use AWS metadata service for authentication HOT 1
- Save chat to database on onSetAIState is not working correctly if connection_limit is set to high HOT 3
- vLLM Provider HOT 1
- Ending `textStream.done()` in `streamUI()` causes another render in component after version `>=3.2.6`
- Add Azure Extensions to the Azure provider
- Add support for edit history
- Create a tool to summarise results HOT 6
- AI_TypeValidationError: Optional type validation in generateObject function. HOT 13
- Model Registry non-standard parameters
- Cannot use zod tuple() in tool schema HOT 2
- Vercel AI SDK Incompatibility with Latest Perplexity API Updates HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ai.