|
|
|
@ -1,5 +1,6 @@
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import json
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QTextEdit, QPushButton, QLineEdit, QWidget
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QTextEdit, QPushButton, QLineEdit, QWidget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,11 +38,37 @@ class MainWindow(QMainWindow):
|
|
|
|
# Get user's message from text input field
|
|
|
|
# Get user's message from text input field
|
|
|
|
user_message = self.text_input.text()
|
|
|
|
user_message = self.text_input.text()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TEMPORAIRE
|
|
|
|
|
|
|
|
tokens = 100
|
|
|
|
|
|
|
|
temperature = 0.1
|
|
|
|
|
|
|
|
|
|
|
|
# Increment message counter
|
|
|
|
# Increment message counter
|
|
|
|
self.num_messages += 1
|
|
|
|
self.num_messages += 1
|
|
|
|
|
|
|
|
|
|
|
|
# Send greeting to user
|
|
|
|
# Define the API endpoint URL
|
|
|
|
bot_response = f"Hello, you have sent {self.num_messages} messages."
|
|
|
|
endpoint = 'https://api.openai.com/v1/completions'
|
|
|
|
|
|
|
|
apiKey = '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'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define the request headers (if needed)
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
|
|
|
"Authorization": f"Bearer {apiKey}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_data = {
|
|
|
|
|
|
|
|
"model": "text-davinci-002",
|
|
|
|
|
|
|
|
"prompt": user_message,
|
|
|
|
|
|
|
|
"max_tokens": tokens,
|
|
|
|
|
|
|
|
"temperature": temperature
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send the POST request and capture the response
|
|
|
|
|
|
|
|
response = requests.post(endpoint, headers=headers, data=json.dumps(json_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Retrieve the response from the API
|
|
|
|
|
|
|
|
response_dict = response.json()
|
|
|
|
|
|
|
|
ext = response_dict["choices"][0]["text"]
|
|
|
|
|
|
|
|
bot_response = f"{ext}"
|
|
|
|
|
|
|
|
|
|
|
|
# Add user's message and bot's response to chat window
|
|
|
|
# Add user's message and bot's response to chat window
|
|
|
|
self.chat_window.append(f"<p style='color: #0084ff;'><strong>You:</strong> {user_message}</p>")
|
|
|
|
self.chat_window.append(f"<p style='color: #0084ff;'><strong>You:</strong> {user_message}</p>")
|
|
|
|
|