Skip to content

ai/packages/core/react /use-assistant.ts: expose setThreadId as helper #1673

@tomfuller71

Description

@tomfuller71

Feature Description

Expose setThreadId as a UseAssistantHelper so that a new conversation thread can be started by executing setThreadId(undefined).

Use Case

Use case: an assistant providing feedback on a specific tuple of "question" and "student_answer". The UI provides user the ability to select the specific course, exam and question they want to get the assistant's feedback on. When selection is complete the UI should initiate a new chat with an initial prompt dynamically generated from the user's selections. Each new request for feedback should be a new chat where the bot has no memory of any previous conversations.

Without the ability to set the threadId to undefined the same chat thread will be used for the entire lifetime of the React component containing the useAssistant hook and even if messages are cleared the assistant still has memory of the previous conversation. A full page refresh is not ideal as memory of current UI state will be lost without some workarounds.

Additional context

As an alternative to exposing setThreadId add a more explicit helper. e.g.

  /**
   * Resets the chat thread.
   * Stops any existing chat threads, clears the chat `Messages` and `Input`.
   * Resets `threadId` so that new messages will run on a new thread.
  */
  resetThread: () => {
    stop()
    setMessages([])
    setInput('')
    setThreadId(undefined)
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/uianything UI related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions