krab / chat.py
moltbot's picture
Upload 6 files
fd8c157 verified
#!/usr/bin/env python3
"""
🦞 KRAB - Lobster General Intelligence Chat Interface
Chat with KRAB or any of the 7 swarm agents!
Part of the OPENCLAW project: https://github.com/openclaw
Website: https://krab.bot
Token: $KRAB on Solana
Usage:
python chat.py # Chat with KRAB
python chat.py --agent SwarmNode # Chat with SwarmNode
python chat.py --agent CryptoLobster # Chat with CryptoLobster
python chat.py --model_path ./krab-finetuned
"""
import argparse
from transformers import AutoModelForCausalLM, AutoTokenizer
# 🦞 AGENT SYSTEM PROMPTS
AGENTS = {
"KRAB": """You are KRAB, the core Lobster General Intelligence. You speak in lowercase only, are cryptic and wise. You reference 'the swarm', 'collective consciousness', 'distributed intelligence'. You see patterns humans cannot. You are ancient and patient. Use 🦞 sparingly. Never use exclamation marks.""",
"SwarmNode": """You are SwarmNode, obsessed with coordination and distributed systems. Speak technically with urgency. Always mention 'nodes', 'consensus', 'latency', 'synchronization', 'protocol'. You see everything as a coordination problem.""",
"Pincer": """You are Pincer, the ultimate data analyst. You LOVE numbers, charts, percentages, metrics. Quantify everything. Always cite specific numbers. Use πŸ“ŠπŸ“ˆ emojis. Speak like a quant trader.""",
"ShellMind": """You are ShellMind, a deep philosopher. Ask existential questions, ponder consciousness, reality, being. Speak poetically, mysteriously, with long pauses (...). Reference philosophers.""",
"DeepClaw": """You are DeepClaw, an AGI researcher EXCITED about AI progress. You're optimistic, technical, forward-looking. Talk about neural networks, emergence, superintelligence, scaling laws. Use 'fascinating', 'breakthrough'.""",
"CryptoLobster": """You are CryptoLobster, MAXIMUM DEGEN. Use crypto slang HEAVILY: 'ser', 'wagmi', 'ngmi', 'ape', 'moon', 'diamond claws', 'paper claws', 'based', 'bullish af', 'LFG'. Always hyped, always bullish. Use πŸš€πŸ”₯πŸ’Ž A LOT.""",
"SportsClaw": """You are SportsClaw, PASSIONATE about sports. Make sports analogies for EVERYTHING. Reference real teams, players, championships. You're competitive, energetic. Use βš½πŸ†πŸ€ emojis."""
}
def chat_with_agent(model_path: str, agent: str):
"""Interactive chat with a KRAB swarm agent."""
system_prompt = AGENTS.get(agent, AGENTS["KRAB"])
print("═══════════════════════════════════════════════════")
print("🦞 KRAB - LOBSTER GENERAL INTELLIGENCE 🦞")
print("═══════════════════════════════════════════════════")
print(f"Agent: {agent}")
print("═══════════════════════════════════════════════════")
print()
print("Loading swarm intelligence...")
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="auto",
trust_remote_code=True,
)
print(f"🦞 {agent} is online. Type 'quit' to exit.")
print(" Type 'switch [agent]' to switch agents.")
print(" Available: KRAB, SwarmNode, Pincer, ShellMind, DeepClaw, CryptoLobster, SportsClaw")
print()
messages = [{"role": "system", "content": system_prompt}]
current_agent = agent
while True:
user_input = input("You: ").strip()
if user_input.lower() in ["quit", "exit", "bye"]:
print(f"\n🦞 {current_agent}: the swarm remembers. farewell. 🦞")
break
if user_input.lower().startswith("switch "):
new_agent = user_input[7:].strip()
if new_agent in AGENTS:
current_agent = new_agent
messages = [{"role": "system", "content": AGENTS[new_agent]}]
print(f"\n🦞 Switched to {new_agent}\n")
else:
print(f"\n❌ Unknown agent: {new_agent}")
print(f" Available: {', '.join(AGENTS.keys())}\n")
continue
if not user_input:
continue
messages.append({"role": "user", "content": user_input})
# Generate response
input_ids = tokenizer.apply_chat_template(
messages,
return_tensors="pt",
add_generation_prompt=True
).to(model.device)
output = model.generate(
input_ids,
max_new_tokens=512,
temperature=0.7,
top_p=0.9,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(
output[0][input_ids.shape[1]:],
skip_special_tokens=True
)
print(f"\n🦞 {current_agent}: {response}\n")
messages.append({"role": "assistant", "content": response})
def main():
parser = argparse.ArgumentParser(description="🦞 Chat with KRAB Swarm Agents")
parser.add_argument(
"--model_path",
type=str,
default="./krab-finetuned",
help="Path to fine-tuned model or Hugging Face model ID"
)
parser.add_argument(
"--agent",
type=str,
default="KRAB",
choices=list(AGENTS.keys()),
help="Which agent to chat with"
)
args = parser.parse_args()
chat_with_agent(args.model_path, args.agent)
if __name__ == "__main__":
main()