Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Updated melli.py with task1,2 and 3
  • Loading branch information
Prashu2020 authored Aug 16, 2023
1 parent 444d44d commit d6fa7ad
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions melli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@app.get("/task1/greet/{name}", tags=["Task 1"], summary="πŸ‘‹πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡Έ")
async def task1_greet(name: str, language: str = "en") -> str:
async def task1_greet(name: str, language: str = "de") -> str:
"""Greet somebody in German, English or Spanish!"""
supported_languages = ["de", "en", "es"]

Expand Down Expand Up @@ -69,29 +69,38 @@ class ActionResponse(BaseModel):


# Action handlers
def handle_call_action(username: str):
return f"πŸ“ž Sure, let me help you connect with your loved ones, {username}!"
def handle_call_action(username: str, action:str):
if action.split()[-1][:-1] not in friends[username]:
return "{username}, I can't find this person in your contacts."
return f"πŸ€™ Calling {username} ..."

def handle_reminder_action(username: str):
return f"πŸ”” Absolutely, I'll remind you to have some tea with your friend, {username}!"
def handle_reminder_action(username: str, action:str):
return f"πŸ”” Alright, I will remind you!"

def handle_timer_action(username: str):
return f"⏰ Don't worry, I'll help you keep track of time for that tea with your friend, {username}!"
def handle_timer_action(username: str, action:str):
return f"⏰ Alright, the timer is set!"

def handle_unknown_action():
return "πŸ€” I'm sorry, I didn't quite catch that. Could you please clarify?"
return "πŸ‘€ Sorry , but I can't help with that!"


@app.post("/task3/action", tags=["Task 3"], summary="🀌")
def task3_action(request: ActionRequest):
"""Accepts an action request, recognizes its intent and forwards it to the corresponding action handler."""
users = []
users.append(friends.keys())
users.extend(friends.values[0])
users.extend(friends.values[1])
if username not in users:
return f"Hi {username}, I don't know you yet. But I would love to meet you!"

action = request.action.lower()
if "call" in action:
return handle_call_action(request.username)
elif "reminder" in action:
return handle_reminder_action(request.username)
elif "timer" in action:
return handle_timer_action(request.username)
if "call" in action.lower():
return handle_call_action(request.username, request.action)
elif "remind" in action.lower():
return handle_reminder_action(request.username, request.action)
elif "timer" in action.lower():
return handle_timer_action(request.username, request.action)
else:
return handle_unknown_action()

Expand Down

0 comments on commit d6fa7ad

Please sign in to comment.