Skip to content

Commit

Permalink
Expose setInput for useAssistant hook (#886)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Leiter <max.leiter@vercel.com>
  • Loading branch information
mathu97 and MaxLeiter committed Dec 30, 2023
1 parent d9896ab commit 9b89c4d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-scissors-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

react/use-assistant: Expose setInput
7 changes: 6 additions & 1 deletion docs/pages/docs/api-reference/use-assistant.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FrameworkTabs, Tab } from '@/components/framework-tabs';

# experimental_useAssistant

## `experimental_useAssistant(options: UseAssistantOptions): UseAssistantHelpers` [#useassistant]
## `experimental_useAssistant(options: UseAssistantOptions): UseAssistantHelpers` [#experimental_useAssistant]

`useAssistant` is a utility designed to handle the UI state of interacting with an OpenAI-compatible assistant API.
This tool is useful when you need to integrate assistant capabilities into your application,
Expand Down Expand Up @@ -126,6 +126,11 @@ The `experimental_useAssistant` hook returns an object with several helper metho
['messages', 'Message[]', 'The current array of chat messages.'],
['threadId', 'string | undefined', 'The current thread ID.'],
['input', 'string', 'The current value of the input field.'],
[
'setInput',
'React.Dispatch<React.SetStateAction<string>>',
'Function to update the `input` value.',
],
[
'handleInputChange',
'(e: any) => void',
Expand Down
6 changes: 6 additions & 0 deletions packages/core/react/use-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export type UseAssistantHelpers = {
*/
input: string;

/**
* setState-powered method to update the input value.
*/
setInput: React.Dispatch<React.SetStateAction<string>>;

/**
* Handler for the `onChange` event of the input field to control the input's value.
*/
Expand Down Expand Up @@ -204,6 +209,7 @@ export function experimental_useAssistant({
messages,
threadId,
input,
setInput,
handleInputChange,
submitMessage,
status,
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {
"dependsOn": ["^build", "build"]
"dependsOn": ["^lint"]
},
"type-check": {
"dependsOn": ["^build", "build"]
Expand Down

0 comments on commit 9b89c4d

Please sign in to comment.