diff --git a/SupportPC.py b/SupportPC.py index e58a398..c097c29 100644 --- a/SupportPC.py +++ b/SupportPC.py @@ -1,5 +1,6 @@ import sys import requests +import json 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 user_message = self.text_input.text() + # TEMPORAIRE + tokens = 100 + temperature = 0.1 + # Increment message counter self.num_messages += 1 - # Send greeting to user - bot_response = f"Hello, you have sent {self.num_messages} messages." + # Define the API endpoint URL + 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 self.chat_window.append(f"

You: {user_message}

")