-
-
Notifications
You must be signed in to change notification settings - Fork 770
Expand file tree
/
Copy pathslash_commands_example.py
More file actions
51 lines (40 loc) · 1.39 KB
/
slash_commands_example.py
File metadata and controls
51 lines (40 loc) · 1.39 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
50
51
"""
Slash Commands Example for PraisonAI CLI.
Demonstrates interactive slash commands like /help, /cost, /model.
Docs: https://docs.praison.ai/cli/slash-commands
"""
from praisonai.cli.features import SlashCommandHandler
from praisonai.cli.features.slash_commands import SlashCommand, CommandKind
# Create handler
handler = SlashCommandHandler()
# Execute commands
print("=== /help ===")
result = handler.execute("/help")
print(result.get("message", ""))
print("\n=== /cost ===")
result = handler.execute("/cost")
print(result.get("message", ""))
print("\n=== /model ===")
result = handler.execute("/model")
print(result.get("message", ""))
# Check if input is a command
print("\n=== Command Detection ===")
print(f"/help is command: {handler.is_command('/help')}")
print(f"hello is command: {handler.is_command('hello')}")
# Get completions for auto-complete
print("\n=== Completions for '/he' ===")
completions = handler.get_completions("/he")
print(completions)
# Register custom command
def my_custom_handler(args, context):
return {"type": "custom", "message": f"Custom command with args: {args}"}
custom_cmd = SlashCommand(
name="mycommand",
description="My custom command",
handler=my_custom_handler,
kind=CommandKind.ACTION,
aliases=["mc"]
)
handler.register(custom_cmd)
result = handler.execute("/mycommand arg1 arg2")
print(f"\n=== Custom Command ===\n{result.get('message', '')}")