ai 2.1.8 → 2.1.10
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/dist/index.d.ts +57 -12
- package/dist/index.js +56 -2
- package/dist/index.mjs +53 -2
- package/package.json +9 -8
- package/react/dist/index.d.ts +73 -19
- package/react/dist/index.js +160 -82
- package/react/dist/index.mjs +160 -83
- package/svelte/dist/index.d.ts +50 -15
- package/svelte/dist/index.js +7 -3
- package/svelte/dist/index.mjs +7 -3
- package/vue/dist/index.d.ts +50 -15
- package/vue/dist/index.js +6 -2
- package/vue/dist/index.mjs +6 -2
package/vue/dist/index.d.ts
CHANGED
@@ -1,32 +1,49 @@
|
|
1
1
|
import { Ref } from 'vue';
|
2
|
+
import { ChatCompletionRequestMessageFunctionCall, CreateChatCompletionRequestFunctionCall } from 'openai-edge';
|
3
|
+
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
2
4
|
|
3
5
|
/**
|
4
6
|
* Shared types between the API and UI packages.
|
5
7
|
*/
|
6
|
-
|
8
|
+
type Message = {
|
7
9
|
id: string;
|
8
10
|
createdAt?: Date;
|
9
11
|
content: string;
|
10
|
-
role: 'system' | 'user' | 'assistant';
|
12
|
+
role: 'system' | 'user' | 'assistant' | 'function';
|
13
|
+
/**
|
14
|
+
* If the message has a role of `function`, the `name` field is the name of the function.
|
15
|
+
* Otherwise, the name field should not be set.
|
16
|
+
*/
|
17
|
+
name?: string;
|
18
|
+
/**
|
19
|
+
* If the assistant role makes a function call, the `function_call` field
|
20
|
+
* contains the function call name and arguments. Otherwise, the field should
|
21
|
+
* not be set.
|
22
|
+
*/
|
23
|
+
function_call?: string | ChatCompletionRequestMessageFunctionCall;
|
11
24
|
};
|
12
|
-
|
13
|
-
id?:
|
14
|
-
|
15
|
-
|
16
|
-
|
25
|
+
type CreateMessage = Omit<Message, 'id'> & {
|
26
|
+
id?: Message['id'];
|
27
|
+
};
|
28
|
+
type ChatRequest = {
|
29
|
+
messages: Message[];
|
30
|
+
options?: RequestOptions;
|
31
|
+
functions?: Array<ChatCompletionFunctions>;
|
32
|
+
function_call?: CreateChatCompletionRequestFunctionCall;
|
17
33
|
};
|
18
|
-
|
34
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionRequestMessageFunctionCall) => Promise<ChatRequest | void>;
|
35
|
+
type RequestOptions = {
|
19
36
|
headers?: Record<string, string> | Headers;
|
20
37
|
body?: object;
|
21
38
|
};
|
22
|
-
|
39
|
+
type UseChatOptions = {
|
23
40
|
/**
|
24
41
|
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
25
42
|
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
26
43
|
*/
|
27
44
|
api?: string;
|
28
45
|
/**
|
29
|
-
*
|
46
|
+
* A unique identifier for the chat. If not provided, a random one will be
|
30
47
|
* generated. When provided, the `useChat` hook with the same `id` will
|
31
48
|
* have shared states across components.
|
32
49
|
*/
|
@@ -39,6 +56,12 @@ declare type UseChatOptions = {
|
|
39
56
|
* Initial input of the chat.
|
40
57
|
*/
|
41
58
|
initialInput?: string;
|
59
|
+
/**
|
60
|
+
* Callback function to be called when a function call is received.
|
61
|
+
* If the function returns a `ChatRequest` object, the request will be sent
|
62
|
+
* automatically to the API and will be used to update the chat.
|
63
|
+
*/
|
64
|
+
experimental_onFunctionCall?: FunctionCallHandler;
|
42
65
|
/**
|
43
66
|
* Callback function to be called when the API response is received.
|
44
67
|
*/
|
@@ -51,6 +74,12 @@ declare type UseChatOptions = {
|
|
51
74
|
* Callback function to be called when an error is encountered.
|
52
75
|
*/
|
53
76
|
onError?: (error: Error) => void;
|
77
|
+
/**
|
78
|
+
* The credentials mode to be used for the fetch request.
|
79
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
80
|
+
* Defaults to 'same-origin'.
|
81
|
+
*/
|
82
|
+
credentials?: RequestCredentials;
|
54
83
|
/**
|
55
84
|
* HTTP headers to be sent with the API request.
|
56
85
|
*/
|
@@ -75,7 +104,7 @@ declare type UseChatOptions = {
|
|
75
104
|
*/
|
76
105
|
sendExtraMessageFields?: boolean;
|
77
106
|
};
|
78
|
-
|
107
|
+
type UseCompletionOptions = {
|
79
108
|
/**
|
80
109
|
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
81
110
|
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
@@ -107,6 +136,12 @@ declare type UseCompletionOptions = {
|
|
107
136
|
* Callback function to be called when an error is encountered.
|
108
137
|
*/
|
109
138
|
onError?: (error: Error) => void;
|
139
|
+
/**
|
140
|
+
* The credentials mode to be used for the fetch request.
|
141
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
142
|
+
* Defaults to 'same-origin'.
|
143
|
+
*/
|
144
|
+
credentials?: RequestCredentials;
|
110
145
|
/**
|
111
146
|
* HTTP headers to be sent with the API request.
|
112
147
|
*/
|
@@ -126,7 +161,7 @@ declare type UseCompletionOptions = {
|
|
126
161
|
body?: object;
|
127
162
|
};
|
128
163
|
|
129
|
-
|
164
|
+
type UseChatHelpers = {
|
130
165
|
/** Current messages in the chat */
|
131
166
|
messages: Ref<Message[]>;
|
132
167
|
/** The error object of the API request */
|
@@ -159,9 +194,9 @@ declare type UseChatHelpers = {
|
|
159
194
|
/** Whether the API request is in progress */
|
160
195
|
isLoading: Ref<boolean>;
|
161
196
|
};
|
162
|
-
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, headers, body }?: UseChatOptions): UseChatHelpers;
|
197
|
+
declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onResponse, onFinish, onError, credentials, headers, body }?: UseChatOptions): UseChatHelpers;
|
163
198
|
|
164
|
-
|
199
|
+
type UseCompletionHelpers = {
|
165
200
|
/** The current completion result */
|
166
201
|
completion: Ref<string>;
|
167
202
|
/** The error object of the API request */
|
@@ -193,6 +228,6 @@ declare type UseCompletionHelpers = {
|
|
193
228
|
/** Whether the API request is in progress */
|
194
229
|
isLoading: Ref<boolean>;
|
195
230
|
};
|
196
|
-
declare function useCompletion({ api, id, initialCompletion, initialInput, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers;
|
231
|
+
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers;
|
197
232
|
|
198
233
|
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion };
|
package/vue/dist/index.js
CHANGED
@@ -101,6 +101,7 @@ function useChat({
|
|
101
101
|
onResponse,
|
102
102
|
onFinish,
|
103
103
|
onError,
|
104
|
+
credentials,
|
104
105
|
headers,
|
105
106
|
body
|
106
107
|
} = {}) {
|
@@ -135,7 +136,8 @@ function useChat({
|
|
135
136
|
}))
|
136
137
|
}, body), options == null ? void 0 : options.body)),
|
137
138
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
138
|
-
signal: abortController.signal
|
139
|
+
signal: abortController.signal,
|
140
|
+
credentials
|
139
141
|
}).catch((err) => {
|
140
142
|
mutate(previousMessages);
|
141
143
|
throw err;
|
@@ -266,6 +268,7 @@ function useCompletion({
|
|
266
268
|
id,
|
267
269
|
initialCompletion = "",
|
268
270
|
initialInput = "",
|
271
|
+
credentials,
|
269
272
|
headers,
|
270
273
|
body,
|
271
274
|
onResponse,
|
@@ -299,7 +302,8 @@ function useCompletion({
|
|
299
302
|
prompt
|
300
303
|
}, body), options == null ? void 0 : options.body)),
|
301
304
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
302
|
-
signal: abortController.signal
|
305
|
+
signal: abortController.signal,
|
306
|
+
credentials
|
303
307
|
}).catch((err) => {
|
304
308
|
throw err;
|
305
309
|
});
|
package/vue/dist/index.mjs
CHANGED
@@ -67,6 +67,7 @@ function useChat({
|
|
67
67
|
onResponse,
|
68
68
|
onFinish,
|
69
69
|
onError,
|
70
|
+
credentials,
|
70
71
|
headers,
|
71
72
|
body
|
72
73
|
} = {}) {
|
@@ -101,7 +102,8 @@ function useChat({
|
|
101
102
|
}))
|
102
103
|
}, body), options == null ? void 0 : options.body)),
|
103
104
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
104
|
-
signal: abortController.signal
|
105
|
+
signal: abortController.signal,
|
106
|
+
credentials
|
105
107
|
}).catch((err) => {
|
106
108
|
mutate(previousMessages);
|
107
109
|
throw err;
|
@@ -232,6 +234,7 @@ function useCompletion({
|
|
232
234
|
id,
|
233
235
|
initialCompletion = "",
|
234
236
|
initialInput = "",
|
237
|
+
credentials,
|
235
238
|
headers,
|
236
239
|
body,
|
237
240
|
onResponse,
|
@@ -265,7 +268,8 @@ function useCompletion({
|
|
265
268
|
prompt
|
266
269
|
}, body), options == null ? void 0 : options.body)),
|
267
270
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
268
|
-
signal: abortController.signal
|
271
|
+
signal: abortController.signal,
|
272
|
+
credentials
|
269
273
|
}).catch((err) => {
|
270
274
|
throw err;
|
271
275
|
});
|