Julien Simon commited on
Commit
6ef1bb3
Β·
1 Parent(s): 7efc364

Add streaming for vanilla answer

Browse files
Files changed (1) hide show
  1. demo.py +10 -6
demo.py CHANGED
@@ -18,7 +18,8 @@ import time
18
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
19
  OPENAI_URL = "https://conductor.arcee.ai/v1"
20
  OPENAI_MODEL = "auto"
21
- CHROMA_PATH = "/data/vectorstore"
 
22
  PDF_PATH = "pdf"
23
 
24
 
@@ -237,15 +238,18 @@ def get_rag_response(qa_chain, query, chat_history):
237
  print("\n=== RAG Response ===")
238
 
239
  try:
 
240
  result = qa_chain.invoke({"question": query, "chat_history": chat_history})
241
-
242
- # Print answer with streaming
243
  print("\nAnswer: ", end="", flush=True)
244
- for chunk in result["answer"]:
245
- print(chunk, end="", flush=True)
 
 
246
  print()
247
 
248
- # Print unique sources
249
  if result.get("source_documents"):
250
  print("\nSources:")
251
  seen_sources = set()
 
18
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
19
  OPENAI_URL = "https://conductor.arcee.ai/v1"
20
  OPENAI_MODEL = "auto"
21
+ CHROMA_PATH = "vectorstore"
22
+ #CHROMA_PATH = "/data/vectorstore"
23
  PDF_PATH = "pdf"
24
 
25
 
 
238
  print("\n=== RAG Response ===")
239
 
240
  try:
241
+ # First get the result to ensure we have the answer and sources
242
  result = qa_chain.invoke({"question": query, "chat_history": chat_history})
243
+
244
+ # Print the answer with character-by-character "streaming" simulation
245
  print("\nAnswer: ", end="", flush=True)
246
+ answer = result.get("answer", "No answer found.")
247
+ for char in answer:
248
+ print(char, end="", flush=True)
249
+ time.sleep(0.005) # Small delay to simulate streaming
250
  print()
251
 
252
+ # Print sources
253
  if result.get("source_documents"):
254
  print("\nSources:")
255
  seen_sources = set()