Skip to content

Commit

Permalink
Expose setMessages for useAssistant hook (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
tchanxx authored Mar 18, 2024
1 parent 500b1fd commit f51e438
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/pages/docs/api-reference/use-assistant.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ The `experimental_useAssistant` hook returns an object with several helper metho
<OptionTable
options={[
['messages', 'Message[]', 'The current array of chat messages.'],
[
'setMessages',
'React.Dispatch<React.SetStateAction<Message>>',
'Function to update the `messages` array.',
],
['threadId', 'string | undefined', 'The current thread ID.'],
['input', 'string', 'The current value of the input field.'],
[
Expand Down
9 changes: 8 additions & 1 deletion packages/core/react/use-assistant.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable react-hooks/rules-of-hooks */

import { nanoid } from 'nanoid';
import { useState } from 'react';

import { readDataStream } from '../shared/read-data-stream';
import { Message } from '../shared/types';
import { nanoid } from 'nanoid';

export type AssistantStatus = 'in_progress' | 'awaiting_message';

Expand All @@ -13,6 +14,11 @@ export type UseAssistantHelpers = {
*/
messages: Message[];

/**
* setState-powered method to update the messages array.
*/
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;

/**
* The current thread ID.
*/
Expand Down Expand Up @@ -236,6 +242,7 @@ export function experimental_useAssistant({

return {
messages,
setMessages,
threadId,
input,
setInput,
Expand Down

0 comments on commit f51e438

Please sign in to comment.