Dharma20 commited on
Commit
ff56a92
·
verified ·
1 Parent(s): 96aa302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -18,27 +18,46 @@ def process_files_into_docs(files, progress=gr.Progress()):
18
  def rag(history, question):
19
  if history is None:
20
  history = []
21
-
22
- messages = [system_message, user_message]
23
  res = conversational_rag.run(
24
- data = {
25
- 'query_rephrase_prompt_builder' : {'query': question},
26
- 'prompt_builder': {'template': messages, 'query': question},
27
- 'memory_joiner': {'values': [ChatMessage.from_user(question)]}
 
 
 
 
 
28
  },
29
- include_outputs_from=['llm', 'query_rephrase_llm']
30
  )
31
-
32
- bot_message = res['llm']['replies'][0].content
33
- streamed_message = ""
34
-
 
 
 
 
 
 
35
  for token in bot_message.split():
36
- streamed_message += f"{token} "
37
- yield history + [(question, streamed_message.strip())], " "
 
 
 
38
  time.sleep(0.05)
39
-
40
- history.append((question, bot_message))
41
- yield history, " "
 
 
 
 
 
42
 
43
  EXAMPLE_FILE = "RAG Survey.pdf"
44
 
 
18
  def rag(history, question):
19
  if history is None:
20
  history = []
21
+
22
+ # Run Haystack pipeline
23
  res = conversational_rag.run(
24
+ data={
25
+ "query_rephrase_prompt_builder": {"query": question},
26
+ "prompt_builder": {
27
+ "template": [system_message, user_message],
28
+ "query": question,
29
+ },
30
+ "memory_joiner": {
31
+ "values": [ChatMessage.from_user(question)]
32
+ }
33
  },
34
+ include_outputs_from=["llm"]
35
  )
36
+
37
+ bot_message = res["llm"]["replies"][0].content
38
+
39
+ # Add user message
40
+ history = history + [
41
+ {"role": "user", "content": question}
42
+ ]
43
+
44
+ # Stream assistant message
45
+ streamed = ""
46
  for token in bot_message.split():
47
+ streamed += token + " "
48
+ yield (
49
+ history + [{"role": "assistant", "content": streamed.strip()}],
50
+ ""
51
+ )
52
  time.sleep(0.05)
53
+
54
+ # Final assistant message
55
+ history = history + [
56
+ {"role": "assistant", "content": bot_message}
57
+ ]
58
+
59
+ yield history, ""
60
+
61
 
62
  EXAMPLE_FILE = "RAG Survey.pdf"
63