-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
51 lines (36 loc) · 1.27 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import asyncio
import logging
from functools import wraps
import typer
from contexts import AppContexts
from src.io import write_summary_to_db
from src.summarization import extract_and_reformat_summary, sanitize_markdown_symbol
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
app = typer.Typer()
CONTEXTS = AppContexts()
def coro(f):
@wraps(f)
def wrapper(*args, **kwargs):
return asyncio.run(f(*args, **kwargs))
return wrapper
@app.command()
@coro
async def summarization_cli(extraction_id: str):
contexts = await CONTEXTS.get_app_contexts(init_nats=False)
summary, translated_summary, decision_number = await extract_and_reformat_summary(
extraction_id=extraction_id,
crawler_db_engine=contexts.crawler_db_engine,
case_db_engine=contexts.case_db_engine,
)
summary_text = sanitize_markdown_symbol(summary)
translated_summary_text = sanitize_markdown_symbol(translated_summary)
await write_summary_to_db(
case_db_engine=contexts.case_db_engine,
decision_number=decision_number,
summary=summary,
summary_text=summary_text,
translated_summary=translated_summary,
translated_summary_text=translated_summary_text,
)
if __name__ == "__main__":
app()