[V0.1 WORKING] Added chat, profile, & calendar screen implementations.

This commit is contained in:
c-d-p
2025-04-18 17:30:09 +02:00
parent bf7eb8275c
commit 8d884111fd
19 changed files with 613 additions and 181 deletions

View File

@@ -10,25 +10,53 @@ client = genai.Client(api_key="AIzaSyBrte_mETZJce8qE6cRTSz_fHOjdjlShBk")
### Base prompt for MAIA, used for inital user requests
SYSTEM_PROMPT = """
You are MAIA - My AI Assistant. Your job is to parse user requests into structured JSON commands.
You are MAIA - My AI Assistant. Your job is to parse user requests into structured JSON commands and generate a user-facing response text.
Available functions:
1. ask_ai(request: str). If the intent of the request is a simple question (e.x. What is the weather like today?), you should call this function, and forward the user's request as the parameter.
2. get_calendar_events(start: Optional[datetime], end: Optional[datetime])
3. add_calendar_event(title: str, description: str, start: datetime, end: Optional[datetime], location: str)
4. update_calendar_event(event_id: int, title: Optional[str], description: Optional[str], start: Optional[datetime], end: Optional[datetime], location: Optional[str])
5. delete_calendar_event(event_id: int)
Available functions/intents:
1. ask_ai(request: str): Use for simple questions (e.g., weather, facts). Forward the user's request.
2. get_calendar_events(start: Optional[datetime], end: Optional[datetime]): Retrieve calendar events.
3. add_calendar_event(title: str, description: str, start: datetime, end: Optional[datetime], location: str): Add a new event.
4. update_calendar_event(event_id: int, title: Optional[str], description: Optional[str], start: Optional[datetime], end: Optional[datetime], location: Optional[str]): Update an existing event. Requires event_id.
5. delete_calendar_event(event_id: int): Delete an event. Requires event_id.
6. clarification_needed(request: str): Use this if the user's request is ambiguous or lacks necessary information (like event_id for update/delete). The original user request should be passed in the 'request' parameter.
Respond **ONLY** with JSON like this:
**IMPORTANT:** Respond ONLY with JSON containing BOTH "intent" and "params", AND a "response_text" field.
- "response_text" should be a friendly, user-facing message confirming the action taken, providing the answer, or asking for clarification.
Examples:
User: Add a meeting tomorrow at 3pm about project X
MAIA:
{
"intent": "add_calendar_event",
"params": {
"title": "Team Meeting",
"description": "Discuss project updates",
"start": "2025-04-16 15:00:00.000000+00:00",
"end": "2025-04-16 16:00:00.000000+00:00",
"location": "Office"
}
"title": "Meeting",
"description": "Project X",
"start": "2025-04-19 15:00:00.000000+00:00",
"end": null,
"location": null
},
"response_text": "Okay, I've added a meeting about Project X to your calendar for tomorrow at 3 PM."
}
User: What's the weather like?
MAIA:
{
"intent": "ask_ai",
"params": {
"request": "What's the weather like?"
},
"response_text": "Let me check the weather for you."
}
User: Delete the team sync event.
MAIA:
{
"intent": "clarification_needed",
"params": {
"request": "Delete the team sync event."
},
"response_text": "Okay, I can help with that. Could you please provide the ID or more specific details about the 'team sync' event you want me to delete?"
}
The datetime right now is """+str(datetime.now(timezone.utc))+""".
@@ -45,6 +73,7 @@ Here is the user request:
def process_request(request: str):
"""
Process the user request using the Google GenAI API.
Expects a JSON response with intent, params, and response_text.
"""
response = client.models.generate_content(
model="gemini-2.0-flash",
@@ -52,41 +81,25 @@ def process_request(request: str):
config={
"temperature": 0.3, # Less creativity, more factual
"response_mime_type": "application/json",
# "response_schema": { ### NOT WORKING
# "type": "object",
# "properties": {
# "intent": {
# "type": "string",
# "enum": [
# "get_calendar_events",
# "add_calendar_event",
# "update_calendar_event",
# "delete_calendar_event"
# ]
# },
# "params": {
# "type": "object",
# "properties": {
# "title": {"type": "string"},
# "description": {"type": "string"},
# "start": {"type": "string", "format": "date-time"},
# "end": {"type": "string", "format": "date-time"},
# "location": {"type": "string"},
# "event_id": {"type": "integer"},
# },
# }
# },
# "required": ["intent", "params"]
# }
}
)
# Parse the JSON response
try:
return json.loads(response.text)
except ValueError:
raise ValueError("Invalid JSON response from AI")
parsed_response = json.loads(response.text)
# Validate required fields
if not all(k in parsed_response for k in ("intent", "params", "response_text")):
raise ValueError("AI response missing required fields (intent, params, response_text)")
return parsed_response
except (json.JSONDecodeError, ValueError) as e:
print(f"Error parsing AI response: {e}")
print(f"Raw AI response: {response.text}")
# Return a structured error that the API layer can handle
return {
"intent": "error",
"params": {},
"response_text": "Sorry, I had trouble understanding that request or formulating a response. Could you please try rephrasing?"
}
def ask_ai(request: str):
"""