-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
71 lines (60 loc) · 1.59 KB
/
Copy pathutils.py
File metadata and controls
71 lines (60 loc) · 1.59 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
import openai
import webbrowser
from configparser import ConfigParser
from tkinter import messagebox
from tkinter.simpledialog import askstring
from tkinter.filedialog import asksaveasfile
class Message:
@staticmethod
def ask_api():
return askstring("API KEY", "Set your API_KEY")
@staticmethod
def api_error():
messagebox.showerror("Error", "Error: Set API KEY first!")
@staticmethod
def show_error():
messagebox.showerror(
"Error",
"\n".join((
"Something went wrong!",
"Check your API_KEY again!"
)),
)
@staticmethod
def save(content):
file = asksaveasfile(
title="Save as",
filetypes= (
("All files", "*.*"),
("Python file", "*.py"),
("Markdown document", "*.md"),
("Text document", "*.txt"),
),
)
try:
file.write(str(content))
except:
pass
else:
file.close()
@staticmethod
def callback(url):
webbrowser.open_new_tab(url)
def get_cfg(filename="config.ini"):
config = ConfigParser()
config.read(filename)
return config
def get_completion(
prompt,
api_key=None,
model="gpt-3.5-turbo",
temperature=0,
):
openai.api_key = api_key
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature,
)
return response.choices[0].message["content"]