File size: 5,815 Bytes
fd8c157 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
#!/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()
|