-
Notifications
You must be signed in to change notification settings - Fork 5
/
openai_api.py
42 lines (40 loc) · 1.58 KB
/
openai_api.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
import openai
import json
class OpenAI_API:
def __init__(self, api_key):
openai.api_key = api_key
def get_completion(self, messages):
response = openai.ChatCompletion.create(
model="gpt-4-0613",
messages=messages,
functions=[
{
"name": "execute_python_code",
"description": "Execute python code in a stateful conda virtual jupyter like environment",
"parameters": {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "string of python code you want to execute",
},
},
"required": ["code"],
},
"name": "execute_cmd_shell",
"description": "Execute shell commands while maintaining a stateful experience",
"parameters": {
"type": "object",
"properties": {
"cmd_str": {
"type": "string",
"description": "string containing a shell command you want to execute",
},
},
"required": ["cmd_str"],
},
}
],
temperature=0,
)
return response