ai 2.2.12 → 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 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 | ChatCompletionMessage.FunctionCall;
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<CompletionCreateParams.Function>;
32
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
64
+ functions?: Array<Function>;
65
+ function_call?: FunctionCall;
33
66
  };
34
- type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
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<CompletionCreateParams.Function>;
42
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
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.12",
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",
@@ -1,5 +1,16 @@
1
- import { ChatCompletionMessage } from 'openai/resources/chat';
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 | ChatCompletionMessage.FunctionCall;
32
+ function_call?: string | FunctionCall;
22
33
  };
23
34
 
24
35
  /**
@@ -1,5 +1,38 @@
1
- import { ChatCompletionMessage, CompletionCreateParams, CreateChatCompletionRequestMessage } from 'openai/resources/chat';
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 | ChatCompletionMessage.FunctionCall;
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<CompletionCreateParams.Function>;
30
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
62
+ functions?: Array<Function>;
63
+ function_call?: FunctionCall;
31
64
  };
32
- type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
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<CompletionCreateParams.Function>;
40
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
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 automattically reset input and append a user message */
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 automattically reset input and append a user message
274
+ * Form submission handler to automatically reset input and append a user message
242
275
  * @example
243
276
  * ```jsx
244
277
  * <form onSubmit={handleSubmit}>
@@ -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(functionCall).function_call;
200
+ const parsedFunctionCall = JSON.parse(
201
+ functionCall
202
+ ).function_call;
201
203
  functionCallMessage = {
202
204
  id: nanoid(),
203
205
  role: "assistant",
@@ -327,6 +329,7 @@ function useChat({
327
329
  async (chatRequest) => {
328
330
  try {
329
331
  mutateLoading(true);
332
+ setError(void 0);
330
333
  const abortController = new AbortController();
331
334
  abortControllerRef.current = abortController;
332
335
  while (true) {
@@ -550,6 +553,7 @@ function useCompletion({
550
553
  async (prompt, options) => {
551
554
  try {
552
555
  mutateLoading(true);
556
+ setError(void 0);
553
557
  const abortController2 = new AbortController();
554
558
  setAbortController(abortController2);
555
559
  mutate("", false);
@@ -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(functionCall).function_call;
164
+ const parsedFunctionCall = JSON.parse(
165
+ functionCall
166
+ ).function_call;
165
167
  functionCallMessage = {
166
168
  id: nanoid(),
167
169
  role: "assistant",
@@ -291,6 +293,7 @@ function useChat({
291
293
  async (chatRequest) => {
292
294
  try {
293
295
  mutateLoading(true);
296
+ setError(void 0);
294
297
  const abortController = new AbortController();
295
298
  abortControllerRef.current = abortController;
296
299
  while (true) {
@@ -514,6 +517,7 @@ function useCompletion({
514
517
  async (prompt, options) => {
515
518
  try {
516
519
  mutateLoading(true);
520
+ setError(void 0);
517
521
  const abortController2 = new AbortController();
518
522
  setAbortController(abortController2);
519
523
  mutate("", false);
@@ -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 | ChatCompletionMessage.FunctionCall;
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<CompletionCreateParams.Function>;
31
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
64
+ functions?: Array<Function>;
65
+ function_call?: FunctionCall;
32
66
  };
33
- type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
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 automattically reset input and append a user message */
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 automattically reset input and append a user message
258
+ * Form submission handler to automatically reset input and append a user message
225
259
  * @example
226
260
  * ```jsx
227
261
  * <form onSubmit={handleSubmit}>
@@ -115,6 +115,7 @@ function useChat({
115
115
  let abortController = null;
116
116
  async function triggerRequest(messagesSnapshot, options) {
117
117
  try {
118
+ setError(void 0);
118
119
  setIsLoading(true);
119
120
  abortController = new AbortController();
120
121
  const previousMessages = chatApiStore.get([key], {
@@ -307,6 +308,7 @@ function useCompletion({
307
308
  let abortController = null;
308
309
  async function triggerRequest(prompt, options) {
309
310
  try {
311
+ setError(void 0);
310
312
  setIsLoading(true);
311
313
  abortController = new AbortController();
312
314
  mutate("");
@@ -88,6 +88,7 @@ function useChat({
88
88
  let abortController = null;
89
89
  async function triggerRequest(messagesSnapshot, options) {
90
90
  try {
91
+ setError(void 0);
91
92
  setIsLoading(true);
92
93
  abortController = new AbortController();
93
94
  const previousMessages = chatApiStore.get([key], {
@@ -280,6 +281,7 @@ function useCompletion({
280
281
  let abortController = null;
281
282
  async function triggerRequest(prompt, options) {
282
283
  try {
284
+ setError(void 0);
283
285
  setIsLoading(true);
284
286
  abortController = new AbortController();
285
287
  mutate("");
@@ -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 | ChatCompletionMessage.FunctionCall;
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<CompletionCreateParams.Function>;
31
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
64
+ functions?: Array<Function>;
65
+ function_call?: FunctionCall;
32
66
  };
33
- type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
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<CompletionCreateParams.Function>;
41
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
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 automattically reset input and append a user message */
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 automattically reset input and append a user message
260
+ * Form submission handler to automatically reset input and append a user message
227
261
  * @example
228
262
  * ```jsx
229
263
  * <form onSubmit={handleSubmit}>
@@ -709,6 +709,7 @@ function useChat({
709
709
  const error = (0, import_store.writable)(void 0);
710
710
  async function triggerRequest(chatRequest) {
711
711
  try {
712
+ error.set(void 0);
712
713
  loading.set(true);
713
714
  abortController = new AbortController();
714
715
  while (true) {
@@ -868,6 +869,7 @@ function useCompletion({
868
869
  let abortController = null;
869
870
  async function triggerRequest(prompt, options) {
870
871
  try {
872
+ error.set(void 0);
871
873
  loading.set(true);
872
874
  abortController = new AbortController();
873
875
  mutate("");
@@ -682,6 +682,7 @@ function useChat({
682
682
  const error = writable(void 0);
683
683
  async function triggerRequest(chatRequest) {
684
684
  try {
685
+ error.set(void 0);
685
686
  loading.set(true);
686
687
  abortController = new AbortController();
687
688
  while (true) {
@@ -841,6 +842,7 @@ function useCompletion({
841
842
  let abortController = null;
842
843
  async function triggerRequest(prompt, options) {
843
844
  try {
845
+ error.set(void 0);
844
846
  loading.set(true);
845
847
  abortController = new AbortController();
846
848
  mutate("");
@@ -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 | ChatCompletionMessage.FunctionCall;
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<CompletionCreateParams.Function>;
31
- function_call?: CreateChatCompletionRequestMessage.FunctionCall;
64
+ functions?: Array<Function>;
65
+ function_call?: FunctionCall;
32
66
  };
33
- type FunctionCallHandler = (chatMessages: Message[], functionCall: ChatCompletionMessage.FunctionCall) => Promise<ChatRequest | void>;
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 automattically reset input and append a user message */
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>;
package/vue/dist/index.js CHANGED
@@ -123,6 +123,7 @@ function useChat({
123
123
  let abortController = null;
124
124
  async function triggerRequest(messagesSnapshot, options) {
125
125
  try {
126
+ error.value = void 0;
126
127
  mutateLoading(() => true);
127
128
  abortController = new AbortController();
128
129
  const previousMessages = messages.value;
@@ -302,6 +303,7 @@ function useCompletion({
302
303
  let abortController = null;
303
304
  async function triggerRequest(prompt, options) {
304
305
  try {
306
+ error.value = void 0;
305
307
  mutateLoading(() => true);
306
308
  abortController = new AbortController();
307
309
  mutate("");
@@ -86,6 +86,7 @@ function useChat({
86
86
  let abortController = null;
87
87
  async function triggerRequest(messagesSnapshot, options) {
88
88
  try {
89
+ error.value = void 0;
89
90
  mutateLoading(() => true);
90
91
  abortController = new AbortController();
91
92
  const previousMessages = messages.value;
@@ -265,6 +266,7 @@ function useCompletion({
265
266
  let abortController = null;
266
267
  async function triggerRequest(prompt, options) {
267
268
  try {
269
+ error.value = void 0;
268
270
  mutateLoading(() => true);
269
271
  abortController = new AbortController();
270
272
  mutate("");