From cff25775d35b9c4aaf2708a0a8b079d7bb67f843 Mon Sep 17 00:00:00 2001 From: "Mauro Rosero P." Date: Wed, 12 Mar 2025 11:09:14 -0500 Subject: [PATCH] [IMPROVED] Limitar tarifas extremas y usar temperatura baja en API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Añadir parámetro temperature=0.2 para respuestas más consistentes - Implementar límite de tarifa máxima de 200.00 USD/hora - Calcular promedio de tarifas del mismo tipo si se supera el límite - Usar fallback ajustado si no hay datos para calcular promedio - Mejorar mensajes de log para casos donde se ajustan tarifas 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- bin/rate_update.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bin/rate_update.py b/bin/rate_update.py index 3b93e45..05bd89c 100755 --- a/bin/rate_update.py +++ b/bin/rate_update.py @@ -173,7 +173,8 @@ def query_perplexity(prompt, model="o1"): "content": prompt } ], - "max_tokens": 100 + "max_tokens": 100, + "temperature": 0.2 # Usar temperatura baja para respuestas más consistentes } try: @@ -626,6 +627,37 @@ def update_rate_files(): rate = get_fallback_rate(programmer_type, region_code) logger.info(f"Valor de respaldo generado: {rate:.2f}") + # Comprobar si la tarifa es superior a 200.00 USD/hora + rate_threshold = 200.00 + if rate > rate_threshold: + # Buscar todas las tarifas del mismo tipo de programador para calcular el promedio + same_type_rates = [] + for other_file in rate_files: + other_type, other_region = parse_rate_filename(other_file) + + # Solo considerar archivos del mismo tipo con regiones válidas + if other_type == programmer_type and other_region is not None and other_region != region_code: + try: + # Leer el archivo para obtener la tarifa actual + with open(other_file, 'r', encoding='utf-8') as f: + content = f.read().strip() + if content: + other_rate = float(content) + same_type_rates.append(other_rate) + except (ValueError, FileNotFoundError): + continue + + # Si encontramos tarifas del mismo tipo, calcular el promedio + if same_type_rates: + avg_rate = sum(same_type_rates) / len(same_type_rates) + logger.warning(f"Tarifa {rate:.2f} supera el umbral de {rate_threshold}. Usando promedio de {len(same_type_rates)} tarifas: {avg_rate:.2f}") + rate = round(avg_rate, 2) + else: + # Si no hay otras tarifas para calcular el promedio, usar un valor de fallback + fallback_rate = min(rate, get_fallback_rate(programmer_type, region_code) * 1.5) + logger.warning(f"Tarifa {rate:.2f} supera el umbral de {rate_threshold}. No hay datos para promedio. Usando valor ajustado: {fallback_rate:.2f}") + rate = round(fallback_rate, 2) + # Guardar el resultado en el archivo - solo el valor numérico con dos decimales, sin salto de línea with open(rate_file, 'w', encoding='utf-8') as f: f.write(f"{rate:.2f}")