-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
60 lines (46 loc) · 1.98 KB
/
Copy pathchatbot.py
File metadata and controls
60 lines (46 loc) · 1.98 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
# utf-8 encoded
# Importar la biblioteca PyQt5
from PyQt5 import QtWidgets
# Importar la biblioteca openai
import openai
# Establecer la clave de API de GPT-3
openai.api_key = "aqui va tu api key"
class GPT3Window(QtWidgets.QWidget):
def __init__(self):
super().__init__()
# Crear un cuadro de texto donde el usuario pueda escribir una pregunta
self.question_input = QtWidgets.QLineEdit(self)
# Crear un boton para enviar la pregunta a GPT-3
self.submit_button = QtWidgets.QPushButton("Enviar", self)
# Crear un cuadro de texto donde se mostrara la respuesta de GPT-3
self.answer_output = QtWidgets.QTextEdit(self)
# Conectar el evento de hacer clic en el bot�n con una funci�n para enviar la pregunta a GPT-3
self.submit_button.clicked.connect(self.submit_question)
# Crear un diseno para organizar los widgets en la ventana
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.question_input)
layout.addWidget(self.submit_button)
layout.addWidget(self.answer_output)
self.setLayout(layout)
# Establecer el titulo de la ventana y mostrarla
self.setWindowTitle("GPT-3 Chat")
self.resize(500, 300)
self.show()
def submit_question(self):
# Obtener la pregunta del cuadro de texto de entrada
question = self.question_input.text()
# Enviar la pregunta a GPT-3 y obtener una respuesta
response = openai.Completion.create(
engine="text-davinci-003",
prompt=question,
temperature=0.5,
max_tokens=1024,
n=1,
stop=["?"],
)
# Mostrar la respuesta de GPT-3 en el cuadro de texto de salida
self.answer_output.setText(response["choices"][0]["text"])
# Crear una instancia de la ventana y ejecutar el script
app = QtWidgets.QApplication([])
window = GPT3Window()
app.exec_()