Update app.py
Browse files
app.py
CHANGED
|
@@ -30,9 +30,7 @@ def format_prompt(message, history):
|
|
| 30 |
prompt += f"[INST] {message} [/INST]"
|
| 31 |
return prompt
|
| 32 |
|
| 33 |
-
def response(
|
| 34 |
-
prompt, history,selected_option,temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0,
|
| 35 |
-
):
|
| 36 |
temperature = float(temperature)
|
| 37 |
if temperature < 1e-2: temperature = 1e-2
|
| 38 |
top_p = float(top_p)
|
|
@@ -44,37 +42,26 @@ def response(
|
|
| 44 |
do_sample=True,
|
| 45 |
seed=42,
|
| 46 |
)
|
| 47 |
-
addon=""
|
| 48 |
-
results=collection.query(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#where={"source": "google-docs"}
|
| 52 |
-
#where_document={"$contains":"search_string"}
|
| 53 |
)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
dists=["<br><small>(relevance: "+str(round((1-d)*100)/100)+";" for d in results['distances'][0]]
|
| 58 |
-
|
| 59 |
-
#sources=["source: "+s["source"]+")</small>" for s in results['metadatas'][0]]
|
| 60 |
-
results=results['documents'][0]
|
| 61 |
-
print("TEst")
|
| 62 |
-
print(results)
|
| 63 |
-
print("_____")
|
| 64 |
-
combination = zip(results,dists)
|
| 65 |
combination = [' '.join(triplets) for triplets in combination]
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
system="Du heißt Avah und bist ein deutschsprachiges KI-basiertes Wahlhilfe Beratungssystem zum Wahl-O-Maten für die Bundestagswahl 2021. DU nimmst selber in keinem Fall eigen politische Postionen ein!"+addon+"\n\nUser-Anliegen:"
|
| 70 |
formatted_prompt = format_prompt(system + "\n" + selected_option + "\n" + prompt, history)
|
| 71 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 72 |
output = ""
|
| 73 |
for response in stream:
|
| 74 |
output += response.token.text
|
| 75 |
yield output
|
| 76 |
-
#output=output+"\n\n<br><details open><summary><strong>Sources</strong></summary><br><ul>"+ "".join(["<li>" + s + "</li>" for s in combination])+"</ul></details>"
|
| 77 |
yield output
|
|
|
|
| 78 |
|
| 79 |
def update_prompt(selected_option, history):
|
| 80 |
if selected_option=="Keine These ausgewählt":
|
|
|
|
| 30 |
prompt += f"[INST] {message} [/INST]"
|
| 31 |
return prompt
|
| 32 |
|
| 33 |
+
def response(prompt, history, selected_option, temperature=0.9, max_new_tokens=500, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
|
|
| 34 |
temperature = float(temperature)
|
| 35 |
if temperature < 1e-2: temperature = 1e-2
|
| 36 |
top_p = float(top_p)
|
|
|
|
| 42 |
do_sample=True,
|
| 43 |
seed=42,
|
| 44 |
)
|
| 45 |
+
addon = ""
|
| 46 |
+
results = collection.query(
|
| 47 |
+
query_texts=[prompt],
|
| 48 |
+
n_results=60,
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
+
dists = ["<br><small>(relevance: " + str(round((1 - d) * 100) / 100) + ";" for d in results['distances'][0]]
|
| 51 |
+
results = results['documents'][0]
|
| 52 |
+
combination = zip(results, dists)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
combination = [' '.join(triplets) for triplets in combination]
|
| 54 |
+
if len(results) > 1:
|
| 55 |
+
addon = " Bitte berücksichtige bei deiner Antwort ausschießlich 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)
|
| 56 |
+
system = "Du heißt Avah und bist ein deutschsprachiges KI-basiertes Wahlhilfe Beratungssystem zum Wahl-O-Maten für die Bundestagswahl 2021. Du nimmst selber keine eigene politische Postion ein!" + addon + "\n\nUser-Anliegen:"
|
|
|
|
| 57 |
formatted_prompt = format_prompt(system + "\n" + selected_option + "\n" + prompt, history)
|
| 58 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 59 |
output = ""
|
| 60 |
for response in stream:
|
| 61 |
output += response.token.text
|
| 62 |
yield output
|
|
|
|
| 63 |
yield output
|
| 64 |
+
|
| 65 |
|
| 66 |
def update_prompt(selected_option, history):
|
| 67 |
if selected_option=="Keine These ausgewählt":
|