ai 0.0.0-85f9a635-20240518005312 → 0.0.0-8777c42a-20250115032312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +2863 -0
  2. package/README.md +99 -22
  3. package/dist/index.d.mts +1925 -1592
  4. package/dist/index.d.ts +1925 -1592
  5. package/dist/index.js +5500 -2961
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +5497 -2916
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +39 -100
  10. package/react/dist/index.d.mts +8 -563
  11. package/react/dist/index.d.ts +8 -580
  12. package/react/dist/index.js +7 -1395
  13. package/react/dist/index.js.map +1 -1
  14. package/react/dist/index.mjs +12 -1383
  15. package/react/dist/index.mjs.map +1 -1
  16. package/rsc/dist/index.d.ts +340 -197
  17. package/rsc/dist/rsc-server.d.mts +339 -197
  18. package/rsc/dist/rsc-server.mjs +1295 -1347
  19. package/rsc/dist/rsc-server.mjs.map +1 -1
  20. package/rsc/dist/rsc-shared.d.mts +30 -23
  21. package/rsc/dist/rsc-shared.mjs +69 -105
  22. package/rsc/dist/rsc-shared.mjs.map +1 -1
  23. package/test/dist/index.d.mts +67 -0
  24. package/test/dist/index.d.ts +67 -0
  25. package/test/dist/index.js +131 -0
  26. package/test/dist/index.js.map +1 -0
  27. package/test/dist/index.mjs +101 -0
  28. package/test/dist/index.mjs.map +1 -0
  29. package/prompts/dist/index.d.mts +0 -324
  30. package/prompts/dist/index.d.ts +0 -324
  31. package/prompts/dist/index.js +0 -178
  32. package/prompts/dist/index.js.map +0 -1
  33. package/prompts/dist/index.mjs +0 -146
  34. package/prompts/dist/index.mjs.map +0 -1
  35. package/react/dist/index.server.d.mts +0 -17
  36. package/react/dist/index.server.d.ts +0 -17
  37. package/react/dist/index.server.js +0 -50
  38. package/react/dist/index.server.js.map +0 -1
  39. package/react/dist/index.server.mjs +0 -23
  40. package/react/dist/index.server.mjs.map +0 -1
  41. package/solid/dist/index.d.mts +0 -408
  42. package/solid/dist/index.d.ts +0 -408
  43. package/solid/dist/index.js +0 -1072
  44. package/solid/dist/index.js.map +0 -1
  45. package/solid/dist/index.mjs +0 -1044
  46. package/solid/dist/index.mjs.map +0 -1
  47. package/svelte/dist/index.d.mts +0 -484
  48. package/svelte/dist/index.d.ts +0 -484
  49. package/svelte/dist/index.js +0 -1778
  50. package/svelte/dist/index.js.map +0 -1
  51. package/svelte/dist/index.mjs +0 -1749
  52. package/svelte/dist/index.mjs.map +0 -1
  53. package/vue/dist/index.d.mts +0 -402
  54. package/vue/dist/index.d.ts +0 -402
  55. package/vue/dist/index.js +0 -1072
  56. package/vue/dist/index.js.map +0 -1
  57. package/vue/dist/index.mjs +0 -1034
  58. package/vue/dist/index.mjs.map +0 -1
package/README.md CHANGED
@@ -1,37 +1,114 @@
1
- # Vercel AI SDK
1
+ ![hero illustration](./assets/hero.gif)
2
2
 
3
- The Vercel AI SDK is **a library for building AI-powered streaming text and chat UIs**.
3
+ # AI SDK
4
4
 
5
- ## Features
5
+ The [AI SDK](https://sdk.vercel.ai/docs) is a TypeScript toolkit designed to help you build AI-powered applications using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
6
6
 
7
- - React, Svelte, Vue and Solid helpers for streaming text responses and building chat and completion UIs
8
- - React Server Components API for streaming [Generative UI](https://vercel.com/blog/ai-sdk-3-generative-ui)
9
- - First-class support for [OpenAI](https://openai.com), [Anthropic](https://www.anthropic.com), [Mistral](https://mistral.ai), [Perplexity](https://perplexity.ai), [AWS Bedrock](https://aws.amazon.com/bedrock/), [Azure](https://ai.azure.com), [Google Gemini](https://ai.google.dev), [Hugging Face](https://huggingface.co), [Fireworks](https://app.fireworks.ai), [Cohere](https://cohere.com), [LangChain](https://js.langchain.com/docs), [Replicate](https://replicate.com), Ollama, and more.
10
- - Node.js, Serverless, and [Edge Runtime](https://edge-runtime.vercel.app/) support
11
- - Lifecycle callbacks for saving completed streaming responses to a database (in the same request)
7
+ To learn more about how to use the AI SDK, check out our [API Reference](https://sdk.vercel.ai/docs/reference) and [Documentation](https://sdk.vercel.ai/docs).
12
8
 
13
9
  ## Installation
14
10
 
15
- ```sh
16
- pnpm install ai
11
+ You will need Node.js 18+ and pnpm installed on your local development machine.
12
+
13
+ ```shell
14
+ npm install ai
17
15
  ```
18
16
 
19
- View the full documentation and examples on [sdk.vercel.ai/docs](https://sdk.vercel.ai/docs).
17
+ ## Usage
20
18
 
21
- ## Authors
19
+ ### AI SDK Core
20
+
21
+ The [AI SDK Core](https://sdk.vercel.ai/docs/ai-sdk-core/overview) module provides a unified API to interact with model providers like [OpenAI](https://sdk.vercel.ai/providers/ai-sdk-providers/openai), [Anthropic](https://sdk.vercel.ai/providers/ai-sdk-providers/anthropic), [Google](https://sdk.vercel.ai/providers/ai-sdk-providers/google-generative-ai), and more.
22
+
23
+ You will then install the model provider of your choice.
22
24
 
23
- This library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from:
25
+ ```shell
26
+ npm install @ai-sdk/openai
27
+ ```
28
+
29
+ ###### @/index.ts (Node.js Runtime)
24
30
 
25
- - Jared Palmer ([@jaredpalmer](https://twitter.com/jaredpalmer)) - [Vercel](https://vercel.com)
26
- - Shu Ding ([@shuding\_](https://twitter.com/shuding_)) - [Vercel](https://vercel.com)
27
- - Max Leiter ([@max_leiter](https://twitter.com/max_leiter)) - [Vercel](https://vercel.com)
28
- - Malte Ubl ([@cramforce](https://twitter.com/cramforce)) - [Vercel](https://vercel.com)
29
- - Justin Ridgewell ([@jridgewell](https://github.com/jridgewell))
31
+ ```ts
32
+ import { generateText } from 'ai';
33
+ import { openai } from '@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is set
30
34
 
31
- [Contributors](https://github.com/vercel/ai/graphs/contributors)
35
+ const { text } = await generateText({
36
+ model: openai('gpt-4o'),
37
+ system: 'You are a friendly assistant!',
38
+ prompt: 'Why is the sky blue?',
39
+ });
40
+
41
+ console.log(text);
42
+ ```
32
43
 
33
- ## Related: Deploy your own Next.js AI Chatbot
44
+ ### AI SDK UI
34
45
 
35
- If you're looking to for a full AI Chatbot application to jumpstart your AI journey, you should checkout [our sister OSS AI Chatbot project](https://github.com/vercel/ai-chatbot) or click the button below to deploy your own to [Vercel](https://vercel.com).
46
+ The [AI SDK UI](https://sdk.vercel.ai/docs/ai-sdk-ui/overview) module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, Vue, and SolidJS.
47
+
48
+ ###### @/app/page.tsx (Next.js App Router)
49
+
50
+ ```tsx
51
+ 'use client';
52
+
53
+ import { useChat } from 'ai/react';
54
+
55
+ export default function Page() {
56
+ const { messages, input, handleSubmit, handleInputChange, isLoading } =
57
+ useChat();
58
+
59
+ return (
60
+ <div>
61
+ {messages.map(message => (
62
+ <div key={message.id}>
63
+ <div>{message.role}</div>
64
+ <div>{message.content}</div>
65
+ </div>
66
+ ))}
67
+
68
+ <form onSubmit={handleSubmit}>
69
+ <input
70
+ value={input}
71
+ placeholder="Send a message..."
72
+ onChange={handleInputChange}
73
+ disabled={isLoading}
74
+ />
75
+ </form>
76
+ </div>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ###### @/app/api/chat/route.ts (Next.js App Router)
82
+
83
+ ```ts
84
+ import { streamText } from 'ai';
85
+ import { openai } from '@ai-sdk/openai';
86
+
87
+ export async function POST(req: Request) {
88
+ const { messages } = await req.json();
89
+
90
+ const result = streamText({
91
+ model: openai('gpt-4o'),
92
+ system: 'You are a helpful assistant.',
93
+ messages,
94
+ });
95
+
96
+ return result.toDataStreamResponse();
97
+ }
98
+ ```
99
+
100
+ ## Templates
101
+
102
+ We've built [templates](https://vercel.com/templates?type=ai) that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application.
103
+
104
+ ## Community
105
+
106
+ The AI SDK community can be found on [GitHub Discussions](https://github.com/vercel/ai/discussions) where you can ask questions, voice ideas, and share your projects with other people.
107
+
108
+ ## Contributing
109
+
110
+ Contributions to the AI SDK are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](https://github.com/vercel/ai/blob/main/CONTRIBUTING.md) to make sure you have smooth experience contributing to AI SDK.
111
+
112
+ ## Authors
36
113
 
37
- [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/templates/Next.js/nextjs-ai-chatbot)
114
+ This library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from the [Open Source Community](https://github.com/vercel/ai/graphs/contributors).