Spaces:
Runtime error
Runtime error
File size: 1,469 Bytes
9799074 8f7ba95 c9cdc25 8f7ba95 c9cdc25 8f7ba95 c9cdc25 8f7ba95 c9cdc25 8f7ba95 c9cdc25 8f7ba95 c9cdc25 9799074 8f7ba95 c9cdc25 8f7ba95 8fe992b 8c01ffb 8f7ba95 2146e70 8c01ffb c9cdc25 2146e70 c9cdc25 2146e70 c9cdc25 2146e70 c9cdc25 2146e70 ae7a494 c9cdc25 2146e70 8c01ffb 8f7ba95 8c01ffb c9cdc25 2146e70 9b5b26a 8f7ba95 | 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 | from smolagents import CodeAgent, tool, ApiModel
# --- Tool ---
@tool
def suggest_activity(mood: str) -> str:
"""
Suggest an activity based on the user's mood.
Args:
mood (str): The detected mood of the user.
Returns:
str: A helpful activity suggestion.
"""
mood = mood.lower()
if mood == "bored":
return "Try a quick 5-minute coding challenge."
elif mood == "sad":
return "Go for a short walk or listen to music."
elif mood == "stressed":
return "Take a 5-minute break and breathe deeply."
elif mood == "happy":
return "Use this energy to work on something exciting!"
else:
return "Try something small and productive."
# --- Model ---
llm = ApiModel("meta-llama/Llama-3-8b-Instruct")
# --- Agent ---
agent = CodeAgent(
tools=[suggest_activity],
model=llm
)
# --- Mood detection ---
def detect_mood(text):
text = text.lower()
if "sad" in text:
return "sad"
elif "bored" in text:
return "bored"
elif "stress" in text or "tired" in text:
return "stressed"
elif "happy" in text:
return "happy"
else:
return "neutral"
# --- Response ---
def respond(message, personality):
mood = detect_mood(message)
prompt = f"""
Personality: {personality}
Mood: {mood}
User: {message}
Give a short helpful response and suggest one activity.
"""
return agent.run(prompt) |