mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
35 lines
983 B
Python
35 lines
983 B
Python
|
"""Tool for asking human input."""
|
||
|
|
||
|
from typing import Callable, Optional
|
||
|
|
||
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
||
|
from langchain_core.pydantic_v1 import Field
|
||
|
from langchain_core.tools import BaseTool
|
||
|
|
||
|
|
||
|
def _print_func(text: str) -> None:
|
||
|
print("\n")
|
||
|
print(text)
|
||
|
|
||
|
|
||
|
class HumanInputRun(BaseTool):
|
||
|
"""Tool that asks user for input."""
|
||
|
|
||
|
name: str = "human"
|
||
|
description: str = (
|
||
|
"You can ask a human for guidance when you think you "
|
||
|
"got stuck or you are not sure what to do next. "
|
||
|
"The input should be a question for the human."
|
||
|
)
|
||
|
prompt_func: Callable[[str], None] = Field(default_factory=lambda: _print_func)
|
||
|
input_func: Callable = Field(default_factory=lambda: input)
|
||
|
|
||
|
def _run(
|
||
|
self,
|
||
|
query: str,
|
||
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||
|
) -> str:
|
||
|
"""Use the Human input tool."""
|
||
|
self.prompt_func(query)
|
||
|
return self.input_func()
|