|
7 | 7 | from langchain.llms import CTransformers, HuggingFacePipeline |
8 | 8 | from langchain.vectorstores import Chroma |
9 | 9 | from rich import print |
| 10 | +from rich.markup import escape |
10 | 11 | from rich.panel import Panel |
11 | 12 |
|
12 | 13 | from . import config |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def print_response(text: str) -> None: |
16 | | - print(f"[bright_cyan]{text}[/bright_cyan]", end="", flush=True) |
| 17 | + print(f"[bright_cyan]{escape(text)}", end="", flush=True) |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class StreamingPrintCallbackHandler(StreamingStdOutCallbackHandler): |
@@ -76,26 +77,27 @@ def chat( |
76 | 77 | print("Type your query below and press Enter.") |
77 | 78 | print("Type 'exit' or 'quit' or 'q' to exit the application.\n") |
78 | 79 | while True: |
79 | | - print("[bold]Q:[/bold] ", end="", flush=True) |
| 80 | + print("[bold]Q: ", end="", flush=True) |
80 | 81 | if interactive: |
81 | 82 | query = input() |
82 | 83 | else: |
83 | | - print(query) |
| 84 | + print(escape(query)) |
84 | 85 | print() |
85 | 86 | if query.strip() in ["exit", "quit", "q"]: |
86 | 87 | print("Exiting...\n") |
87 | 88 | break |
88 | | - print("[bold]A:[/bold]", end="", flush=True) |
| 89 | + print("[bold]A:", end="", flush=True) |
89 | 90 |
|
90 | 91 | res = qa(query) |
91 | 92 | if hf: |
92 | 93 | print_response(res["result"]) |
93 | 94 |
|
94 | 95 | print() |
95 | 96 | for doc in res["source_documents"]: |
| 97 | + source, content = doc.metadata["source"], doc.page_content |
96 | 98 | print( |
97 | 99 | Panel( |
98 | | - f"[bright_blue]{doc.metadata['source']}[/bright_blue]\n\n{doc.page_content}" |
| 100 | + f"[bright_blue]{escape(source)}[/bright_blue]\n\n{escape(content)}" |
99 | 101 | ) |
100 | 102 | ) |
101 | 103 | print() |
|
0 commit comments