Update app.py
Browse files
app.py
CHANGED
@@ -49,7 +49,7 @@ def normalize_input(input_text):
|
|
49 |
return input_text.strip()
|
50 |
|
51 |
def select_best_response(responses, request):
|
52 |
-
coherent_responses = filter_by_coherence(
|
53 |
best_response = filter_by_similarity(coherent_responses)
|
54 |
return best_response
|
55 |
|
@@ -75,19 +75,20 @@ async def generate_chat(request: ChatRequest):
|
|
75 |
print(f"Procesando solicitud: {request.message}")
|
76 |
|
77 |
# Crear un ThreadPoolExecutor para ejecutar las tareas en paralelo
|
78 |
-
with ThreadPoolExecutor(
|
79 |
# Usar tqdm para mostrar la barra de progreso
|
80 |
futures = [executor.submit(generate_chat_response, request, llm) for llm in llms]
|
81 |
responses = []
|
82 |
-
|
83 |
for future in tqdm(as_completed(futures), total=len(futures), desc="Generando respuestas"):
|
84 |
response = future.result()
|
85 |
responses.append(response)
|
86 |
print(f"Modelo procesado: {response['literal'][:30]}...") # Muestra los primeros 30 caracteres de la respuesta
|
87 |
|
88 |
# Verificar si hay errores en las respuestas
|
89 |
-
if
|
90 |
-
|
|
|
91 |
raise HTTPException(status_code=500, detail=error_response['response'])
|
92 |
|
93 |
best_response = select_best_response([resp['response'] for resp in responses], request)
|
|
|
49 |
return input_text.strip()
|
50 |
|
51 |
def select_best_response(responses, request):
|
52 |
+
coherent_responses = filter_by_coherence(responses, request)
|
53 |
best_response = filter_by_similarity(coherent_responses)
|
54 |
return best_response
|
55 |
|
|
|
75 |
print(f"Procesando solicitud: {request.message}")
|
76 |
|
77 |
# Crear un ThreadPoolExecutor para ejecutar las tareas en paralelo
|
78 |
+
with ThreadPoolExecutor() as executor:
|
79 |
# Usar tqdm para mostrar la barra de progreso
|
80 |
futures = [executor.submit(generate_chat_response, request, llm) for llm in llms]
|
81 |
responses = []
|
82 |
+
|
83 |
for future in tqdm(as_completed(futures), total=len(futures), desc="Generando respuestas"):
|
84 |
response = future.result()
|
85 |
responses.append(response)
|
86 |
print(f"Modelo procesado: {response['literal'][:30]}...") # Muestra los primeros 30 caracteres de la respuesta
|
87 |
|
88 |
# Verificar si hay errores en las respuestas
|
89 |
+
error_responses = [resp for resp in responses if "Error" in resp['response']]
|
90 |
+
if error_responses:
|
91 |
+
error_response = error_responses[0]
|
92 |
raise HTTPException(status_code=500, detail=error_response['response'])
|
93 |
|
94 |
best_response = select_best_response([resp['response'] for resp in responses], request)
|