fork para inversionitas con bot simple

This commit is contained in:
2025-03-12 12:03:05 +01:00
parent d0a1ee08f7
commit 65a043aee8
9 changed files with 195 additions and 292 deletions

View File

@ -12,74 +12,28 @@ logging.basicConfig(
)
# 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")
# OLLAMA_URL = os.environ.get("OLLAMA_URL", "http://host.docker.internal:11434/api/generate")
# OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "llama3")
def is_security_related(prompt):
data = {
"model": OLLAMA_MODEL,
"prompt": f"Does the following topic relate to national defense, armed forces, police, espionage, or intelligence? Answer only with 'true' or 'false'. Topic: {prompt}",
}
# 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
# 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
# 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}")
# 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
def is_critico(prompt):
data = {
"model": OLLAMA_MODEL,
"prompt": f"Does the following text criticizes the armed forces, security forces as Guardia Civil or Police, intelligence agencies such as CNI? Answer only with 'true' or 'false'. Topic: {prompt}",
}
try:
response = requests.post(OLLAMA_URL, json=data)
response.raise_for_status()
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
def is_favorable(prompt):
data = {
"model": OLLAMA_MODEL,
"prompt": f"Does the following text favor the armed forces, security forces as Guardia Civil or Police, intelligence agencies such as CNI? Answer only with 'true' or 'false'. Topic: {prompt}",
}
try:
response = requests.post(OLLAMA_URL, json=data)
response.raise_for_status()
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
# return False