2026-05-27 17:45:52 +00:00
|
|
|
import logging
|
|
|
|
|
import uuid
|
|
|
|
|
|
2026-06-02 20:02:50 +00:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
|
|
|
|
from app.outbound.postgres.repositories.article_repository import (
|
|
|
|
|
PostgresArticleRepository,
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-27 17:45:52 +00:00
|
|
|
from ..config import settings
|
|
|
|
|
from ..domain.services.summarise_service import SummariseService
|
|
|
|
|
from ..outbound.anthropic.anthropic_client import AnthropicClient
|
|
|
|
|
from ..outbound.deepgram.deepgram_client import LocalDeepgramClient
|
|
|
|
|
from ..outbound.deepl.deepl_client import DeepLClient
|
|
|
|
|
from ..outbound.gemini.gemini_client import GeminiClient
|
|
|
|
|
from ..outbound.postgres.database import AsyncSessionLocal
|
|
|
|
|
from ..outbound.spacy.spacy_client import SpacyClient
|
|
|
|
|
from .app import procrastinate_app
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
2026-06-02 20:02:50 +00:00
|
|
|
def _make_summarise_service(db: AsyncSession) -> SummariseService:
|
2026-05-27 17:45:52 +00:00
|
|
|
return SummariseService(
|
|
|
|
|
anthropic_client=AnthropicClient.new(settings.anthropic_api_key),
|
|
|
|
|
deepgram_client=LocalDeepgramClient(settings.deepgram_api_key),
|
|
|
|
|
deepl_client=DeepLClient(settings.deepl_api_key),
|
|
|
|
|
gemini_client=GeminiClient(settings.gemini_api_key),
|
|
|
|
|
spacy_client=SpacyClient(),
|
2026-06-02 20:02:50 +00:00
|
|
|
article_repository=PostgresArticleRepository(db),
|
2026-05-27 17:45:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@procrastinate_app.task(queue="default")
|
2026-06-02 20:02:50 +00:00
|
|
|
async def create_summary_article(
|
|
|
|
|
article_id: str, target_language: str, complexity_level: str, input_text: str
|
2026-05-27 17:45:52 +00:00
|
|
|
) -> None:
|
2026-06-02 20:02:50 +00:00
|
|
|
print(f"Starting summarisation task for article_id={article_id}")
|
2026-05-27 17:45:52 +00:00
|
|
|
async with AsyncSessionLocal() as db:
|
2026-06-02 20:02:50 +00:00
|
|
|
print("Session opened, calling summarise service...")
|
|
|
|
|
await _make_summarise_service(db).summarise_article(
|
2026-05-27 17:45:52 +00:00
|
|
|
article_id=uuid.UUID(article_id),
|
|
|
|
|
target_language=target_language,
|
|
|
|
|
complexity_level=complexity_level,
|
2026-06-02 20:02:50 +00:00
|
|
|
input_text=input_text,
|
2026-05-27 17:45:52 +00:00
|
|
|
)
|