Update core_creator/intent_parser.py
Browse files- core_creator/intent_parser.py +17 -14
core_creator/intent_parser.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
| 1 |
# intent_parser.py - Extracts purpose and domain of the robotics app idea
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Categories the system understands
|
| 6 |
INTENT_CATEGORIES = [
|
|
@@ -14,9 +23,10 @@ INTENT_CATEGORIES = [
|
|
| 14 |
"creative"
|
| 15 |
]
|
| 16 |
|
| 17 |
-
#
|
|
|
|
| 18 |
def classify_robot_idea(user_input: str) -> str:
|
| 19 |
-
|
| 20 |
Classify this user idea into one of the following categories:
|
| 21 |
{', '.join(INTENT_CATEGORIES)}.
|
| 22 |
Only return the category word. If none fits, return 'creative'.
|
|
@@ -25,17 +35,10 @@ def classify_robot_idea(user_input: str) -> str:
|
|
| 25 |
Category:
|
| 26 |
"""
|
| 27 |
|
| 28 |
-
response =
|
| 29 |
-
|
| 30 |
-
messages=[
|
| 31 |
-
{"role": "system", "content": "You are a classification AI for robotics ideas."},
|
| 32 |
-
{"role": "user", "content": system_prompt},
|
| 33 |
-
],
|
| 34 |
-
temperature=0
|
| 35 |
-
)
|
| 36 |
-
return response.choices[0].message.content.strip().lower()
|
| 37 |
|
| 38 |
# Example
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
|
| 41 |
-
print("Predicted Intent:", classify_robot_idea(
|
|
|
|
| 1 |
# intent_parser.py - Extracts purpose and domain of the robotics app idea
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import google.generativeai as genai
|
| 5 |
+
|
| 6 |
+
# Use Gemini API Key from environment variable
|
| 7 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 8 |
+
if not GEMINI_API_KEY:
|
| 9 |
+
raise EnvironmentError("GEMINI_API_KEY not set in environment variables.")
|
| 10 |
+
|
| 11 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
| 12 |
+
model = genai.GenerativeModel("gemini-pro")
|
| 13 |
|
| 14 |
# Categories the system understands
|
| 15 |
INTENT_CATEGORIES = [
|
|
|
|
| 23 |
"creative"
|
| 24 |
]
|
| 25 |
|
| 26 |
+
# Classify robot idea using Gemini
|
| 27 |
+
|
| 28 |
def classify_robot_idea(user_input: str) -> str:
|
| 29 |
+
prompt = f"""
|
| 30 |
Classify this user idea into one of the following categories:
|
| 31 |
{', '.join(INTENT_CATEGORIES)}.
|
| 32 |
Only return the category word. If none fits, return 'creative'.
|
|
|
|
| 35 |
Category:
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
response = model.generate_content(prompt)
|
| 39 |
+
return response.text.strip().lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Example
|
| 42 |
if __name__ == "__main__":
|
| 43 |
+
idea = "Build a robot that reminds elderly people to take medicine."
|
| 44 |
+
print("Predicted Intent:", classify_robot_idea(idea))
|