forked from tisu19021997/langclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
56 lines (40 loc) · 1.67 KB
/
bot.py
File metadata and controls
56 lines (40 loc) · 1.67 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
52
53
54
55
56
"""
Custom langclaw bot with commands and tools.
Run with: .venv/bin/python bot.py
"""
from __future__ import annotations
import platform
import time
from langclaw import Langclaw
from langclaw.gateway.commands import CommandContext
app = Langclaw(
system_prompt=(
"You are a helpful assistant running on Miguel's Mac mini. "
"Keep answers concise. You have access to web search and Python tools."
),
)
# ─── Commands (instant, no LLM, no cost) ─────────────────────────
_start_time = time.time()
@app.command("status", description="Show bot health and uptime")
async def status_cmd(ctx: CommandContext) -> str:
uptime_s = int(time.time() - _start_time)
hours, remainder = divmod(uptime_s, 3600)
minutes, seconds = divmod(remainder, 60)
lines = [
"🟢 Bot Status",
f" Model: {app._config.agents.model if app._config else 'unknown'}",
f" Uptime: {hours}h {minutes}m {seconds}s",
f" Python: {platform.python_version()}",
f" Host: {platform.node()}",
]
return "\n".join(lines)
@app.command("ping", description="Check if bot is alive")
async def ping_cmd(ctx: CommandContext) -> str:
return "🏓 Pong!"
@app.command("model", description="Show current model info")
async def model_cmd(ctx: CommandContext) -> str:
model = app._config.agents.model if app._config else "unknown"
return f"🤖 Running: {model}"
# ─── Run ──────────────────────────────────────────────────────────
if __name__ == "__main__":
app.run()