geronimo-pericoli
commited on
Commit
•
333b9c7
1
Parent(s):
66df018
Update app.py
Browse files
app.py
CHANGED
@@ -81,14 +81,13 @@ def draw_graph():
|
|
81 |
return Image.open(buf)
|
82 |
|
83 |
|
84 |
-
def extraer_informacion_metadata(respuesta, max_results=10):
|
85 |
-
# Obtener source_nodes de la respuesta
|
86 |
-
source_nodes = respuesta.source_nodes
|
87 |
|
|
|
88 |
# Obtener page_labels, file_names y scores de source_nodes
|
89 |
page_file_info = [
|
90 |
-
f"Página {node.node.metadata.get('page_label', '')} del archivo {node.node.metadata
|
91 |
for node in source_nodes
|
|
|
92 |
]
|
93 |
|
94 |
# Limitar la cantidad de resultados
|
@@ -96,6 +95,8 @@ def extraer_informacion_metadata(respuesta, max_results=10):
|
|
96 |
|
97 |
return page_file_info
|
98 |
|
|
|
|
|
99 |
from typing import List
|
100 |
from llama_index.core import Prompt
|
101 |
from llama_index.core.llms import ChatMessage, MessageRole
|
@@ -149,14 +150,19 @@ with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
|
149 |
def respond(message, chat_history):
|
150 |
global chat_history_engine
|
151 |
global result_metadata
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
# Si chat_history está vacío, inicialízalo con el mensaje del usuario actual
|
154 |
if not chat_history:
|
155 |
chat_history = [[message, ""]]
|
156 |
else:
|
157 |
# Si chat_history no está vacío, agrega el mensaje actual al final de la lista
|
158 |
chat_history.append([message, ""])
|
159 |
-
|
160 |
chat_history_engine = summarize_assistant_messages(chat_history_engine)
|
161 |
#chat_history_engine.append(ChatMessage(role=MessageRole.USER, content=message))
|
162 |
response = chat_engine.stream_chat(message, chat_history=chat_history_engine)
|
@@ -171,11 +177,9 @@ with gr.Blocks(theme='sudeepshouche/minimalist') as demo:
|
|
171 |
for text in response.response_gen:
|
172 |
chat_history[-1][1] += text # Agrega el texto de respuesta al último mensaje en chat_history
|
173 |
yield "", chat_history
|
174 |
-
|
175 |
print("----------")
|
176 |
print(memory.get_all())
|
177 |
-
#chat_history_engine.append(ChatMessage(role=MessageRole.ASSISTANT, content=chat_history[-1][1]))
|
178 |
-
#return "", chat_history
|
179 |
|
180 |
|
181 |
gr.Markdown("""
|
|
|
81 |
return Image.open(buf)
|
82 |
|
83 |
|
|
|
|
|
|
|
84 |
|
85 |
+
def extraer_informacion_metadata(source_nodes, max_results=10):
|
86 |
# Obtener page_labels, file_names y scores de source_nodes
|
87 |
page_file_info = [
|
88 |
+
f"Página {node.node.metadata.get('page_label', '')} del archivo {node.node.metadata['file_name']} (Relevance: {node.score:.2f} - Id: {node.node.id_})"
|
89 |
for node in source_nodes
|
90 |
+
if 'file_name' in node.node.metadata and node.node.metadata['file_name']
|
91 |
]
|
92 |
|
93 |
# Limitar la cantidad de resultados
|
|
|
95 |
|
96 |
return page_file_info
|
97 |
|
98 |
+
|
99 |
+
|
100 |
from typing import List
|
101 |
from llama_index.core import Prompt
|
102 |
from llama_index.core.llms import ChatMessage, MessageRole
|
|
|
150 |
def respond(message, chat_history):
|
151 |
global chat_history_engine
|
152 |
global result_metadata
|
153 |
+
|
154 |
+
# Verificar si el mensaje está vacío o no contiene nada
|
155 |
+
if not message.strip():
|
156 |
+
gr.Info("Escribe un mensaje en el chat")
|
157 |
+
return
|
158 |
+
|
159 |
# Si chat_history está vacío, inicialízalo con el mensaje del usuario actual
|
160 |
if not chat_history:
|
161 |
chat_history = [[message, ""]]
|
162 |
else:
|
163 |
# Si chat_history no está vacío, agrega el mensaje actual al final de la lista
|
164 |
chat_history.append([message, ""])
|
165 |
+
|
166 |
chat_history_engine = summarize_assistant_messages(chat_history_engine)
|
167 |
#chat_history_engine.append(ChatMessage(role=MessageRole.USER, content=message))
|
168 |
response = chat_engine.stream_chat(message, chat_history=chat_history_engine)
|
|
|
177 |
for text in response.response_gen:
|
178 |
chat_history[-1][1] += text # Agrega el texto de respuesta al último mensaje en chat_history
|
179 |
yield "", chat_history
|
180 |
+
|
181 |
print("----------")
|
182 |
print(memory.get_all())
|
|
|
|
|
183 |
|
184 |
|
185 |
gr.Markdown("""
|