Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def respond(message, chat_history):
|
4 |
bot_message = " ".join([m for m,_ in chat_history]+[message])
|
|
|
1 |
import gradio as gr
|
2 |
+
from SysPrompt import sysPrompt
|
3 |
+
from index_query import get_docs
|
4 |
+
from ChatResponse import get_completion_from_messages, template
|
5 |
+
import json
|
6 |
+
|
7 |
+
def res(prompt, historial):
|
8 |
+
# Preparar historial
|
9 |
+
#historial=json.loads(historial)
|
10 |
+
if historial==[]:
|
11 |
+
historial=sysPrompt
|
12 |
+
historial.append({'role':'user', 'content':prompt})
|
13 |
+
|
14 |
+
# Respuesta
|
15 |
+
context=get_docs(prompt)
|
16 |
+
historial.append({'role':'system', 'content':template(context)})
|
17 |
+
try:
|
18 |
+
respuesta = get_completion_from_messages(historial)
|
19 |
+
historial.pop() # delete the context prompt
|
20 |
+
historial.append({'role':'assistant', 'content': respuesta})
|
21 |
+
except Exception as e:
|
22 |
+
respuesta=str(e)
|
23 |
+
|
24 |
+
return respuesta, historial
|
25 |
|
26 |
def respond(message, chat_history):
|
27 |
bot_message = " ".join([m for m,_ in chat_history]+[message])
|