Pclanglais commited on
Commit
22b51ff
1 Parent(s): dcbc7a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -69,15 +69,34 @@ class StopOnTokens(StoppingCriteria):
69
 
70
 
71
  def predict(message, history):
72
- text = vector_search(message)
73
- message = message + "\n\n### Source ###\n" + text
74
 
75
- print(message)
 
 
 
76
  history_transformer_format = history + [[message, ""]]
 
 
77
  stop = StopOnTokens()
78
 
79
- messages = "".join(["".join(["<|start_header_id|>user<|end_header_id|>\n\n"+item[0], "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"+item[1]])
80
- for item in history_transformer_format])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  messages = system_prompt + messages
83
 
 
69
 
70
 
71
  def predict(message, history):
 
 
72
 
73
+ #For now, we only query the vector database once, at the start.
74
+ if len(history) == 0:
75
+ source_text = vector_search(message)
76
+
77
  history_transformer_format = history + [[message, ""]]
78
+
79
+ print(history_transformer_format)
80
  stop = StopOnTokens()
81
 
82
+ messages = []
83
+ id_message = 1
84
+ total_message = len(history_transformer_format)
85
+ for item in history_transformer_format:
86
+
87
+ #Once we target the ongoing post we add the source.
88
+ if id_message == total_message:
89
+ question = "<|start_header_id|>user<|end_header_id|>\n\n"+ item[0] + "\n\n### Source ###\n" + source_text
90
+ else:
91
+ question = "<|start_header_id|>user<|end_header_id|>\n\n"+ item[0]
92
+ answer = "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"+item[1]
93
+ result = "".join([question, answer])
94
+ messages.append(result)
95
+ id_message = id_message + 1
96
+
97
+ messages = "".join(messages)
98
+
99
+ print(messages)
100
 
101
  messages = system_prompt + messages
102