Skip to content

Commit b01cf3b

Browse files
committed
feat add experimental_attachmentgenerator
1 parent 2d83886 commit b01cf3b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/react/src/use-chat.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
392392
api,
393393
extraMetadataRef,
394394
onResponse,
395+
onParts,
395396
onFinish,
396397
onError,
397398
setError,
@@ -420,11 +421,12 @@ By default, it's set to 1, which means that only a single LLM call is made.
420421
headers,
421422
body,
422423
experimental_attachments = message.experimental_attachments,
424+
experimental_attachmentGenerator,
423425
}: ChatRequestOptions = {},
424426
) => {
425-
const attachmentsForRequest = await prepareAttachmentsForRequest(
426-
experimental_attachments,
427-
);
427+
const attachmentsForRequest = experimental_attachmentGenerator
428+
? await experimental_attachmentGenerator()
429+
: await prepareAttachmentsForRequest(experimental_attachments);
428430

429431
const messages = messagesRef.current.concat({
430432
...message,
@@ -524,9 +526,9 @@ By default, it's set to 1, which means that only a single LLM call is made.
524526
};
525527
}
526528

527-
const attachmentsForRequest = await prepareAttachmentsForRequest(
528-
options.experimental_attachments,
529-
);
529+
const attachmentsForRequest = options?.experimental_attachmentGenerator
530+
? await options.experimental_attachmentGenerator()
531+
: await prepareAttachmentsForRequest(options.experimental_attachments);
530532

531533
const messages = messagesRef.current.concat({
532534
id: generateId(),

packages/ui-utils/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Additional data to be sent to the API endpoint.
269269
* Allow submitting an empty message. Defaults to `false`.
270270
*/
271271
allowEmptySubmit?: boolean;
272+
273+
experimental_attachmentGenerator?: () => Promise<Attachment[]> | Attachment[];
272274
};
273275

274276
export type UseChatOptions = {

0 commit comments

Comments
 (0)