Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,24 +31,36 @@ chain = llm | StrOutputParser()
|
|
31 |
ranker = Reranker("answerdotai/answerai-colbert-small-v1", model_type="colbert")
|
32 |
|
33 |
# Funci贸n RAG
|
34 |
-
def rag_chat(
|
|
|
|
|
|
|
35 |
results = vectordb.similarity_search_with_score(query)
|
36 |
context = []
|
37 |
for doc, score in results:
|
38 |
if score < 7:
|
39 |
context.append(doc.page_content)
|
40 |
if not context:
|
41 |
-
return "No tengo informaci贸n para responder a esa pregunta."
|
42 |
|
43 |
ranking = ranker.rank(query=query, docs=context)
|
44 |
best_context = ranking[0].text
|
45 |
|
46 |
-
prompt =
|
47 |
-
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
|
|
|
|
|
52 |
# Interfaz Gradio
|
53 |
-
iface = gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
54 |
iface.launch()
|
|
|
31 |
ranker = Reranker("answerdotai/answerai-colbert-small-v1", model_type="colbert")
|
32 |
|
33 |
# Funci贸n RAG
|
34 |
+
def rag_chat(message, history):
|
35 |
+
# Solo usamos el mensaje del usuario
|
36 |
+
query = message
|
37 |
+
|
38 |
results = vectordb.similarity_search_with_score(query)
|
39 |
context = []
|
40 |
for doc, score in results:
|
41 |
if score < 7:
|
42 |
context.append(doc.page_content)
|
43 |
if not context:
|
44 |
+
return "No tengo informaci贸n suficiente para responder a esa pregunta."
|
45 |
|
46 |
ranking = ranker.rank(query=query, docs=context)
|
47 |
best_context = ranking[0].text
|
48 |
|
49 |
+
prompt = f"""Contesta a la siguiente pregunta usando solo el contexto que se proporciona:
|
50 |
+
|
51 |
+
Contexto:
|
52 |
+
{best_context}
|
53 |
|
54 |
+
Pregunta: {query}
|
55 |
+
Respuesta:"""
|
56 |
|
57 |
+
return llm.invoke(prompt)
|
58 |
+
|
59 |
# Interfaz Gradio
|
60 |
+
iface = gr.ChatInterface(
|
61 |
+
fn=rag_chat,
|
62 |
+
title="Chat Julio Verne - RAG",
|
63 |
+
description="Pregunta lo que quieras sobre *La vuelta al mundo en 80 d铆as* de Julio Verne.",
|
64 |
+
chatbot=gr.Chatbot(type="messages") # 馃憟 Esto elimina el warning de formato obsoleto
|
65 |
+
)
|
66 |
iface.launch()
|