robosage / core_creator /intent_parser.py
mgbam's picture
Update core_creator/intent_parser.py
634a8f0 verified
raw
history blame
1.18 kB
# intent_parser.py - Extracts purpose and domain of the robotics app idea
import os
import google.generativeai as genai
# Use Gemini API Key from environment variable
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
if not GEMINI_API_KEY:
raise EnvironmentError("GEMINI_API_KEY not set in environment variables.")
genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel("gemini-pro")
# Categories the system understands
INTENT_CATEGORIES = [
"educational",
"assistive",
"entertainment",
"industrial",
"home automation",
"healthcare",
"retail",
"creative"
]
# Classify robot idea using Gemini
def classify_robot_idea(user_input: str) -> str:
prompt = f"""
Classify this user idea into one of the following categories:
{', '.join(INTENT_CATEGORIES)}.
Only return the category word. If none fits, return 'creative'.
Idea: {user_input}
Category:
"""
response = model.generate_content(prompt)
return response.text.strip().lower()
# Example
if __name__ == "__main__":
idea = "Build a robot that reminds elderly people to take medicine."
print("Predicted Intent:", classify_robot_idea(idea))