ai 2.2.13 → 2.2.14
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 +66 -23
- package/package.json +1 -3
- package/prompts/dist/index.d.ts +14 -3
- package/react/dist/index.d.ts +43 -10
- package/react/dist/index.js +3 -1
- package/react/dist/index.mjs +3 -1
- package/solid/dist/index.d.ts +41 -7
- package/svelte/dist/index.d.ts +43 -9
- package/vue/dist/index.d.ts +40 -6
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,40 @@
|
|
1
|
-
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
2
1
|
import { ServerResponse } from 'node:http';
|
3
|
-
import { Prediction } from 'replicate';
|
4
2
|
|
3
|
+
interface FunctionCall {
|
4
|
+
/**
|
5
|
+
* The arguments to call the function with, as generated by the model in JSON
|
6
|
+
* format. Note that the model does not always generate valid JSON, and may
|
7
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
8
|
+
* arguments in your code before calling your function.
|
9
|
+
*/
|
10
|
+
arguments?: string;
|
11
|
+
/**
|
12
|
+
* The name of the function to call.
|
13
|
+
*/
|
14
|
+
name?: string;
|
15
|
+
}
|
16
|
+
interface Function {
|
17
|
+
/**
|
18
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
19
|
+
* underscores and dashes, with a maximum length of 64.
|
20
|
+
*/
|
21
|
+
name: string;
|
22
|
+
/**
|
23
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
24
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
25
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
26
|
+
* documentation about the format.
|
27
|
+
*
|
28
|
+
* To describe a function that accepts no parameters, provide the value
|
29
|
+
* `{"type": "object", "properties": {}}`.
|
30
|
+
*/
|
31
|
+
parameters: Record<string, unknown>;
|
32
|
+
/**
|
33
|
+
* A description of what the function does, used by the model to choose when and
|
34
|
+
* how to call the function.
|
35
|
+
*/
|
36
|
+
description?: string;
|
37
|
+
}
|
5
38
|
/**
|
6
39
|
* Shared types between the API and UI packages.
|
7
40
|
*/
|
@@ -20,7 +53,7 @@ type Message = {
|
|
20
53
|
* contains the function call name and arguments. Otherwise, the field should
|
21
54
|
* not be set.
|
22
55
|
*/
|
23
|
-
function_call?: string |
|
56
|
+
function_call?: string | FunctionCall;
|
24
57
|
};
|
25
58
|
type CreateMessage = Omit<Message, 'id'> & {
|
26
59
|
id?: Message['id'];
|
@@ -28,18 +61,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
28
61
|
type ChatRequest = {
|
29
62
|
messages: Message[];
|
30
63
|
options?: RequestOptions;
|
31
|
-
functions?: Array<
|
32
|
-
function_call?:
|
64
|
+
functions?: Array<Function>;
|
65
|
+
function_call?: FunctionCall;
|
33
66
|
};
|
34
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
67
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
35
68
|
type RequestOptions = {
|
36
69
|
headers?: Record<string, string> | Headers;
|
37
70
|
body?: object;
|
38
71
|
};
|
39
72
|
type ChatRequestOptions = {
|
40
73
|
options?: RequestOptions;
|
41
|
-
functions?: Array<
|
42
|
-
function_call?:
|
74
|
+
functions?: Array<Function>;
|
75
|
+
function_call?: FunctionCall;
|
43
76
|
};
|
44
77
|
type UseChatOptions = {
|
45
78
|
/**
|
@@ -208,7 +241,7 @@ interface ChatCompletionChunk {
|
|
208
241
|
}
|
209
242
|
interface ChatCompletionChunkChoice {
|
210
243
|
delta: ChoiceDelta;
|
211
|
-
finish_reason: 'stop' | 'length' | 'function_call' | null;
|
244
|
+
finish_reason: 'stop' | 'length' | 'function_call' | 'content_filter' | null;
|
212
245
|
index: number;
|
213
246
|
}
|
214
247
|
interface ChoiceDelta {
|
@@ -226,19 +259,6 @@ interface ChoiceDelta {
|
|
226
259
|
*/
|
227
260
|
role?: 'system' | 'user' | 'assistant' | 'function';
|
228
261
|
}
|
229
|
-
interface FunctionCall {
|
230
|
-
/**
|
231
|
-
* The arguments to call the function with, as generated by the model in JSON
|
232
|
-
* format. Note that the model does not always generate valid JSON, and may
|
233
|
-
* hallucinate parameters not defined by your function schema. Validate the
|
234
|
-
* arguments in your code before calling your function.
|
235
|
-
*/
|
236
|
-
arguments?: string;
|
237
|
-
/**
|
238
|
-
* The name of the function to call.
|
239
|
-
*/
|
240
|
-
name?: string;
|
241
|
-
}
|
242
262
|
/**
|
243
263
|
* https://github.com/openai/openai-node/blob/3ec43ee790a2eb6a0ccdd5f25faa23251b0f9b8e/src/resources/completions.ts#L28C1-L64C1
|
244
264
|
* Completions API. Streamed and non-streamed responses are the same.
|
@@ -464,6 +484,29 @@ declare function LangChainStream(callbacks?: AIStreamCallbacksAndOptions): {
|
|
464
484
|
};
|
465
485
|
};
|
466
486
|
|
487
|
+
interface Prediction {
|
488
|
+
id: string;
|
489
|
+
status: 'starting' | 'processing' | 'succeeded' | 'failed' | 'canceled';
|
490
|
+
version: string;
|
491
|
+
input: object;
|
492
|
+
output?: any;
|
493
|
+
source: 'api' | 'web';
|
494
|
+
error?: any;
|
495
|
+
logs?: string;
|
496
|
+
metrics?: {
|
497
|
+
predict_time?: number;
|
498
|
+
};
|
499
|
+
webhook?: string;
|
500
|
+
webhook_events_filter?: ('start' | 'output' | 'logs' | 'completed')[];
|
501
|
+
created_at: string;
|
502
|
+
updated_at: string;
|
503
|
+
completed_at?: string;
|
504
|
+
urls: {
|
505
|
+
get: string;
|
506
|
+
cancel: string;
|
507
|
+
stream?: string;
|
508
|
+
};
|
509
|
+
}
|
467
510
|
/**
|
468
511
|
* Stream predictions from Replicate.
|
469
512
|
* Only certain models are supported and you must pass `stream: true` to
|
@@ -528,4 +571,4 @@ declare const getStreamStringTypeAndValue: (line: string) => {
|
|
528
571
|
*/
|
529
572
|
declare const COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
530
573
|
|
531
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AnthropicStream, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CreateMessage, FunctionCallHandler, FunctionCallPayload, HuggingFaceStream, JSONValue, LangChainStream, Message, OpenAIStream, OpenAIStreamCallbacks, ReplicateStream, RequestOptions, StreamString, StreamStringPrefixes, StreamingTextResponse, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_StreamData, getStreamString, getStreamStringTypeAndValue, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
|
574
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AnthropicStream, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CreateMessage, FunctionCall, FunctionCallHandler, FunctionCallPayload, HuggingFaceStream, JSONValue, LangChainStream, Message, OpenAIStream, OpenAIStreamCallbacks, ReplicateStream, RequestOptions, StreamString, StreamStringPrefixes, StreamingTextResponse, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_StreamData, getStreamString, getStreamStringTypeAndValue, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.14",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -61,7 +61,6 @@
|
|
61
61
|
"dependencies": {
|
62
62
|
"eventsource-parser": "1.0.0",
|
63
63
|
"nanoid": "3.3.6",
|
64
|
-
"openai": "4.2.0",
|
65
64
|
"solid-swr-store": "0.10.7",
|
66
65
|
"sswr": "2.0.0",
|
67
66
|
"swr": "2.2.0",
|
@@ -76,7 +75,6 @@
|
|
76
75
|
"@types/react-dom": "^18.2.0",
|
77
76
|
"eslint": "^7.32.0",
|
78
77
|
"jest": "29.2.1",
|
79
|
-
"replicate": "^0.16.0",
|
80
78
|
"ts-jest": "29.0.3",
|
81
79
|
"tsup": "^6.7.0",
|
82
80
|
"typescript": "5.1.3",
|
package/prompts/dist/index.d.ts
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
interface FunctionCall {
|
2
|
+
/**
|
3
|
+
* The arguments to call the function with, as generated by the model in JSON
|
4
|
+
* format. Note that the model does not always generate valid JSON, and may
|
5
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
6
|
+
* arguments in your code before calling your function.
|
7
|
+
*/
|
8
|
+
arguments?: string;
|
9
|
+
/**
|
10
|
+
* The name of the function to call.
|
11
|
+
*/
|
12
|
+
name?: string;
|
13
|
+
}
|
3
14
|
/**
|
4
15
|
* Shared types between the API and UI packages.
|
5
16
|
*/
|
@@ -18,7 +29,7 @@ type Message = {
|
|
18
29
|
* contains the function call name and arguments. Otherwise, the field should
|
19
30
|
* not be set.
|
20
31
|
*/
|
21
|
-
function_call?: string |
|
32
|
+
function_call?: string | FunctionCall;
|
22
33
|
};
|
23
34
|
|
24
35
|
/**
|
package/react/dist/index.d.ts
CHANGED
@@ -1,5 +1,38 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
interface FunctionCall {
|
2
|
+
/**
|
3
|
+
* The arguments to call the function with, as generated by the model in JSON
|
4
|
+
* format. Note that the model does not always generate valid JSON, and may
|
5
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
6
|
+
* arguments in your code before calling your function.
|
7
|
+
*/
|
8
|
+
arguments?: string;
|
9
|
+
/**
|
10
|
+
* The name of the function to call.
|
11
|
+
*/
|
12
|
+
name?: string;
|
13
|
+
}
|
14
|
+
interface Function {
|
15
|
+
/**
|
16
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
17
|
+
* underscores and dashes, with a maximum length of 64.
|
18
|
+
*/
|
19
|
+
name: string;
|
20
|
+
/**
|
21
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
22
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
23
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
24
|
+
* documentation about the format.
|
25
|
+
*
|
26
|
+
* To describe a function that accepts no parameters, provide the value
|
27
|
+
* `{"type": "object", "properties": {}}`.
|
28
|
+
*/
|
29
|
+
parameters: Record<string, unknown>;
|
30
|
+
/**
|
31
|
+
* A description of what the function does, used by the model to choose when and
|
32
|
+
* how to call the function.
|
33
|
+
*/
|
34
|
+
description?: string;
|
35
|
+
}
|
3
36
|
/**
|
4
37
|
* Shared types between the API and UI packages.
|
5
38
|
*/
|
@@ -18,7 +51,7 @@ type Message = {
|
|
18
51
|
* contains the function call name and arguments. Otherwise, the field should
|
19
52
|
* not be set.
|
20
53
|
*/
|
21
|
-
function_call?: string |
|
54
|
+
function_call?: string | FunctionCall;
|
22
55
|
};
|
23
56
|
type CreateMessage = Omit<Message, 'id'> & {
|
24
57
|
id?: Message['id'];
|
@@ -26,18 +59,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
26
59
|
type ChatRequest = {
|
27
60
|
messages: Message[];
|
28
61
|
options?: RequestOptions;
|
29
|
-
functions?: Array<
|
30
|
-
function_call?:
|
62
|
+
functions?: Array<Function>;
|
63
|
+
function_call?: FunctionCall;
|
31
64
|
};
|
32
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
65
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
33
66
|
type RequestOptions = {
|
34
67
|
headers?: Record<string, string> | Headers;
|
35
68
|
body?: object;
|
36
69
|
};
|
37
70
|
type ChatRequestOptions = {
|
38
71
|
options?: RequestOptions;
|
39
|
-
functions?: Array<
|
40
|
-
function_call?:
|
72
|
+
functions?: Array<Function>;
|
73
|
+
function_call?: FunctionCall;
|
41
74
|
};
|
42
75
|
type UseChatOptions = {
|
43
76
|
/**
|
@@ -198,7 +231,7 @@ type UseChatHelpers = {
|
|
198
231
|
setInput: React.Dispatch<React.SetStateAction<string>>;
|
199
232
|
/** An input/textarea-ready onChange handler to control the value of the input */
|
200
233
|
handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
201
|
-
/** Form submission handler to
|
234
|
+
/** Form submission handler to automatically reset input and append a user message */
|
202
235
|
handleSubmit: (e: React.FormEvent<HTMLFormElement>, chatRequestOptions?: ChatRequestOptions) => void;
|
203
236
|
metadata?: Object;
|
204
237
|
/** Whether the API request is in progress */
|
@@ -238,7 +271,7 @@ type UseCompletionHelpers = {
|
|
238
271
|
*/
|
239
272
|
handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
240
273
|
/**
|
241
|
-
* Form submission handler to
|
274
|
+
* Form submission handler to automatically reset input and append a user message
|
242
275
|
* @example
|
243
276
|
* ```jsx
|
244
277
|
* <form onSubmit={handleSubmit}>
|
package/react/dist/index.js
CHANGED
@@ -197,7 +197,9 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
197
197
|
prefixMap["function_call"] = value2;
|
198
198
|
let functionCall = prefixMap["function_call"];
|
199
199
|
if (functionCall && typeof functionCall === "string") {
|
200
|
-
const parsedFunctionCall = JSON.parse(
|
200
|
+
const parsedFunctionCall = JSON.parse(
|
201
|
+
functionCall
|
202
|
+
).function_call;
|
201
203
|
functionCallMessage = {
|
202
204
|
id: nanoid(),
|
203
205
|
role: "assistant",
|
package/react/dist/index.mjs
CHANGED
@@ -161,7 +161,9 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
161
161
|
prefixMap["function_call"] = value2;
|
162
162
|
let functionCall = prefixMap["function_call"];
|
163
163
|
if (functionCall && typeof functionCall === "string") {
|
164
|
-
const parsedFunctionCall = JSON.parse(
|
164
|
+
const parsedFunctionCall = JSON.parse(
|
165
|
+
functionCall
|
166
|
+
).function_call;
|
165
167
|
functionCallMessage = {
|
166
168
|
id: nanoid(),
|
167
169
|
role: "assistant",
|
package/solid/dist/index.d.ts
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
import { Resource, Accessor, Setter } from 'solid-js';
|
2
|
-
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
3
2
|
|
3
|
+
interface FunctionCall {
|
4
|
+
/**
|
5
|
+
* The arguments to call the function with, as generated by the model in JSON
|
6
|
+
* format. Note that the model does not always generate valid JSON, and may
|
7
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
8
|
+
* arguments in your code before calling your function.
|
9
|
+
*/
|
10
|
+
arguments?: string;
|
11
|
+
/**
|
12
|
+
* The name of the function to call.
|
13
|
+
*/
|
14
|
+
name?: string;
|
15
|
+
}
|
16
|
+
interface Function {
|
17
|
+
/**
|
18
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
19
|
+
* underscores and dashes, with a maximum length of 64.
|
20
|
+
*/
|
21
|
+
name: string;
|
22
|
+
/**
|
23
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
24
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
25
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
26
|
+
* documentation about the format.
|
27
|
+
*
|
28
|
+
* To describe a function that accepts no parameters, provide the value
|
29
|
+
* `{"type": "object", "properties": {}}`.
|
30
|
+
*/
|
31
|
+
parameters: Record<string, unknown>;
|
32
|
+
/**
|
33
|
+
* A description of what the function does, used by the model to choose when and
|
34
|
+
* how to call the function.
|
35
|
+
*/
|
36
|
+
description?: string;
|
37
|
+
}
|
4
38
|
/**
|
5
39
|
* Shared types between the API and UI packages.
|
6
40
|
*/
|
@@ -19,7 +53,7 @@ type Message = {
|
|
19
53
|
* contains the function call name and arguments. Otherwise, the field should
|
20
54
|
* not be set.
|
21
55
|
*/
|
22
|
-
function_call?: string |
|
56
|
+
function_call?: string | FunctionCall;
|
23
57
|
};
|
24
58
|
type CreateMessage = Omit<Message, 'id'> & {
|
25
59
|
id?: Message['id'];
|
@@ -27,10 +61,10 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
27
61
|
type ChatRequest = {
|
28
62
|
messages: Message[];
|
29
63
|
options?: RequestOptions;
|
30
|
-
functions?: Array<
|
31
|
-
function_call?:
|
64
|
+
functions?: Array<Function>;
|
65
|
+
function_call?: FunctionCall;
|
32
66
|
};
|
33
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
67
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
34
68
|
type RequestOptions = {
|
35
69
|
headers?: Record<string, string> | Headers;
|
36
70
|
body?: object;
|
@@ -192,7 +226,7 @@ type UseChatHelpers = {
|
|
192
226
|
input: Accessor<string>;
|
193
227
|
/** Signal setter to update the input value */
|
194
228
|
setInput: Setter<string>;
|
195
|
-
/** Form submission handler to
|
229
|
+
/** Form submission handler to automatically reset input and append a user message */
|
196
230
|
handleSubmit: (e: any) => void;
|
197
231
|
/** Whether the API request is in progress */
|
198
232
|
isLoading: Accessor<boolean>;
|
@@ -221,7 +255,7 @@ type UseCompletionHelpers = {
|
|
221
255
|
/** Signal Setter to update the input value */
|
222
256
|
setInput: Setter<string>;
|
223
257
|
/**
|
224
|
-
* Form submission handler to
|
258
|
+
* Form submission handler to automatically reset input and append a user message
|
225
259
|
* @example
|
226
260
|
* ```jsx
|
227
261
|
* <form onSubmit={handleSubmit}>
|
package/svelte/dist/index.d.ts
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
import { Readable, Writable } from 'svelte/store';
|
2
|
-
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
3
2
|
|
3
|
+
interface FunctionCall {
|
4
|
+
/**
|
5
|
+
* The arguments to call the function with, as generated by the model in JSON
|
6
|
+
* format. Note that the model does not always generate valid JSON, and may
|
7
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
8
|
+
* arguments in your code before calling your function.
|
9
|
+
*/
|
10
|
+
arguments?: string;
|
11
|
+
/**
|
12
|
+
* The name of the function to call.
|
13
|
+
*/
|
14
|
+
name?: string;
|
15
|
+
}
|
16
|
+
interface Function {
|
17
|
+
/**
|
18
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
19
|
+
* underscores and dashes, with a maximum length of 64.
|
20
|
+
*/
|
21
|
+
name: string;
|
22
|
+
/**
|
23
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
24
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
25
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
26
|
+
* documentation about the format.
|
27
|
+
*
|
28
|
+
* To describe a function that accepts no parameters, provide the value
|
29
|
+
* `{"type": "object", "properties": {}}`.
|
30
|
+
*/
|
31
|
+
parameters: Record<string, unknown>;
|
32
|
+
/**
|
33
|
+
* A description of what the function does, used by the model to choose when and
|
34
|
+
* how to call the function.
|
35
|
+
*/
|
36
|
+
description?: string;
|
37
|
+
}
|
4
38
|
/**
|
5
39
|
* Shared types between the API and UI packages.
|
6
40
|
*/
|
@@ -19,7 +53,7 @@ type Message = {
|
|
19
53
|
* contains the function call name and arguments. Otherwise, the field should
|
20
54
|
* not be set.
|
21
55
|
*/
|
22
|
-
function_call?: string |
|
56
|
+
function_call?: string | FunctionCall;
|
23
57
|
};
|
24
58
|
type CreateMessage = Omit<Message, 'id'> & {
|
25
59
|
id?: Message['id'];
|
@@ -27,18 +61,18 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
27
61
|
type ChatRequest = {
|
28
62
|
messages: Message[];
|
29
63
|
options?: RequestOptions;
|
30
|
-
functions?: Array<
|
31
|
-
function_call?:
|
64
|
+
functions?: Array<Function>;
|
65
|
+
function_call?: FunctionCall;
|
32
66
|
};
|
33
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
67
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
34
68
|
type RequestOptions = {
|
35
69
|
headers?: Record<string, string> | Headers;
|
36
70
|
body?: object;
|
37
71
|
};
|
38
72
|
type ChatRequestOptions = {
|
39
73
|
options?: RequestOptions;
|
40
|
-
functions?: Array<
|
41
|
-
function_call?:
|
74
|
+
functions?: Array<Function>;
|
75
|
+
function_call?: FunctionCall;
|
42
76
|
};
|
43
77
|
type UseChatOptions = {
|
44
78
|
/**
|
@@ -195,7 +229,7 @@ type UseChatHelpers = {
|
|
195
229
|
setMessages: (messages: Message[]) => void;
|
196
230
|
/** The current value of the input */
|
197
231
|
input: Writable<string>;
|
198
|
-
/** Form submission handler to
|
232
|
+
/** Form submission handler to automatically reset input and append a user message */
|
199
233
|
handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
|
200
234
|
metadata?: Object;
|
201
235
|
/** Whether the API request is in progress */
|
@@ -223,7 +257,7 @@ type UseCompletionHelpers = {
|
|
223
257
|
/** The current value of the input */
|
224
258
|
input: Writable<string>;
|
225
259
|
/**
|
226
|
-
* Form submission handler to
|
260
|
+
* Form submission handler to automatically reset input and append a user message
|
227
261
|
* @example
|
228
262
|
* ```jsx
|
229
263
|
* <form onSubmit={handleSubmit}>
|
package/vue/dist/index.d.ts
CHANGED
@@ -1,6 +1,40 @@
|
|
1
1
|
import { Ref } from 'vue';
|
2
|
-
import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
|
3
2
|
|
3
|
+
interface FunctionCall {
|
4
|
+
/**
|
5
|
+
* The arguments to call the function with, as generated by the model in JSON
|
6
|
+
* format. Note that the model does not always generate valid JSON, and may
|
7
|
+
* hallucinate parameters not defined by your function schema. Validate the
|
8
|
+
* arguments in your code before calling your function.
|
9
|
+
*/
|
10
|
+
arguments?: string;
|
11
|
+
/**
|
12
|
+
* The name of the function to call.
|
13
|
+
*/
|
14
|
+
name?: string;
|
15
|
+
}
|
16
|
+
interface Function {
|
17
|
+
/**
|
18
|
+
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
|
19
|
+
* underscores and dashes, with a maximum length of 64.
|
20
|
+
*/
|
21
|
+
name: string;
|
22
|
+
/**
|
23
|
+
* The parameters the functions accepts, described as a JSON Schema object. See the
|
24
|
+
* [guide](/docs/guides/gpt/function-calling) for examples, and the
|
25
|
+
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
|
26
|
+
* documentation about the format.
|
27
|
+
*
|
28
|
+
* To describe a function that accepts no parameters, provide the value
|
29
|
+
* `{"type": "object", "properties": {}}`.
|
30
|
+
*/
|
31
|
+
parameters: Record<string, unknown>;
|
32
|
+
/**
|
33
|
+
* A description of what the function does, used by the model to choose when and
|
34
|
+
* how to call the function.
|
35
|
+
*/
|
36
|
+
description?: string;
|
37
|
+
}
|
4
38
|
/**
|
5
39
|
* Shared types between the API and UI packages.
|
6
40
|
*/
|
@@ -19,7 +53,7 @@ type Message = {
|
|
19
53
|
* contains the function call name and arguments. Otherwise, the field should
|
20
54
|
* not be set.
|
21
55
|
*/
|
22
|
-
function_call?: string |
|
56
|
+
function_call?: string | FunctionCall;
|
23
57
|
};
|
24
58
|
type CreateMessage = Omit<Message, 'id'> & {
|
25
59
|
id?: Message['id'];
|
@@ -27,10 +61,10 @@ type CreateMessage = Omit<Message, 'id'> & {
|
|
27
61
|
type ChatRequest = {
|
28
62
|
messages: Message[];
|
29
63
|
options?: RequestOptions;
|
30
|
-
functions?: Array<
|
31
|
-
function_call?:
|
64
|
+
functions?: Array<Function>;
|
65
|
+
function_call?: FunctionCall;
|
32
66
|
};
|
33
|
-
type FunctionCallHandler = (chatMessages: Message[], functionCall:
|
67
|
+
type FunctionCallHandler = (chatMessages: Message[], functionCall: FunctionCall) => Promise<ChatRequest | void>;
|
34
68
|
type RequestOptions = {
|
35
69
|
headers?: Record<string, string> | Headers;
|
36
70
|
body?: object;
|
@@ -188,7 +222,7 @@ type UseChatHelpers = {
|
|
188
222
|
setMessages: (messages: Message[]) => void;
|
189
223
|
/** The current value of the input */
|
190
224
|
input: Ref<string>;
|
191
|
-
/** Form submission handler to
|
225
|
+
/** Form submission handler to automatically reset input and append a user message */
|
192
226
|
handleSubmit: (e: any) => void;
|
193
227
|
/** Whether the API request is in progress */
|
194
228
|
isLoading: Ref<boolean | undefined>;
|