-
Notifications
You must be signed in to change notification settings - Fork 0
/
begin.py
62 lines (57 loc) · 1.54 KB
/
begin.py
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
# -*- coding: utf-8 -*-
# Python
from os.path import dirname
import sys
from dotenv import load_dotenv, find_dotenv
sys.path.append(dirname(find_dotenv()))
load_dotenv()
"""OPENAI_API_KEY or OPENAI_API_KEY_PATH,
OPENAI_ORGANIZATION can be set... or not.
The properly named environment variables are loaded
into the OpenAI library by its' __init__"""
import openai
from json import loads, dumps
from participants import Facilitator
kwa = {
'name': 'Alex',
'role': 'facilitator',
}
Alex = Facilitator(**kwa)
statement = """What's the weather like in Chicago, IL?"""
who = 'Alex'
messages = [
{
"role": "user",
"name":f'{who}',
"content": f'{statement}'
}
]
functions = [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=messages,
functions=functions,
function_call="auto", # auto is default
)
response_messages = list()
for choice in response["choices"]:
message = choice["message"]
content = message.to_dict_recursive()
print(dumps(content, indent=2))
print('ok')