Exception in Tkinter callback
Traceback (most recent call last):
File "openai\http_client.py", line 221, in request
File "requests\sessions.py", line 587, in request
File "requests\sessions.py", line 701, in send
File "requests\adapters.py", line 458, in send
File "requests\adapters.py", line 262, in cert_verify
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\nicla\dist\app\openai\data/ca-certificates.crt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tkinter\__init__.py", line 1702, in __call__
File "app.py", line 90, in _on_enter_pressed
File "app.py", line 102, in _insert_message
File "app.py", line 22, in askGPT
File "openai\api_resources\completion.py", line 31, in create
File "openai\api_resources\abstract\engine_api_resource.py", line 67, in create
File "openai\api_requestor.py", line 127, in request
File "openai\api_requestor.py", line 322, in request_raw
File "openai\http_client.py", line 87, in request_with_retries
File "openai\http_client.py", line 58, in request_with_retries
File "openai\http_client.py", line 246, in request
File "openai\http_client.py", line 306, in _handle_request_error
openai.error.APIConnectionError: Unexpected error communicating with OpenAI. It looks like there's
probably a configuration issue locally. If this problem persists, let
us know at support@openai.com.
(Network error: A OSError was raised with error message Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\nicla\dist\app\openai\data/ca-certificates.crt)
Hier noch mein Python Code:
from tkinter import *
import openai
import os
os.environ['REQUESTS_CA_BUNDLE'] = r'C:\Users\nicla\cacert.pem'
#Chatbot
def askGPT(text):
openai.api_key = "XXX"
response = openai.Completion.create(
engine = "curie:ft-ruven-2023-03-30-09-22-21",
prompt = text,
temperature = 0.3,
max_tokens = 80,
)
antwort = response.choices[0].text
return antwort
BG_GRAY = "dimgray"
BG_COLOR = "paleturquoise"
BG_COLOR2 = 'teal'
TEXT_COLOR = "black"
Schriftart = "Helvetica 12"
Schriftart_fett = "Helvetica 11 bold"
class ChatApplication:
def __init__(self):
self.window = Tk()
self.setup_main_window()
def run(self):
self.window.mainloop()
def setup_main_window(self):
self.window.title("Chat")
self.window.resizable(width=False, height=False)
self.window.configure(width=400, height=500, bg=BG_COLOR)
#Kopfzeile
kopfzeile = Label(self.window, bg=BG_COLOR2, fg=TEXT_COLOR,
text="EAH-Jena Chatbot", font=Schriftart_fett, pady=10)
kopfzeile.place(relwidth=1, relheight=0.1)
#Teiler Kopfzeile
line = Label(self.window, width=400, bg=BG_GRAY)
line.place(relwidth=1, rely=0.09, relheight=0.0005)
#Textfeld
self.textfeld = Text(self.window, width=20, height=2, bg=BG_COLOR, fg=TEXT_COLOR,
font=Schriftart, padx=5, pady=5, wrap='word')
self.textfeld.place(relheight=0.75, relwidth=1, rely=0.09)
self.textfeld.config(width=self.textfeld.get('1.0', 'end-1c').count('\n')+2) #Textfeldüberlappung mit Scrollbar vermeiden
self.textfeld.configure(cursor="arrow", state=DISABLED)
#scroll bar
scrollbar = Scrollbar(self.textfeld)
scrollbar.place(relheight=1, relx=0.974)
scrollbar.configure(command=self.textfeld.yview)
#unteres label
unteres_label = Label(self.window, bg=BG_COLOR2, height=74)
unteres_label.place(relwidth=1, rely=0.825)
#Chatbox
self.chatbox = Entry(unteres_label, bg=BG_COLOR, fg=TEXT_COLOR, font=Schriftart)
self.chatbox.place(relwidth=0.75, relheight=0.06, rely=0.008, relx=0.011)
self.chatbox.focus()
self.chatbox.bind("<Return>", self._on_enter_pressed)
#Send-Button
send_button = Button(unteres_label, text="Senden", font=Schriftart_fett, width=20, bg=BG_COLOR,
command=lambda: self._on_enter_pressed(None))
send_button.place(relx=0.77, rely=0.008, relheight=0.06, relwidth=0.22)
def _on_enter_pressed(self, event):
msg = self.chatbox.get()
self._insert_message(msg, "Sie")
def _insert_message(self, msg, sender):
if not msg:
return
self.chatbox.delete(0, END) #Text wird aus Message-Box gelöscht
msg1 = f"{sender}: {msg}\n\n" #Message die angezeigt werden soll definieren
self.textfeld.configure(state=NORMAL)
self.textfeld.insert(END, msg1)
self.textfeld.configure(state=DISABLED)
antwort = askGPT(msg)
print(f"API-Anfrage: {msg}")
print(f"API-Antwort: {antwort}")
msg2 = f"{'Bot'}: {antwort}\n\n"
self.textfeld.configure(state=NORMAL)
self.textfeld.insert(END, msg2)
self.textfeld.configure(state=DISABLED)
self.textfeld.see(END)
if __name__=="__main__":
app = ChatApplication()
app.run()
Vielleicht kann mir jemand helfen
