fix: UserInputTool prompts now display in Gradio interface#1954
Draft
wingding12 wants to merge 1 commit intohuggingface:mainfrom
Draft
fix: UserInputTool prompts now display in Gradio interface#1954wingding12 wants to merge 1 commit intohuggingface:mainfrom
wingding12 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Fixes huggingface#805 Previously, UserInputTool used Python's input() function directly, which only works in terminal contexts. When used with GradioUI, the prompts would appear in the terminal instead of the Gradio chat interface. Changes: - UserInputTool now accepts an optional `get_user_input` callback that can be used to customize how user input is collected - Default behavior unchanged (uses terminal input()) - GradioUI automatically configures UserInputTool instances to use a handler that displays questions in the chat interface - When the agent needs user input, it pauses and shows the question - The user's next message is treated as the answer Added GradioUserInputHandler class to manage the input request/response flow between the agent and the Gradio interface. Added tests for UserInputTool with custom input handlers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #805
Previously,
UserInputToolused Python'sinput()function directly, which only works in terminal contexts. When used withGradioUI, the prompts would appear in the terminal instead of the Gradio chat interface.Changes
UserInputToolnow accepts an optionalget_user_inputcallback parameter that can be used to customize how user input is collectedinput())GradioUIautomatically configuresUserInputToolinstances to use a handler that displays questions in the chat interfaceNew Classes
GradioUserInputHandler: Manages the input request/response flow between the agent and the Gradio interfaceUserInputRequiredException: Exception raised to pause agent execution when user input is neededExample Usage
Test Plan
UserInputToolwith custom input handlersGradioUItests pass