-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (47 loc) · 1.75 KB
/
app.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
52
53
54
55
56
57
58
59
import asyncio
from rich.console import Console
from rich.markdown import Markdown
from rich.progress import Progress, SpinnerColumn, TextColumn
from tracking.check_state import check_files_state
from query_handler import query_with_llm
console = Console()
async def main():
progress = Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console,
transient=True
)
try:
with progress:
task = progress.add_task("Checking file states & updating embeddings...", total=None)
await asyncio.to_thread(check_files_state)
progress.remove_task(task)
except Exception as e:
console.print(f"\n[bold red]Error during file checking/processing:[/bold red] {e}")
return
try:
query = console.input("[bold blue]Enter your query: [/bold blue]")
if not query.strip():
return
response_content = ""
referenced_ids = None
with console.status("[bold cyan]Searching documents and asking the LLM...", spinner="dots"):
response_content, referenced_ids = query_with_llm(query)
if referenced_ids:
console.print("\n[bold yellow]Referencing documents:[/bold yellow]")
for doc_id in referenced_ids:
console.print(f"- [dim]{doc_id}[/dim]")
console.print()
if response_content:
response_md = Markdown(response_content)
console.print(response_md)
except KeyboardInterrupt:
pass
except Exception as e:
console.print(f"\n[bold red]Error during query processing:[/bold red] {e}")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass