geronimo-pericoli
commited on
Commit
•
1a9d9ac
1
Parent(s):
091d09c
Update app.py
Browse files
app.py
CHANGED
@@ -366,8 +366,29 @@ def ctx_relevancy_eval():
|
|
366 |
|
367 |
def faithfulness_eval():
|
368 |
global final_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
evaluator = FaithfulnessEvaluator(llm=gpt4omini)
|
370 |
-
eval_result = evaluator.
|
371 |
|
372 |
print("Groundedness: " + str(eval_result.score) + " - " + str(eval_result.passing) + "\n")
|
373 |
print("Respuesta: " + str(final_response) + "\n\n----------")
|
|
|
366 |
|
367 |
def faithfulness_eval():
|
368 |
global final_response
|
369 |
+
global query
|
370 |
+
|
371 |
+
# Verificamos si 'final_response' tiene el atributo 'source_nodes'
|
372 |
+
if not hasattr(final_response, 'source_nodes'):
|
373 |
+
raise AttributeError("El objeto 'final_response' no tiene un atributo 'source_nodes'.")
|
374 |
+
|
375 |
+
# Obtener los source_nodes de la respuesta
|
376 |
+
source_nodes = final_response.source_nodes
|
377 |
+
|
378 |
+
# Extraer los textos de los source nodes
|
379 |
+
contexts = []
|
380 |
+
for node in source_nodes:
|
381 |
+
if node.score <= 1: # Excluir nodos con score > 1
|
382 |
+
text = node.node.text.strip()
|
383 |
+
contexts.append(text)
|
384 |
+
|
385 |
+
# Si no se encuentran textos en los source nodes, puedes manejarlo de alguna forma
|
386 |
+
if not contexts:
|
387 |
+
raise ValueError("No se encontraron textos en los source nodes.")
|
388 |
+
|
389 |
+
|
390 |
evaluator = FaithfulnessEvaluator(llm=gpt4omini)
|
391 |
+
eval_result = evaluator.evaluate(query=query, response=final_response, contexts=contexts)
|
392 |
|
393 |
print("Groundedness: " + str(eval_result.score) + " - " + str(eval_result.passing) + "\n")
|
394 |
print("Respuesta: " + str(final_response) + "\n\n----------")
|