40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import requests
|
|
import json
|
|
import os
|
|
import logging
|
|
|
|
# Configuración del logging
|
|
LOG_FILE = "app.log"
|
|
logging.basicConfig(
|
|
filename=LOG_FILE, # Archivo de logs
|
|
level=logging.INFO, # Nivel de logging (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
format="%(asctime)s - %(levelname)s - %(message)s", # Formato de los logs
|
|
)
|
|
|
|
# Obtener variables de entorno
|
|
# OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://host.docker.internal:11434/api/generate")
|
|
# OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "llama3")
|
|
|
|
# def is_economy_related(prompt):
|
|
# data = {
|
|
# "model": OLLAMA_MODEL,
|
|
# "prompt": f"Does the following topic relate to economy, investing or financial issues? Answer only with 'true' or 'false'. Topic: {prompt}",
|
|
# }
|
|
|
|
# try:
|
|
# response = requests.post(OLLAMA_URL, json=data)
|
|
# response.raise_for_status() # Lanza una excepción si la solicitud falla
|
|
|
|
# for line in response.text.strip().split("\n"):
|
|
# json_data = json.loads(line)
|
|
# if "response" in json_data and json_data["response"].strip():
|
|
# result = json_data["response"].strip().lower() == "true"
|
|
# return result
|
|
|
|
# except requests.RequestException as e:
|
|
# logging.error(f"Request error: {e}")
|
|
# except json.JSONDecodeError as e:
|
|
# logging.error(f"JSON Decode Error: {e}")
|
|
|
|
# return False
|