File size: 2,748 Bytes
203f861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
006b3a2
203f861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
006b3a2
203f861
006b3a2
 
203f861
 
 
 
 
 
 
 
 
006b3a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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,
    }