Spaces:
Runtime error
Runtime error
Julien Simon commited on
Commit Β·
6ef1bb3
1
Parent(s): 7efc364
Add streaming for vanilla answer
Browse files17 unmodified lines18192021222324212 unmodified lines23723823924024124224324424524624724824925025117 unmodified linesOPENAI_API_KEY = os.getenv("OPENAI_API_KEY")OPENAI_URL = "https://conductor.arcee.ai/v1"OPENAI_MODEL = "auto"CHROMA_PATH = "/data/vectorstore"PDF_PATH = "pdf"212 unmodified linesprint("\n=== RAG Response ===")try:result = qa_chain.invoke({"question": query, "chat_history": chat_history})# Print answer with streamingprint("\nAnswer: ", end="", flush=True)for chunk in result["answer"]:print(chunk, end="", flush=True)print()# Print unique sourcesif result.get("source_documents"):print("\nSources:")seen_sources = set()17 unmodified lines1819202122232425212 unmodified lines23823924024124224324424524624724824925025125225325425517 unmodified linesOPENAI_API_KEY = os.getenv("OPENAI_API_KEY")OPENAI_URL = "https://conductor.arcee.ai/v1"OPENAI_MODEL = "auto"CHROMA_PATH = "vectorstore"#CHROMA_PATH = "/data/vectorstore"PDF_PATH = "pdf"212 unmodified linesprint("\n=== RAG Response ===")try:# First get the result to ensure we have the answer and sourcesresult = qa_chain.invoke({"question": query, "chat_history": chat_history})# Print the answer with character-by-character "streaming" simulationprint("\nAnswer: ", end="", flush=True)answer = result.get("answer", "No answer found.")for char in answer:print(char, end="", flush=True)time.sleep(0.005) # Small delay to simulate streamingprint()# Print sourcesif result.get("source_documents"):print("\nSources:")seen_sources = set()
demo.py+10-6