ai 2.1.9 → 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 +51 -8
- package/dist/index.js +30 -2
- package/dist/index.mjs +28 -2
- package/package.json +6 -5
- package/react/dist/index.d.ts +53 -12
- package/react/dist/index.js +134 -82
- package/react/dist/index.mjs +135 -83
- package/svelte/dist/index.d.ts +44 -9
- package/svelte/dist/index.js +7 -3
- package/svelte/dist/index.mjs +7 -3
- package/vue/dist/index.d.ts +44 -9
- package/vue/dist/index.js +6 -2
- package/vue/dist/index.mjs +6 -2
package/svelte/dist/index.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { Readable, Writable } from 'svelte/store';
|
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.
|
@@ -7,14 +9,29 @@ 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
|
-
type CreateMessage = {
|
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
|
};
|
34
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionRequestMessageFunctionCall) => Promise<ChatRequest | void>;
|
18
35
|
type RequestOptions = {
|
19
36
|
headers?: Record<string, string> | Headers;
|
20
37
|
body?: object;
|
@@ -26,7 +43,7 @@ type UseChatOptions = {
|
|
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 @@ 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 @@ 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
|
*/
|
@@ -107,6 +136,12 @@ 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
|
*/
|
@@ -159,7 +194,7 @@ type UseChatHelpers = {
|
|
159
194
|
/** Whether the API request is in progress */
|
160
195
|
isLoading: Writable<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 */
|
@@ -193,6 +228,6 @@ type UseCompletionHelpers = {
|
|
193
228
|
/** Whether the API request is in progress */
|
194
229
|
isLoading: Writable<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/svelte/dist/index.js
CHANGED
@@ -395,7 +395,7 @@ var SWR = class {
|
|
395
395
|
}
|
396
396
|
};
|
397
397
|
|
398
|
-
// ../../node_modules/.pnpm/sswr@1.10.0_svelte@
|
398
|
+
// ../../node_modules/.pnpm/sswr@1.10.0_svelte@4.0.0/node_modules/sswr/dist/sswr.mjs
|
399
399
|
var import_svelte = require("svelte");
|
400
400
|
function h() {
|
401
401
|
}
|
@@ -527,6 +527,7 @@ function useChat({
|
|
527
527
|
onResponse,
|
528
528
|
onFinish,
|
529
529
|
onError,
|
530
|
+
credentials,
|
530
531
|
headers,
|
531
532
|
body
|
532
533
|
} = {}) {
|
@@ -561,7 +562,8 @@ function useChat({
|
|
561
562
|
}))
|
562
563
|
}, body), options == null ? void 0 : options.body)),
|
563
564
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
564
|
-
signal: abortController.signal
|
565
|
+
signal: abortController.signal,
|
566
|
+
credentials
|
565
567
|
}).catch((err) => {
|
566
568
|
mutate(previousMessages);
|
567
569
|
throw err;
|
@@ -691,6 +693,7 @@ function useCompletion({
|
|
691
693
|
id,
|
692
694
|
initialCompletion = "",
|
693
695
|
initialInput = "",
|
696
|
+
credentials,
|
694
697
|
headers,
|
695
698
|
body,
|
696
699
|
onResponse,
|
@@ -724,7 +727,8 @@ function useCompletion({
|
|
724
727
|
prompt
|
725
728
|
}, body), options == null ? void 0 : options.body)),
|
726
729
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
727
|
-
signal: abortController.signal
|
730
|
+
signal: abortController.signal,
|
731
|
+
credentials
|
728
732
|
}).catch((err) => {
|
729
733
|
throw err;
|
730
734
|
});
|
package/svelte/dist/index.mjs
CHANGED
@@ -371,7 +371,7 @@ var SWR = class {
|
|
371
371
|
}
|
372
372
|
};
|
373
373
|
|
374
|
-
// ../../node_modules/.pnpm/sswr@1.10.0_svelte@
|
374
|
+
// ../../node_modules/.pnpm/sswr@1.10.0_svelte@4.0.0/node_modules/sswr/dist/sswr.mjs
|
375
375
|
import { beforeUpdate as _, onDestroy as D } from "svelte";
|
376
376
|
function h() {
|
377
377
|
}
|
@@ -503,6 +503,7 @@ function useChat({
|
|
503
503
|
onResponse,
|
504
504
|
onFinish,
|
505
505
|
onError,
|
506
|
+
credentials,
|
506
507
|
headers,
|
507
508
|
body
|
508
509
|
} = {}) {
|
@@ -537,7 +538,8 @@ function useChat({
|
|
537
538
|
}))
|
538
539
|
}, body), options == null ? void 0 : options.body)),
|
539
540
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
540
|
-
signal: abortController.signal
|
541
|
+
signal: abortController.signal,
|
542
|
+
credentials
|
541
543
|
}).catch((err) => {
|
542
544
|
mutate(previousMessages);
|
543
545
|
throw err;
|
@@ -667,6 +669,7 @@ function useCompletion({
|
|
667
669
|
id,
|
668
670
|
initialCompletion = "",
|
669
671
|
initialInput = "",
|
672
|
+
credentials,
|
670
673
|
headers,
|
671
674
|
body,
|
672
675
|
onResponse,
|
@@ -700,7 +703,8 @@ function useCompletion({
|
|
700
703
|
prompt
|
701
704
|
}, body), options == null ? void 0 : options.body)),
|
702
705
|
headers: __spreadValues(__spreadValues({}, headers), options == null ? void 0 : options.headers),
|
703
|
-
signal: abortController.signal
|
706
|
+
signal: abortController.signal,
|
707
|
+
credentials
|
704
708
|
}).catch((err) => {
|
705
709
|
throw err;
|
706
710
|
});
|
package/vue/dist/index.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
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.
|
@@ -7,14 +9,29 @@ 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
|
-
type CreateMessage = {
|
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
|
};
|
34
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionRequestMessageFunctionCall) => Promise<ChatRequest | void>;
|
18
35
|
type RequestOptions = {
|
19
36
|
headers?: Record<string, string> | Headers;
|
20
37
|
body?: object;
|
@@ -26,7 +43,7 @@ type UseChatOptions = {
|
|
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 @@ 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 @@ 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
|
*/
|
@@ -107,6 +136,12 @@ 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
|
*/
|
@@ -159,7 +194,7 @@ 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 */
|
@@ -193,6 +228,6 @@ 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
|
});
|