Skip to content

Commit e0c7b53

Browse files
committed
Escape text when printing
1 parent 83d829b commit e0c7b53

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

chatdocs/chat.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
from langchain.llms import CTransformers, HuggingFacePipeline
88
from langchain.vectorstores import Chroma
99
from rich import print
10+
from rich.markup import escape
1011
from rich.panel import Panel
1112

1213
from . import config
1314

1415

1516
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)
1718

1819

1920
class StreamingPrintCallbackHandler(StreamingStdOutCallbackHandler):
@@ -76,26 +77,27 @@ def chat(
7677
print("Type your query below and press Enter.")
7778
print("Type 'exit' or 'quit' or 'q' to exit the application.\n")
7879
while True:
79-
print("[bold]Q:[/bold] ", end="", flush=True)
80+
print("[bold]Q: ", end="", flush=True)
8081
if interactive:
8182
query = input()
8283
else:
83-
print(query)
84+
print(escape(query))
8485
print()
8586
if query.strip() in ["exit", "quit", "q"]:
8687
print("Exiting...\n")
8788
break
88-
print("[bold]A:[/bold]", end="", flush=True)
89+
print("[bold]A:", end="", flush=True)
8990

9091
res = qa(query)
9192
if hf:
9293
print_response(res["result"])
9394

9495
print()
9596
for doc in res["source_documents"]:
97+
source, content = doc.metadata["source"], doc.page_content
9698
print(
9799
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)}"
99101
)
100102
)
101103
print()

0 commit comments

Comments
 (0)