Spaces:
Sleeping
Sleeping
Commit
·
04f37d5
1
Parent(s):
356d480
Update sourcey in run.py
Browse files
run.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
# Title: Gradio Interface to LLM-chatbot with RAG-funcionality and ChromaDB on premises
|
3 |
# Author: Andreas Fischer
|
4 |
# Date: October 15th, 2023
|
5 |
-
# Last update: December
|
6 |
##########################################################################################
|
7 |
|
8 |
|
@@ -93,13 +93,17 @@ def response(message, history):
|
|
93 |
#where={"source": "google-docs"}
|
94 |
#where_document={"$contains":"search_string"}
|
95 |
)
|
|
|
|
|
96 |
results=results['documents'][0]
|
97 |
-
|
|
|
|
|
98 |
if(len(results)>1):
|
99 |
addon=" Bitte berücksichtige bei deiner Antwort ggf. folgende Auszüge aus unserer Datenbank, sofern sie für die Antwort erforderlich sind. Beantworte die Frage knapp und präzise. Ignoriere unpassende Datenbank-Auszüge OHNE sie zu kommentieren, zu erwähnen oder aufzulisten:\n"+"\n".join(results)
|
100 |
#url="https://afischer1985-wizardlm-13b-v1-2-q4-0-gguf.hf.space/v1/completions"
|
101 |
url="http://localhost:2600/v1/completions"
|
102 |
-
system="Du bist ein KI-basiertes Assistenzsystem."+addon+"\n\nUser-Anliegen:"
|
103 |
#body={"prompt":system+"### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"} #e.g. SauerkrautLM
|
104 |
body={"prompt":"[INST]"+system+"\n"+message+"[/INST]","max_tokens":500, "echo":"False","stream":"True"} #e.g. Mixtral-Instruct
|
105 |
response=""
|
@@ -130,7 +134,7 @@ def response(message, history):
|
|
130 |
print("Exception:"+str(e))
|
131 |
pass
|
132 |
yield response
|
133 |
-
yield response+"\n\n<br><strong>Sources
|
134 |
|
135 |
gr.ChatInterface(response, chatbot=gr.Chatbot(render_markdown=True)).queue().launch(share=True) #False, server_name="0.0.0.0", server_port=7864)
|
136 |
print("Interface up and running!")
|
|
|
2 |
# Title: Gradio Interface to LLM-chatbot with RAG-funcionality and ChromaDB on premises
|
3 |
# Author: Andreas Fischer
|
4 |
# Date: October 15th, 2023
|
5 |
+
# Last update: December 28th, 2023
|
6 |
##########################################################################################
|
7 |
|
8 |
|
|
|
93 |
#where={"source": "google-docs"}
|
94 |
#where_document={"$contains":"search_string"}
|
95 |
)
|
96 |
+
dists=["<small>(relevance: "+str(round(d*100)/100)+";" for d in results['distances'][0]]
|
97 |
+
sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
98 |
results=results['documents'][0]
|
99 |
+
combination = zip(results,dists,sources)
|
100 |
+
combination = [' '.join(triplets) for triplets in combination]
|
101 |
+
print(combination)
|
102 |
if(len(results)>1):
|
103 |
addon=" Bitte berücksichtige bei deiner Antwort ggf. folgende Auszüge aus unserer Datenbank, sofern sie für die Antwort erforderlich sind. Beantworte die Frage knapp und präzise. Ignoriere unpassende Datenbank-Auszüge OHNE sie zu kommentieren, zu erwähnen oder aufzulisten:\n"+"\n".join(results)
|
104 |
#url="https://afischer1985-wizardlm-13b-v1-2-q4-0-gguf.hf.space/v1/completions"
|
105 |
url="http://localhost:2600/v1/completions"
|
106 |
+
system="Du bist ein KI-basiertes Assistenzsystem."+addon+"\n\nUser-Anliegen:"
|
107 |
#body={"prompt":system+"### Instruktion:\n"+message+"\n\n### Antwort:","max_tokens":500, "echo":"False","stream":"True"} #e.g. SauerkrautLM
|
108 |
body={"prompt":"[INST]"+system+"\n"+message+"[/INST]","max_tokens":500, "echo":"False","stream":"True"} #e.g. Mixtral-Instruct
|
109 |
response=""
|
|
|
134 |
print("Exception:"+str(e))
|
135 |
pass
|
136 |
yield response
|
137 |
+
yield response+"\n\n<br><details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
138 |
|
139 |
gr.ChatInterface(response, chatbot=gr.Chatbot(render_markdown=True)).queue().launch(share=True) #False, server_name="0.0.0.0", server_port=7864)
|
140 |
print("Interface up and running!")
|