-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfunctions.py
More file actions
72 lines (63 loc) · 2.37 KB
/
functions.py
File metadata and controls
72 lines (63 loc) · 2.37 KB
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
""" This module is an example of how to define functions
that can be called by the OpenAI API. """
import json
import logging
from datetime import datetime
# This list of functions is used to define the available functions
# that can be called by the OpenAI API.
# Used format is JSON schema
FUNCTIONS = [
{
"name": "get_time",
"description":
"Use this function to display the current time."
"It takes 1 parameter: seconds, a boolean value"
"that indicates whether to print the seconds or not.",
"parameters": {
"type": "object",
"properties": {
"seconds": {
"type": "boolean",
"description": "Whether to print the seconds or not."
}
},
"required": ["seconds"]
}
},
{
"name": "get_welcome_message",
"description": "Use this function to get a welcome message. It takes no parameters.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
]
# This function is a prototype for the functions that can be called
def prototype(engine, arguments): # pylint: disable=unused-argument
"""
This function is a prototype for the functions that can be called
by the OpenAI API. It takes two parameters: engine and arguments.
The engine parameter is an instance of the OpenAI API, and the
arguments parameter is a JSON string that contains the arguments
for the function.
"""
args = json.loads(arguments)
logging.info("Function called with arguments: %s", args)
# Perform the function's logic here
def get_time(engine, arguments): # pylint: disable=unused-argument
""" This function is used to display the current time. """
args = json.loads(arguments)
seconds = args.get("seconds", False)
if seconds:
time_format = "%Y-%m-%d %H:%M:%S"
else:
time_format = "%Y-%m-%d %H:%M"
current_time = datetime.now().strftime(time_format)
logging.info("Current time: %s", current_time)
def get_welcome_message(engine, arguments): # pylint: disable=unused-argument
""" This function is used to get a welcome message. """
# args = json.loads(arguments)
welcome_message = "Welcome to the system!"
logging.info("Welcome message: %s", welcome_message)