AFischer1985
commited on
Commit
•
c980cad
1
Parent(s):
98a436b
Update run.py
Browse files
run.py
CHANGED
@@ -187,9 +187,10 @@ def response(
|
|
187 |
message, history, temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0,
|
188 |
):
|
189 |
addon=""
|
190 |
-
first_message = history[0][0] if history else message
|
|
|
191 |
results=collection.query(
|
192 |
-
query_texts=[
|
193 |
n_results=2,
|
194 |
#where={"source": "google-docs"}
|
195 |
#where_document={"$contains":"search_string"}
|
@@ -205,14 +206,14 @@ def response(
|
|
205 |
system="Du bist ein deutschsprachiges KI-basiertes Assistenzsystem, das zu jedem Anliegen möglichst geeignete KI-Tools empfiehlt." #+addon #+"\n\nUser-Anliegen:"
|
206 |
#body={"prompt":system+"### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"} #e.g. SauerkrautLM
|
207 |
#formatted_prompt = extend_prompt(system+"\n"+prompt, None) #history)
|
208 |
-
removeHTML=
|
209 |
prompt=extend_prompt(
|
210 |
message, # current message of the user
|
211 |
history, # complete history
|
212 |
system, # system prompt
|
213 |
addon, # RAG-component added to the system prompt
|
214 |
None, # fictive first words of the AI (neither displayed nor stored)
|
215 |
-
historylimit=
|
216 |
removeHTML=removeHTML # remove HTML-components from History (to prevent bugs with Markdown)
|
217 |
)
|
218 |
|
@@ -245,7 +246,7 @@ def response(
|
|
245 |
response += part
|
246 |
if removeHTML==True: response = re.sub("<(.*?)>","\n", response) # remove HTML-components in general (may cause bugs with markdown-rendering)
|
247 |
yield response
|
248 |
-
if(len(history)==0):
|
249 |
response=response+"\n\n<details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
250 |
yield response
|
251 |
|
@@ -283,7 +284,7 @@ def response(
|
|
283 |
pass
|
284 |
if removeHTML==True: response = re.sub("<(.*?)>","\n", response) # remove HTML-components in general (may cause bugs with markdown-rendering)
|
285 |
yield response
|
286 |
-
if(len(history)==0):
|
287 |
response=response+"\n\n<details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
288 |
yield response
|
289 |
#history.append((message, response)) # add current dialog to history
|
|
|
187 |
message, history, temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0,
|
188 |
):
|
189 |
addon=""
|
190 |
+
first_message = history[0][0] if history else message
|
191 |
+
last_message = history[-1][0] if history else message # RAG based on last user-message
|
192 |
results=collection.query(
|
193 |
+
query_texts=[last_message],
|
194 |
n_results=2,
|
195 |
#where={"source": "google-docs"}
|
196 |
#where_document={"$contains":"search_string"}
|
|
|
206 |
system="Du bist ein deutschsprachiges KI-basiertes Assistenzsystem, das zu jedem Anliegen möglichst geeignete KI-Tools empfiehlt." #+addon #+"\n\nUser-Anliegen:"
|
207 |
#body={"prompt":system+"### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"} #e.g. SauerkrautLM
|
208 |
#formatted_prompt = extend_prompt(system+"\n"+prompt, None) #history)
|
209 |
+
removeHTML=True
|
210 |
prompt=extend_prompt(
|
211 |
message, # current message of the user
|
212 |
history, # complete history
|
213 |
system, # system prompt
|
214 |
addon, # RAG-component added to the system prompt
|
215 |
None, # fictive first words of the AI (neither displayed nor stored)
|
216 |
+
historylimit=2, # number of past messages to consider for response to current message
|
217 |
removeHTML=removeHTML # remove HTML-components from History (to prevent bugs with Markdown)
|
218 |
)
|
219 |
|
|
|
246 |
response += part
|
247 |
if removeHTML==True: response = re.sub("<(.*?)>","\n", response) # remove HTML-components in general (may cause bugs with markdown-rendering)
|
248 |
yield response
|
249 |
+
if(True): #len(history)==0):
|
250 |
response=response+"\n\n<details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
251 |
yield response
|
252 |
|
|
|
284 |
pass
|
285 |
if removeHTML==True: response = re.sub("<(.*?)>","\n", response) # remove HTML-components in general (may cause bugs with markdown-rendering)
|
286 |
yield response
|
287 |
+
if(True): #len(history)==0):
|
288 |
response=response+"\n\n<details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
289 |
yield response
|
290 |
#history.append((message, response)) # add current dialog to history
|