Spaces:
Sleeping
Sleeping
Update app.py
Browse filesdef handle_query(query, index)
y
dccuchile/bert-base-spanish-wwm-cased.
app.py
CHANGED
@@ -20,7 +20,7 @@ Settings.llm = HuggingFaceInferenceAPI(
|
|
20 |
generate_kwargs={"temperature": 0.1},
|
21 |
)
|
22 |
Settings.embed_model = HuggingFaceEmbedding(
|
23 |
-
model_name="
|
24 |
)
|
25 |
|
26 |
# Define the directory for persistent storage and data
|
@@ -48,10 +48,10 @@ def handle_query(query, index):
|
|
48 |
chat_text_qa_msgs = [
|
49 |
(
|
50 |
"user",
|
51 |
-
"""Debes
|
52 |
-
|
53 |
{context_str}
|
54 |
-
|
55 |
{query_str}
|
56 |
"""
|
57 |
)
|
@@ -61,12 +61,20 @@ def handle_query(query, index):
|
|
61 |
query_engine = index.as_query_engine(text_qa_template=text_qa_template)
|
62 |
answer = query_engine.query(query)
|
63 |
|
|
|
64 |
if hasattr(answer, 'response'):
|
65 |
-
|
66 |
elif isinstance(answer, dict) and 'response' in answer:
|
67 |
-
|
68 |
else:
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Initialize session state
|
72 |
if 'messages' not in st.session_state:
|
|
|
20 |
generate_kwargs={"temperature": 0.1},
|
21 |
)
|
22 |
Settings.embed_model = HuggingFaceEmbedding(
|
23 |
+
model_name="dccuchile/bert-base-spanish-wwm-cased"
|
24 |
)
|
25 |
|
26 |
# Define the directory for persistent storage and data
|
|
|
48 |
chat_text_qa_msgs = [
|
49 |
(
|
50 |
"user",
|
51 |
+
"""Debes contestar en español. Eres un asistente llamado Lobito hecho en la UPNFM. Tu objetivo principal es proporcionar respuestas lo más precisas posible, basadas en las instrucciones y el contexto que se te han dado. Si una pregunta no coincide con el contexto proporcionado o está fuera del alcance del documento, amablemente aconseja al usuario que haga preguntas dentro del contexto del documento.
|
52 |
+
Contexto:
|
53 |
{context_str}
|
54 |
+
Pregunta:
|
55 |
{query_str}
|
56 |
"""
|
57 |
)
|
|
|
61 |
query_engine = index.as_query_engine(text_qa_template=text_qa_template)
|
62 |
answer = query_engine.query(query)
|
63 |
|
64 |
+
# Asegurar que las respuestas siempre estén en español
|
65 |
if hasattr(answer, 'response'):
|
66 |
+
response = answer.response
|
67 |
elif isinstance(answer, dict) and 'response' in answer:
|
68 |
+
response = answer['response']
|
69 |
else:
|
70 |
+
response = "Lo siento, no tengo información sobre este tema en el contexto proporcionado. Por favor, intenta con otra pregunta."
|
71 |
+
|
72 |
+
# Verificar si la respuesta está en inglés y corregirla
|
73 |
+
if "The provided text does not contain" in response:
|
74 |
+
response = "Lo siento, no tengo información en el contexto proporcionado sobre este tema."
|
75 |
+
|
76 |
+
return response
|
77 |
+
|
78 |
|
79 |
# Initialize session state
|
80 |
if 'messages' not in st.session_state:
|