ai 2.1.2 → 2.1.3

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/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Vercel AI SDK
2
+
3
+ The Vercel AI SDK is **a library for building edge-ready AI-powered streaming text and chat UIs**.
4
+
5
+ ## Features
6
+
7
+ - [SWR](https://swr.vercel.app)-powered React, Svelte and Vue helpers for streaming text responses and building chat and completion UIs
8
+ - First-class support for [LangChain](js.langchain.com/docs) and [OpenAI](https://openai.com), [Anthropic](https://www.anthropic.com), and [HuggingFace](https://huggingface.co)
9
+ - [Edge Runtime](https://edge-runtime.vercel.app/) compatibility
10
+ - Callbacks for saving completed streaming responses to a database (in the same request)
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pnpm install ai
16
+ ```
17
+
18
+ ## Example: An AI Chatbot with Next.js and OpenAI
19
+
20
+ With the Vercel AI SDK, you can build a ChatGPT-like app in just a few lines of code:
21
+
22
+ ```tsx
23
+ // ./app/api/chat/route.js
24
+ import { Configuration, OpenAIApi } from 'openai-edge'
25
+ import { OpenAIStream, StreamingTextResponse } from 'ai'
26
+
27
+ const config = new Configuration({
28
+ apiKey: process.env.OPENAI_API_KEY
29
+ })
30
+ const openai = new OpenAIApi(config)
31
+
32
+ export const runtime = 'edge'
33
+
34
+ export async function POST(req) {
35
+ const { messages } = await req.json()
36
+ const response = await openai.createChatCompletion({
37
+ model: 'gpt-4',
38
+ stream: true,
39
+ messages
40
+ })
41
+ const stream = OpenAIStream(response)
42
+ return new StreamingTextResponse(stream)
43
+ }
44
+ ```
45
+
46
+ ```tsx
47
+ // ./app/page.js
48
+ 'use client'
49
+
50
+ import { useChat } from 'ai/react'
51
+
52
+ export default function Chat() {
53
+ const { messages, input, handleInputChange, handleSubmit } = useChat()
54
+
55
+ return (
56
+ <div>
57
+ {messages.map(m => (
58
+ <div key={m.id}>
59
+ {m.role}: {m.content}
60
+ </div>
61
+ ))}
62
+
63
+ <form onSubmit={handleSubmit}>
64
+ <input
65
+ value={input}
66
+ placeholder="Say something..."
67
+ onChange={handleInputChange}
68
+ />
69
+ </form>
70
+ </div>
71
+ )
72
+ }
73
+ ```
74
+
75
+ ---
76
+
77
+ View the full documentation and examples on [play.vercel.ai/docs](https://play.vercel.ai/docs)
78
+
79
+ ## Authors
80
+
81
+ This library is created by [Vercel](https://vercel.com) and [Next.js](https://nextjs.org) team members, with contributions from:
82
+
83
+ - Jared Palmer ([@jaredpalmer](https://twitter.com/jaredpalmer)) - [Vercel](https://vercel.com)
84
+ - Shu Ding ([@shuding\_](https://twitter.com/shuding_)) - [Vercel](https://vercel.com)
85
+ - Max Leiter ([@max_leiter](https://twitter.com/max_leiter)) - [Vercel](https://vercel.com)
86
+ - Malte Ubl ([@cramforce](https://twitter.com/cramforce)) - [Vercel](https://vercel.com)
87
+ - Justin Ridgewell ([@jridgewell](https://github.com/jridgewell)) - [Vercel](https://vercel.com)
88
+
89
+ [Contributors](https://github.com/vercel-labs/ai/graphs/contributors)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -250,7 +250,8 @@ function useChat({
250
250
  return;
251
251
  append({
252
252
  content: input,
253
- role: "user"
253
+ role: "user",
254
+ createdAt: /* @__PURE__ */ new Date()
254
255
  });
255
256
  setInput("");
256
257
  },
@@ -216,7 +216,8 @@ function useChat({
216
216
  return;
217
217
  append({
218
218
  content: input,
219
- role: "user"
219
+ role: "user",
220
+ createdAt: /* @__PURE__ */ new Date()
220
221
  });
221
222
  setInput("");
222
223
  },
@@ -659,7 +659,8 @@ function useChat({
659
659
  return;
660
660
  append({
661
661
  content: inputValue,
662
- role: "user"
662
+ role: "user",
663
+ createdAt: /* @__PURE__ */ new Date()
663
664
  });
664
665
  input.set("");
665
666
  };
@@ -635,7 +635,8 @@ function useChat({
635
635
  return;
636
636
  append({
637
637
  content: inputValue,
638
- role: "user"
638
+ role: "user",
639
+ createdAt: /* @__PURE__ */ new Date()
639
640
  });
640
641
  input.set("");
641
642
  };