jason-ai-twin / Robot_Logic.py
jlind456's picture
Initial upload of Qwen AI twin weights
9507c73 verified
Raw History Blame Contribute Delete
2.03 kB
import os
import random
# Path to your shared directory
SHARE_DIR = os.path.expanduser("~/robot_share")
def get_context_from_memory(topic):
"""
Scans the robot_share directory for files matching the topic
and returns their combined content.
"""
relevant_content = []
if not os.path.exists(SHARE_DIR):
return "Memory bank not found."
for filename in os.listdir(SHARE_DIR):
if topic.lower() in filename.lower():
file_path = os.path.join(SHARE_DIR, filename)
try:
with open(file_path, "r", encoding="utf-8") as f:
relevant_content.append(f.read())
except Exception as e:
return f"Error reading memory: {str(e)}"
return "\n".join(relevant_content) if relevant_content else None
def process_robot_command(command):
"""
Decision-making logic for the robot based on user input.
"""
cmd = command.lower()
# 1. Handle Reminders/Health
if "remind" in cmd or "health" in cmd:
memory = get_context_from_memory("reminders")
return f"Checking my notes: {memory}" if memory else "I don't have any health reminders set."
# 2. Handle Comedy/Rodney Rude
elif "joke" in cmd or "funny" in cmd or "rodney" in cmd:
jokes = get_context_from_memory("rodney")
if jokes:
# Assumes jokes are separated by newlines
joke_list = [j.strip() for j in jokes.split('\n') if j.strip()]
return random.choice(joke_list)
return "I haven't loaded any jokes yet. Please add a 'Rodney_Rude.txt' file to the robot_share folder!"
# 3. Default fallback
else:
return "I'm listening. I've logged this command in my notes for later review."
# --- Testing the Logic ---
if __name__ == "__main__":
print("--- Robot Logic Test ---")
# Simulate a command
test_cmd = "Tell me a joke"
print(f"User command: {test_cmd}")
print(f"Robot response: {process_robot_command(test_cmd)}")