fix: responder a partir dos livros com embeddings em português

Usa o modelo multilingual, ignora trechos curtos e o template do Llama 3.2
para a resposta sair em uma frase completa. O chat deixa a API livre durante
a geração, o upload indexa o PDF e os agendamentos não são gravados duas vezes.
This commit is contained in:
lgcosta committed 2026-11-01 12:34:54 -03:00
1 parent 7af7ba530d
commit 8eeb6b89f4
11 files changed
+185 -90

No files matched your search

+30 -8
View File
@@ -30,25 +30,47 @@ def save_schedules(schedules: List[Dict]):
with open("/app/schedules.json", "w") as f:
json.dump(schedules, f, indent=2)
def schedule_is_due(schedule: Dict) -> bool:
raw = str(schedule.get("time", "")).replace("Z", "+00:00")
when = datetime.fromisoformat(raw)
if when.tzinfo is not None:
when = when.astimezone().replace(tzinfo=None)
return datetime.now() >= when
@celery.task
def send_scheduled_message(schedule_id: int = None):
"""Send one schedule, or every enabled schedule when id is omitted."""
"""Send enabled schedules whose time has arrived and that were not sent yet."""
schedules = load_schedules()
if schedule_id is None:
selected = [item for item in schedules if item.get("enabled", True)]
else:
selected = [item for item in schedules if item.get("id") == schedule_id and item.get("enabled", True)]
due = []
for item in schedules:
if schedule_id is not None and item.get("id") != schedule_id:
continue
if not item.get("enabled", True) or item.get("sent"):
continue
try:
ready = schedule_is_due(item)
except ValueError:
print(f"Invalid schedule time: {item.get('time')}")
continue
if ready:
due.append(item)
if not selected:
print(f"Schedule {schedule_id} not found")
if not due:
print("No schedules due")
return
for schedule in selected:
changed = False
for schedule in due:
try:
bot_service.send_scheduled_message(schedule)
schedule["sent"] = True
changed = True
print(f"Sent scheduled message: {schedule['time']}")
except Exception as e:
print(f"Error sending scheduled message: {e}")
if changed:
save_schedules(schedules)
@celery.task
def generate_daily_content():