ai 2.1.19 → 2.1.20

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
@@ -268,7 +268,7 @@ type OpenAIStreamCallbacks = AIStreamCallbacks & {
268
268
  * // ... run your custom logic here
269
269
  * const result = await myFunction(functionCallPayload)
270
270
  *
271
- * // Ask for another completion
271
+ * // Ask for another completion, or return a string to send to the client as an assistant message.
272
272
  * return await openai.createChatCompletion({
273
273
  * model: 'gpt-3.5-turbo-0613',
274
274
  * stream: true,
@@ -280,7 +280,7 @@ type OpenAIStreamCallbacks = AIStreamCallbacks & {
280
280
  * })
281
281
  * ```
282
282
  */
283
- experimental_onFunctionCall?: (functionCallPayload: FunctionCallPayload, createFunctionCallMessages: (functionCallResult: JSONValue) => CreateMessage[]) => Promise<Response | undefined>;
283
+ experimental_onFunctionCall?: (functionCallPayload: FunctionCallPayload, createFunctionCallMessages: (functionCallResult: JSONValue) => CreateMessage[]) => Promise<Response | undefined | void | string>;
284
284
  };
285
285
  declare function OpenAIStream(res: Response, callbacks?: OpenAIStreamCallbacks): ReadableStream;
286
286
 
package/dist/index.js CHANGED
@@ -265,6 +265,9 @@ function createFunctionCallTransformer(callbacks) {
265
265
  if (!functionResponse) {
266
266
  controller.enqueue(textEncoder.encode(aggregatedResponse));
267
267
  return;
268
+ } else if (typeof functionResponse === "string") {
269
+ controller.enqueue(textEncoder.encode(functionResponse));
270
+ return;
268
271
  }
269
272
  const openAIStream = OpenAIStream(functionResponse, __spreadProps(__spreadValues({}, callbacks), {
270
273
  [__internal__OpenAIFnMessagesSymbol]: newFunctionCallMessages
package/dist/index.mjs CHANGED
@@ -232,6 +232,9 @@ function createFunctionCallTransformer(callbacks) {
232
232
  if (!functionResponse) {
233
233
  controller.enqueue(textEncoder.encode(aggregatedResponse));
234
234
  return;
235
+ } else if (typeof functionResponse === "string") {
236
+ controller.enqueue(textEncoder.encode(functionResponse));
237
+ return;
235
238
  }
236
239
  const openAIStream = OpenAIStream(functionResponse, __spreadProps(__spreadValues({}, callbacks), {
237
240
  [__internal__OpenAIFnMessagesSymbol]: newFunctionCallMessages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "2.1.19",
3
+ "version": "2.1.20",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",