Cost control

This commit is contained in:
2026-01-27 09:25:11 +01:00
parent 37eb03583c
commit 0ed89a7045
9 changed files with 733 additions and 6 deletions

View File

@@ -75,6 +75,15 @@ async def main():
await db.update_article_processing(
article.id, relevance_score=0.0, ai_summary="", included=False
)
# Still save the run with costs (for filtering only)
session_cost = ai_client.get_session_cost()
await db.save_run(
articles_fetched=len(articles),
articles_processed=len(unprocessed),
articles_included=0,
total_cost=session_cost,
)
return
# Summarize filtered articles (using batch processing for speed, silently)
@@ -109,14 +118,29 @@ async def main():
article.id, relevance_score=0.0, ai_summary="", included=False
)
# Generate email (silently)
# Get cost information
session_cost = ai_client.get_session_cost()
total_cost = await db.get_total_cost()
cumulative_cost = total_cost + session_cost
# Save run statistics with costs
await db.save_run(
articles_fetched=len(articles),
articles_processed=len(unprocessed),
articles_included=len(digest_entries),
total_cost=session_cost,
filtering_cost=0.0, # Could split this if tracking separately
summarization_cost=0.0,
)
# Generate email (silently) with cost info
generator = EmailGenerator()
date_str = datetime.now().strftime("%A, %B %d, %Y")
subject = config.email.subject_template.format(date=date_str)
html_content, text_content = generator.generate_digest_email(
digest_entries, date_str, subject
digest_entries, date_str, subject, session_cost, cumulative_cost
)
# Send email (silently)