Support multiline chat input.
This commit is contained in:
parent
1a125a0139
commit
5b4aa746bf
|
|
@ -341,4 +341,5 @@ Exit Criteria:
|
|||
Remember:
|
||||
- Always begin by calling ask_human.
|
||||
- Always ask_human before finalizing or exiting.
|
||||
- Never announce that you are going to ask the human, just do it.
|
||||
"""
|
||||
|
|
@ -1,13 +1,23 @@
|
|||
"""Tool for asking questions to the human user."""
|
||||
|
||||
from langchain_core.tools import tool
|
||||
from prompt_toolkit import PromptSession
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
from rich.console import Console
|
||||
from rich.prompt import Prompt
|
||||
from rich.panel import Panel
|
||||
from rich.markdown import Markdown
|
||||
|
||||
console = Console()
|
||||
|
||||
def create_keybindings():
|
||||
"""Create custom key bindings for Ctrl+D submission."""
|
||||
bindings = KeyBindings()
|
||||
|
||||
@bindings.add('c-d')
|
||||
def submit(event):
|
||||
"""Trigger submission when Ctrl+D is pressed."""
|
||||
event.current_buffer.validate_and_handle()
|
||||
|
||||
return bindings
|
||||
|
||||
@tool
|
||||
def ask_human(question: str) -> str:
|
||||
"""Ask the human user a question with a nicely formatted display.
|
||||
|
|
@ -19,10 +29,22 @@ def ask_human(question: str) -> str:
|
|||
The user's response as a string
|
||||
"""
|
||||
console.print(Panel(
|
||||
Markdown(question),
|
||||
Markdown(question + "\n\n*Multiline input is supported; use Ctrl+D to submit. Use Ctrl+C to exit the program.*"),
|
||||
title="💭 Question for Human",
|
||||
border_style="yellow bold"
|
||||
))
|
||||
response = Prompt.ask("\nYour response")
|
||||
|
||||
session = PromptSession(
|
||||
multiline=True,
|
||||
key_bindings=create_keybindings(),
|
||||
prompt_continuation='. ',
|
||||
vi_mode=True # Enable Vi mode for more intuitive Ctrl+D behavior
|
||||
)
|
||||
|
||||
response = session.prompt(
|
||||
"> ",
|
||||
wrap_lines=True
|
||||
)
|
||||
|
||||
print()
|
||||
return response
|
||||
|
|
|
|||
Loading…
Reference in New Issue