ai 0.0.0-156c9f7b-20250115085202

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.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ ![hero illustration](./assets/hero.gif)
2
+
3
+ # AI SDK
4
+
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
+
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).
8
+
9
+ ## Installation
10
+
11
+ You will need Node.js 18+ and pnpm installed on your local development machine.
12
+
13
+ ```shell
14
+ npm install ai
15
+ ```
16
+
17
+ ## Usage
18
+
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.
24
+
25
+ ```shell
26
+ npm install @ai-sdk/openai
27
+ ```
28
+
29
+ ###### @/index.ts (Node.js Runtime)
30
+
31
+ ```ts
32
+ import { generateText } from 'ai';
33
+ import { openai } from '@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is set
34
+
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
+ ```
43
+
44
+ ### AI SDK UI
45
+
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
113
+
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).