import json import requests def get_current_weather(location, unit="celsius"): """Get the current weather in a given location""" if "taipei" in location.lower(): return json.dumps({"location": "Taipei", "temperature": "10", "unit": unit}) else: return json.dumps({"location": location, "temperature": "unknown"}) def get_junyi_content(type): print(f"Fetching Junyi content of type {type}") base_url = "https://www.junyiacademy.org/api/v2/open/content/topicpage/" topic_id = "knsh-7a" url = f"{base_url}{topic_id}" response = requests.get(url) if response.status_code == 200: data = response.json() print(data) else: print(f"Request failed with status code {response.status_code}") if type == "english": return json.dumps( { "content": "英文", "url": "https://www.junyiacademy.org/junyi-english/eng-junior/eng-junior07/eng-junior07-knsh/knsh-7a", } ) def get_openai_function_tools(): tools = [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use. Infer this from the users location.", }, }, "required": ["location", "unit"], }, }, }, { "type": "function", "function": { "name": "get_junyi_content", "description": "Get the content from Junyi Academy", "parameters": { "type": "object", "properties": { "type": { "type": "string", "enum": ["english", "math"], "description": "The type of content to fetch", }, }, "required": ["type"], }, }, }, ] return tools def get_functions(): return { "get_current_weather": get_current_weather, "get_junyi_content": get_junyi_content, }