Uhhy commited on
Commit
95ed60f
1 Parent(s): d6a8693

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -136,10 +136,9 @@ def filter_by_similarity(responses):
136
  break
137
  return best_response
138
 
139
- def worker_function(llm, request, progress_bar):
140
  print(f"Generando respuesta con el modelo {llm}...")
141
  response = generate_chat_response(request, llm)
142
- progress_bar.update(1)
143
  return response
144
 
145
  @app.post("/generate_chat")
@@ -152,15 +151,14 @@ async def generate_chat(request: ChatRequest):
152
  responses = []
153
  num_models = len(global_data['models'])
154
 
155
- with tqdm(total=num_models, desc="Generando respuestas", unit="modelo") as progress_bar:
156
- with ThreadPoolExecutor(max_workers=num_models) as executor:
157
- futures = [executor.submit(worker_function, llm, request, progress_bar) for llm in global_data['models']]
158
- for future in as_completed(futures):
159
- try:
160
- response = future.result()
161
- responses.append(response['response'])
162
- except Exception as exc:
163
- print(f"Error en la generación de respuesta: {exc}")
164
 
165
  best_response = select_best_response(responses)
166
 
 
136
  break
137
  return best_response
138
 
139
+ def worker_function(llm, request):
140
  print(f"Generando respuesta con el modelo {llm}...")
141
  response = generate_chat_response(request, llm)
 
142
  return response
143
 
144
  @app.post("/generate_chat")
 
151
  responses = []
152
  num_models = len(global_data['models'])
153
 
154
+ with ThreadPoolExecutor(max_workers=num_models) as executor:
155
+ futures = [executor.submit(worker_function, llm, request) for llm in global_data['models']]
156
+ for future in tqdm(as_completed(futures), total=num_models, desc="Generando respuestas", unit="modelo"):
157
+ try:
158
+ response = future.result()
159
+ responses.append(response['response'])
160
+ except Exception as exc:
161
+ print(f"Error en la generación de respuesta: {exc}")
 
162
 
163
  best_response = select_best_response(responses)
164