Files
inversionitasbot/scrapper/iacorrector.py
2025-02-05 22:45:41 +01:00

67 lines
2.3 KiB
Python

import requests
import json
def is_security_related(prompt):
url = "http://localhost:11434/api/generate"
data = {
"model": "llama3",
"prompt": f"Does the following topic relate to national defense, armed forces, police, espionage, or intelligence? Answer only with 'true' or 'false'. Topic: {prompt}",
}
response = requests.post(url, json=data)
try:
# Dividir la respuesta en líneas y parsear cada una
for line in response.text.strip().split("\n"):
json_data = json.loads(line)
if "response" in json_data and json_data["response"].strip():
return json_data["response"].strip().lower() == "true"
except json.JSONDecodeError as e:
print("JSON Decode Error:", e)
return False
def is_critico(prompt):
url = "http://localhost:11434/api/generate"
data = {
"model": "llama3",
"prompt": f"Does the following text critics the armed forces, security forces as Guardia Civil or Police, intelligence agencies such as CNI? Answer only with 'true' or 'false'. Topic: {prompt}",
}
response = requests.post(url, json=data)
try:
# Dividir la respuesta en líneas y parsear cada una
for line in response.text.strip().split("\n"):
json_data = json.loads(line)
if "response" in json_data and json_data["response"].strip():
return json_data["response"].strip().lower() == "true"
except json.JSONDecodeError as e:
print("JSON Decode Error:", e)
return False
def is_favorable(prompt):
url = "http://localhost:11434/api/generate"
data = {
"model": "llama3",
"prompt": f"Does the following text favours the armed forces, security forces as Guardia Civil or Police, intelligence agencies such as CNI? Answer only with 'true' or 'false'. Topic: {prompt}",
}
response = requests.post(url, json=data)
try:
# Dividir la respuesta en líneas y parsear cada una
for line in response.text.strip().split("\n"):
json_data = json.loads(line)
if "response" in json_data and json_data["response"].strip():
return json_data["response"].strip().lower() == "true"
except json.JSONDecodeError as e:
print("JSON Decode Error:", e)
return False