Spaces:
Sleeping
Sleeping
Commit
·
57da5e9
1
Parent(s):
9ec4448
Upload 3 files
Browse files- .env +2 -0
- img/demo.png +0 -0
- tools.py +47 -0
.env
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# OPEN AI CREDENTIAL
|
2 |
+
OPENAI_KEY = "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"
|
img/demo.png
ADDED
![]() |
tools.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import openai
|
4 |
+
|
5 |
+
|
6 |
+
# Cargar variables de entorno
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
OPENAI_KEY = os.getenv('OPENAI_KEY', '')
|
10 |
+
|
11 |
+
# Asignar la API Key
|
12 |
+
openai.api_key = OPENAI_KEY
|
13 |
+
|
14 |
+
def mychatbot(messages):
|
15 |
+
# Chatbot que hace consultas "query" a una base de conocimiento "contract_knowledge"
|
16 |
+
|
17 |
+
# Enviar solicitud a la api OpenAI con el modelo "GPT-3.5-turbo"
|
18 |
+
res = openai.ChatCompletion.create(
|
19 |
+
model="gpt-3.5-turbo",
|
20 |
+
messages = messages
|
21 |
+
)
|
22 |
+
|
23 |
+
# Del diccionario extraer la informacion correspondiente al id "content"
|
24 |
+
conclusion = res['choices'][0]['message']['content']
|
25 |
+
|
26 |
+
return conclusion
|
27 |
+
|
28 |
+
|
29 |
+
def ask_chatbot(question):
|
30 |
+
|
31 |
+
prompt = f"""
|
32 |
+
Dada la siguiente pregunta realizada por el usuario: {question}.
|
33 |
+
Reponde de manera cálida la conversación.
|
34 |
+
Agrega datos curiososos sobre el espacio y el turismo espacial.
|
35 |
+
"""
|
36 |
+
|
37 |
+
|
38 |
+
# Dialogo con ChatGPT
|
39 |
+
messages = [
|
40 |
+
{"role": "system", "content": "Eres un asistente útil experto en psicología y turismo espacial. Acompañarás al usuario durante todo su viaje espacial."},
|
41 |
+
{"role": "user", "content": prompt}
|
42 |
+
]
|
43 |
+
|
44 |
+
# Output
|
45 |
+
respuesta = mychatbot(messages)
|
46 |
+
|
47 |
+
return respuesta
|