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}")