Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ if not os.path.exists(path):
|
|
| 10 |
path = "/home/user/app/chromafiles"
|
| 11 |
|
| 12 |
print(path)
|
| 13 |
-
mragdata= pd.read_excel("mragdata.xlsx")
|
| 14 |
client = chromadb.PersistentClient(path=path)
|
| 15 |
print(client.heartbeat())
|
| 16 |
print(client.get_version())
|
|
@@ -158,15 +157,11 @@ def responsefull(
|
|
| 158 |
#return "Bitte spezifiziere deine Frage."
|
| 159 |
if responsecritical(prompt)==False:
|
| 160 |
return "Es scheint so, als sei dies keine Frage, die sich auf Bundestagswahl oder den Wahl-O-Maten bezieht"
|
| 161 |
-
arag=False
|
| 162 |
if selected_option == "Keine These ausgewählt":
|
| 163 |
-
arag=True
|
| 164 |
query_prompt=format_prompt(prompt,history)
|
| 165 |
selected_optionfull = " Die Frage bezieht sich auf keine These speziell und ist somit allgemeiner zu behandeln."
|
| 166 |
else:
|
| 167 |
-
|
| 168 |
-
print(results)
|
| 169 |
-
#query_prompt=selected_option
|
| 170 |
selected_optionfull = " Die Nutzer Frage bezieht sich auf folgende Wahl-O-Mat These: " + selected_option
|
| 171 |
if contains_op(prompt)==True:
|
| 172 |
return "Als KI Assitenz kann ich dich nur beraten, jedoch bleibe ich neutral und werde keine Position einehmen. Frage mich aber gerne etwas anderes zum Wahl-O-Maten."
|
|
@@ -176,22 +171,21 @@ def responsefull(
|
|
| 176 |
|
| 177 |
prompt= prompt + selected_optionfull
|
| 178 |
addon=""
|
| 179 |
-
|
| 180 |
-
results=collection.query(
|
| 181 |
query_texts=[query_prompt],
|
| 182 |
n_results=8,
|
| 183 |
#where={"source": "google-docs"}
|
| 184 |
#where_document={"$contains":"search_string"}
|
| 185 |
)
|
| 186 |
#print("REsults")
|
| 187 |
-
|
| 188 |
#print("_____")
|
| 189 |
-
|
| 190 |
|
| 191 |
#sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
#print(str(prompt)+"\n\n"+str(combination))
|
| 196 |
if(len(results)>1):
|
| 197 |
addon="Bitte berücksichtige bei deiner Antwort folgende Auszüge aus unserer Wahlhilfe 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)
|
|
|
|
| 10 |
path = "/home/user/app/chromafiles"
|
| 11 |
|
| 12 |
print(path)
|
|
|
|
| 13 |
client = chromadb.PersistentClient(path=path)
|
| 14 |
print(client.heartbeat())
|
| 15 |
print(client.get_version())
|
|
|
|
| 157 |
#return "Bitte spezifiziere deine Frage."
|
| 158 |
if responsecritical(prompt)==False:
|
| 159 |
return "Es scheint so, als sei dies keine Frage, die sich auf Bundestagswahl oder den Wahl-O-Maten bezieht"
|
|
|
|
| 160 |
if selected_option == "Keine These ausgewählt":
|
|
|
|
| 161 |
query_prompt=format_prompt(prompt,history)
|
| 162 |
selected_optionfull = " Die Frage bezieht sich auf keine These speziell und ist somit allgemeiner zu behandeln."
|
| 163 |
else:
|
| 164 |
+
query_prompt=selected_option
|
|
|
|
|
|
|
| 165 |
selected_optionfull = " Die Nutzer Frage bezieht sich auf folgende Wahl-O-Mat These: " + selected_option
|
| 166 |
if contains_op(prompt)==True:
|
| 167 |
return "Als KI Assitenz kann ich dich nur beraten, jedoch bleibe ich neutral und werde keine Position einehmen. Frage mich aber gerne etwas anderes zum Wahl-O-Maten."
|
|
|
|
| 171 |
|
| 172 |
prompt= prompt + selected_optionfull
|
| 173 |
addon=""
|
| 174 |
+
results=collection.query(
|
|
|
|
| 175 |
query_texts=[query_prompt],
|
| 176 |
n_results=8,
|
| 177 |
#where={"source": "google-docs"}
|
| 178 |
#where_document={"$contains":"search_string"}
|
| 179 |
)
|
| 180 |
#print("REsults")
|
| 181 |
+
print(results)
|
| 182 |
#print("_____")
|
| 183 |
+
dists=["<br><small>(relevance: "+str(round((1-d)*100)/100)+";" for d in results['distances'][0]]
|
| 184 |
|
| 185 |
#sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
| 186 |
+
results=results['documents'][0]
|
| 187 |
+
combination = zip(results,dists)
|
| 188 |
+
combination = [' '.join(triplets) for triplets in combination]
|
| 189 |
#print(str(prompt)+"\n\n"+str(combination))
|
| 190 |
if(len(results)>1):
|
| 191 |
addon="Bitte berücksichtige bei deiner Antwort folgende Auszüge aus unserer Wahlhilfe 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)
|