ai 2.1.34 → 2.2.0
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 +3 -4
- package/dist/index.d.ts +9 -10
- package/package.json +2 -2
- package/prompts/dist/index.d.ts +2 -2
- package/react/dist/index.d.ts +7 -8
- package/solid/dist/index.d.ts +5 -6
- package/svelte/dist/index.d.ts +7 -8
- package/svelte/dist/index.js +3 -1
- package/svelte/dist/index.mjs +3 -1
- package/vue/dist/index.d.ts +5 -6
package/README.md
CHANGED
@@ -23,19 +23,18 @@ With the Vercel AI SDK, you can build a ChatGPT-like app in just a few lines of
|
|
23
23
|
|
24
24
|
```tsx
|
25
25
|
// ./app/api/chat/route.js
|
26
|
-
import
|
26
|
+
import OpenAI from 'openai'
|
27
27
|
import { OpenAIStream, StreamingTextResponse } from 'ai'
|
28
28
|
|
29
|
-
const
|
29
|
+
const openai = new OpenAI({
|
30
30
|
apiKey: process.env.OPENAI_API_KEY
|
31
31
|
})
|
32
|
-
const openai = new OpenAIApi(config)
|
33
32
|
|
34
33
|
export const runtime = 'edge'
|
35
34
|
|
36
35
|
export async function POST(req) {
|
37
36
|
const { messages } = await req.json()
|
38
|
-
const response = await openai.
|
37
|
+
const response = await openai.chat.completions.create({
|
39
38
|
model: 'gpt-4',
|
40
39
|
stream: true,
|
41
40
|
messages
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
1
|
+
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
3
2
|
import { ServerResponse } from 'node:http';
|
4
3
|
import { Prediction } from 'replicate';
|
5
4
|
|
@@ -109,7 +108,7 @@ type Message = {
|
|
109
108
|
* contains the function call name and arguments. Otherwise, the field should
|
110
109
|
* not be set.
|
111
110
|
*/
|
112
|
-
function_call?: string |
|
111
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
113
112
|
};
|
114
113
|
type CreateMessage = Omit<Message, 'id'> & {
|
115
114
|
id?: Message['id'];
|
@@ -117,18 +116,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
117
116
|
type ChatRequest = {
|
118
117
|
messages: Message[];
|
119
118
|
options?: RequestOptions;
|
120
|
-
functions?: Array<
|
121
|
-
function_call?:
|
119
|
+
functions?: Array<CompletionCreateParams.Function>;
|
120
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
122
121
|
};
|
123
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
122
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
|
124
123
|
type RequestOptions = {
|
125
124
|
headers?: Record<string, string> | Headers;
|
126
125
|
body?: object;
|
127
126
|
};
|
128
127
|
type ChatRequestOptions = {
|
129
128
|
options?: RequestOptions;
|
130
|
-
functions?: Array<
|
131
|
-
function_call?:
|
129
|
+
functions?: Array<CompletionCreateParams.Function>;
|
130
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
132
131
|
};
|
133
132
|
type UseChatOptions = {
|
134
133
|
/**
|
@@ -262,7 +261,7 @@ type OpenAIStreamCallbacks = AIStreamCallbacks & {
|
|
262
261
|
/**
|
263
262
|
* @example
|
264
263
|
* ```js
|
265
|
-
* const response = await openai.
|
264
|
+
* const response = await openai.chat.completions.create({
|
266
265
|
* model: 'gpt-3.5-turbo-0613',
|
267
266
|
* stream: true,
|
268
267
|
* messages,
|
@@ -275,7 +274,7 @@ type OpenAIStreamCallbacks = AIStreamCallbacks & {
|
|
275
274
|
* const result = await myFunction(functionCallPayload)
|
276
275
|
*
|
277
276
|
* // Ask for another completion, or return a string to send to the client as an assistant message.
|
278
|
-
* return await openai.
|
277
|
+
* return await openai.chat.completions.create({
|
279
278
|
* model: 'gpt-3.5-turbo-0613',
|
280
279
|
* stream: true,
|
281
280
|
* // Append the relevant "assistant" and "function" call messages
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.2.0",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -61,6 +61,7 @@
|
|
61
61
|
"dependencies": {
|
62
62
|
"eventsource-parser": "1.0.0",
|
63
63
|
"nanoid": "3.3.6",
|
64
|
+
"openai": "4.0.0",
|
64
65
|
"solid-swr-store": "0.10.7",
|
65
66
|
"sswr": "2.0.0",
|
66
67
|
"swr": "2.2.0",
|
@@ -75,7 +76,6 @@
|
|
75
76
|
"@types/react-dom": "^18.2.0",
|
76
77
|
"eslint": "^7.32.0",
|
77
78
|
"jest": "29.2.1",
|
78
|
-
"openai-edge": "^1.1.0",
|
79
79
|
"replicate": "^0.16.0",
|
80
80
|
"ts-jest": "29.0.3",
|
81
81
|
"tsup": "^6.7.0",
|
package/prompts/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ChatCompletionMessage } from 'openai/resources/chat';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* Shared types between the API and UI packages.
|
@@ -18,7 +18,7 @@ type Message = {
|
|
18
18
|
* contains the function call name and arguments. Otherwise, the field should
|
19
19
|
* not be set.
|
20
20
|
*/
|
21
|
-
function_call?: string |
|
21
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
22
22
|
};
|
23
23
|
|
24
24
|
/**
|
package/react/dist/index.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
1
|
+
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
3
2
|
|
4
3
|
/**
|
5
4
|
* Shared types between the API and UI packages.
|
@@ -19,7 +18,7 @@ type Message = {
|
|
19
18
|
* contains the function call name and arguments. Otherwise, the field should
|
20
19
|
* not be set.
|
21
20
|
*/
|
22
|
-
function_call?: string |
|
21
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
23
22
|
};
|
24
23
|
type CreateMessage = Omit<Message, 'id'> & {
|
25
24
|
id?: Message['id'];
|
@@ -27,18 +26,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
27
26
|
type ChatRequest = {
|
28
27
|
messages: Message[];
|
29
28
|
options?: RequestOptions;
|
30
|
-
functions?: Array<
|
31
|
-
function_call?:
|
29
|
+
functions?: Array<CompletionCreateParams.Function>;
|
30
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
32
31
|
};
|
33
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
32
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
|
34
33
|
type RequestOptions = {
|
35
34
|
headers?: Record<string, string> | Headers;
|
36
35
|
body?: object;
|
37
36
|
};
|
38
37
|
type ChatRequestOptions = {
|
39
38
|
options?: RequestOptions;
|
40
|
-
functions?: Array<
|
41
|
-
function_call?:
|
39
|
+
functions?: Array<CompletionCreateParams.Function>;
|
40
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
42
41
|
};
|
43
42
|
type UseChatOptions = {
|
44
43
|
/**
|
package/solid/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Resource, Accessor, Setter } from 'solid-js';
|
2
|
-
import {
|
3
|
-
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
2
|
+
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
4
3
|
|
5
4
|
/**
|
6
5
|
* Shared types between the API and UI packages.
|
@@ -20,7 +19,7 @@ type Message = {
|
|
20
19
|
* contains the function call name and arguments. Otherwise, the field should
|
21
20
|
* not be set.
|
22
21
|
*/
|
23
|
-
function_call?: string |
|
22
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
24
23
|
};
|
25
24
|
type CreateMessage = Omit<Message, 'id'> & {
|
26
25
|
id?: Message['id'];
|
@@ -28,10 +27,10 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
28
27
|
type ChatRequest = {
|
29
28
|
messages: Message[];
|
30
29
|
options?: RequestOptions;
|
31
|
-
functions?: Array<
|
32
|
-
function_call?:
|
30
|
+
functions?: Array<CompletionCreateParams.Function>;
|
31
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
33
32
|
};
|
34
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
33
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
|
35
34
|
type RequestOptions = {
|
36
35
|
headers?: Record<string, string> | Headers;
|
37
36
|
body?: object;
|
package/svelte/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Readable, Writable } from 'svelte/store';
|
2
|
-
import {
|
3
|
-
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
2
|
+
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
4
3
|
|
5
4
|
/**
|
6
5
|
* Shared types between the API and UI packages.
|
@@ -20,7 +19,7 @@ type Message = {
|
|
20
19
|
* contains the function call name and arguments. Otherwise, the field should
|
21
20
|
* not be set.
|
22
21
|
*/
|
23
|
-
function_call?: string |
|
22
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
24
23
|
};
|
25
24
|
type CreateMessage = Omit<Message, 'id'> & {
|
26
25
|
id?: Message['id'];
|
@@ -28,18 +27,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
28
27
|
type ChatRequest = {
|
29
28
|
messages: Message[];
|
30
29
|
options?: RequestOptions;
|
31
|
-
functions?: Array<
|
32
|
-
function_call?:
|
30
|
+
functions?: Array<CompletionCreateParams.Function>;
|
31
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
33
32
|
};
|
34
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
33
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
|
35
34
|
type RequestOptions = {
|
36
35
|
headers?: Record<string, string> | Headers;
|
37
36
|
body?: object;
|
38
37
|
};
|
39
38
|
type ChatRequestOptions = {
|
40
39
|
options?: RequestOptions;
|
41
|
-
functions?: Array<
|
42
|
-
function_call?:
|
40
|
+
functions?: Array<CompletionCreateParams.Function>;
|
41
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
43
42
|
};
|
44
43
|
type UseChatOptions = {
|
45
44
|
/**
|
package/svelte/dist/index.js
CHANGED
@@ -626,7 +626,9 @@ var getStreamedResponse = async (api, chatRequest, mutate, extraMetadata, previo
|
|
626
626
|
}
|
627
627
|
}
|
628
628
|
if (typeof responseMessage.function_call === "string") {
|
629
|
-
const parsedFunctionCall = JSON.parse(
|
629
|
+
const parsedFunctionCall = JSON.parse(
|
630
|
+
responseMessage.function_call
|
631
|
+
).function_call;
|
630
632
|
responseMessage.function_call = parsedFunctionCall;
|
631
633
|
mutate([...chatRequest.messages, { ...responseMessage }]);
|
632
634
|
}
|
package/svelte/dist/index.mjs
CHANGED
@@ -599,7 +599,9 @@ var getStreamedResponse = async (api, chatRequest, mutate, extraMetadata, previo
|
|
599
599
|
}
|
600
600
|
}
|
601
601
|
if (typeof responseMessage.function_call === "string") {
|
602
|
-
const parsedFunctionCall = JSON.parse(
|
602
|
+
const parsedFunctionCall = JSON.parse(
|
603
|
+
responseMessage.function_call
|
604
|
+
).function_call;
|
603
605
|
responseMessage.function_call = parsedFunctionCall;
|
604
606
|
mutate([...chatRequest.messages, { ...responseMessage }]);
|
605
607
|
}
|
package/vue/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Ref } from 'vue';
|
2
|
-
import {
|
3
|
-
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
2
|
+
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
4
3
|
|
5
4
|
/**
|
6
5
|
* Shared types between the API and UI packages.
|
@@ -20,7 +19,7 @@ type Message = {
|
|
20
19
|
* contains the function call name and arguments. Otherwise, the field should
|
21
20
|
* not be set.
|
22
21
|
*/
|
23
|
-
function_call?: string |
|
22
|
+
function_call?: string | ChatCompletionMessage.FunctionCall;
|
24
23
|
};
|
25
24
|
type CreateMessage = Omit<Message, 'id'> & {
|
26
25
|
id?: Message['id'];
|
@@ -28,10 +27,10 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
28
27
|
type ChatRequest = {
|
29
28
|
messages: Message[];
|
30
29
|
options?: RequestOptions;
|
31
|
-
functions?: Array<
|
32
|
-
function_call?:
|
30
|
+
functions?: Array<CompletionCreateParams.Function>;
|
31
|
+
function_call?: CreateChatCompletionRequestMessage.FunctionCall;
|
33
32
|
};
|
34
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
33
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
|
35
34
|
type RequestOptions = {
|
36
35
|
headers?: Record<string, string> | Headers;
|
37
36
|
body?: object;
|