45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import logging
|
|
import uuid
|
|
|
|
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__)
|
|
|
|
|
|
def _make_summarise_service() -> SummariseService:
|
|
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(),
|
|
)
|
|
|
|
|
|
@procrastinate_app.task(queue="default")
|
|
async def summarise_article(
|
|
job_id: str,
|
|
article_id: str,
|
|
source_language: str,
|
|
target_language: str,
|
|
complexity_level: str,
|
|
input_texts: list[str],
|
|
) -> None:
|
|
async with AsyncSessionLocal() as db:
|
|
await _make_summarise_service().run(
|
|
db=db,
|
|
job_id=uuid.UUID(job_id),
|
|
article_id=uuid.UUID(article_id),
|
|
source_language=source_language,
|
|
target_language=target_language,
|
|
complexity_level=complexity_level,
|
|
input_texts=input_texts,
|
|
)
|