-
-
Notifications
You must be signed in to change notification settings - Fork 781
Expand file tree
/
Copy pathinteractive_tui_example.py
More file actions
49 lines (39 loc) · 1.21 KB
/
interactive_tui_example.py
File metadata and controls
49 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Interactive TUI Example for PraisonAI CLI.
Rich terminal interface with completions and history.
Docs: https://docs.praison.ai/cli/interactive-tui
"""
from praisonai.cli.features import InteractiveTUIHandler
from praisonai.cli.features.interactive_tui import InteractiveConfig
# Custom configuration
config = InteractiveConfig(
prompt="ai> ",
multiline=True,
enable_completions=True,
show_status_bar=True
)
# Define callbacks
def on_input(text):
"""Handle regular input."""
return f"You said: {text}"
def on_command(cmd):
"""Handle slash commands."""
if cmd == "/exit":
return {"type": "exit"}
return {"type": "command", "message": f"Executed: {cmd}"}
# Initialize
handler = InteractiveTUIHandler()
session = handler.initialize(
config=config,
on_input=on_input,
on_command=on_command
)
# Add commands for completion
session.add_commands(["help", "exit", "cost", "model", "plan"])
# Add symbols from codebase
session.add_symbols(["MyClass", "my_function"])
print("Interactive TUI initialized!")
print("Commands available: /help, /exit, /cost, /model, /plan")
print("Run handler.run() to start interactive session")
# Uncomment to run interactive session:
# handler.run()