Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| from dotenv import load_dotenv | |
| load_dotenv(override=True) | |
| def push(text: str): | |
| """Send a notification via Pushover when credentials are configured.""" | |
| if not os.getenv("PUSHOVER_TOKEN") or not os.getenv("PUSHOVER_USER"): | |
| # Fail silently if pushover is not configured – avoids runtime errors | |
| print("[PUSHOVER] Not configured, message was:", text, flush=True) | |
| return | |
| requests.post( | |
| "https://api.pushover.net/1/messages.json", | |
| data={ | |
| "token": os.getenv("PUSHOVER_TOKEN"), | |
| "user": os.getenv("PUSHOVER_USER"), | |
| "message": text, | |
| }, | |
| ) | |
| def record_user_details(email, name="Name not provided", notes="not provided"): | |
| push(f"Recording {name} with email {email} and notes {notes}") | |
| return {"recorded": "ok"} | |
| def record_unknown_question(question): | |
| push(f"User made an interesting question that I could not answer: {question}") | |
| return {"recorded": "ok"} | |
| record_user_details_json = { | |
| "name": "record_user_details", | |
| "description": "Use this tool to record that a user is interested in being in touch and provided an email address", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "email": { | |
| "type": "string", | |
| "description": "The email address of this user", | |
| }, | |
| "name": { | |
| "type": "string", | |
| "description": "The user's name, if they provided it", | |
| }, | |
| "notes": { | |
| "type": "string", | |
| "description": "Any additional information about the conversation that's worth recording to give context", | |
| }, | |
| }, | |
| "required": ["email"], | |
| "additionalProperties": False, | |
| }, | |
| } | |
| record_unknown_question_json = { | |
| "name": "record_unknown_question", | |
| "description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "question": { | |
| "type": "string", | |
| "description": "The question that couldn't be answered", | |
| }, | |
| }, | |
| "required": ["question"], | |
| "additionalProperties": False, | |
| }, | |
| } | |
| TOOLS = [ | |
| {"type": "function", "function": record_user_details_json}, | |
| {"type": "function", "function": record_unknown_question_json}, | |
| ] | |
| FUNCTION_MAP = { | |
| "record_user_details": record_user_details, | |
| "record_unknown_question": record_unknown_question, | |
| } | |