init: scripts diversos (crawlers, conversores, scrapers)
This commit is contained in:
56
scraper/test_gemini_response.py
Executable file
56
scraper/test_gemini_response.py
Executable file
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import requests
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
API_KEY = os.getenv("OPENROUTER_API_KEY")
|
||||
API_URL = "https://openrouter.ai/api/v1/chat/completions"
|
||||
|
||||
# Teste simples
|
||||
test_prompt = """
|
||||
És um especialista em estofamento automotivo.
|
||||
|
||||
Analisa este texto e extrai conhecimento útil.
|
||||
|
||||
FORMATO JSON DE SAÍDA:
|
||||
{
|
||||
"relevante": true/false,
|
||||
"problema": "descrição do problema se existir"
|
||||
}
|
||||
|
||||
SE NÃO HOUVER CONTEÚDO ÚTIL, retorna: {"relevante": false}
|
||||
|
||||
TEXTO:
|
||||
Leather seat repair tutorial for BMW E30.
|
||||
|
||||
Responde APENAS com o JSON, sem texto adicional.
|
||||
"""
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {API_KEY}",
|
||||
"Content-Type": "application/json",
|
||||
"HTTP-Referer": "https://descomplicar.pt",
|
||||
"X-Title": "CTF Knowledge Test"
|
||||
}
|
||||
|
||||
data = {
|
||||
"model": "google/gemini-2.5-flash",
|
||||
"messages": [{"role": "user", "content": test_prompt}],
|
||||
"temperature": 0.2,
|
||||
"max_tokens": 500
|
||||
}
|
||||
|
||||
response = requests.post(API_URL, headers=headers, json=data, timeout=30)
|
||||
print("STATUS:", response.status_code)
|
||||
print("\nRESPOSTA RAW:")
|
||||
print(response.json())
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
content = result['choices'][0]['message']['content']
|
||||
print("\n\nCONTEÚDO EXTRAÍDO:")
|
||||
print(repr(content)) # Mostrar com caracteres escapados
|
||||
print("\n\nCONTEÚDO FORMATADO:")
|
||||
print(content)
|
||||
Reference in New Issue
Block a user