Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,37 +84,44 @@ Important instructions:
|
|
| 84 |
"Entschuldigung. Leider kenne ich die Antwort auf diese Frage nicht."
|
| 85 |
4. If a formula is relevant, show the **exact formula** and explain it in **simple terms**.
|
| 86 |
5. Do not give vague or speculative answers — it's better to skip a question than guess.
|
| 87 |
-
6. **
|
| 88 |
-
7.
|
|
|
|
| 89 |
"""
|
| 90 |
|
| 91 |
-
|
| 92 |
|
| 93 |
Vorlesungsinhalte:
|
| 94 |
{context}
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
Antwort:"""
|
| 99 |
-
|
| 100 |
return prompt
|
| 101 |
|
| 102 |
|
| 103 |
|
|
|
|
| 104 |
def respond(message, history):
|
| 105 |
try:
|
| 106 |
prompt = build_prompt(message)
|
| 107 |
|
| 108 |
payload = {
|
| 109 |
"inputs": prompt,
|
| 110 |
-
"parameters": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
response = requests.post(HF_API_URL, headers=headers, json=payload, timeout=30)
|
| 114 |
response.raise_for_status()
|
| 115 |
output = response.json()
|
| 116 |
generated_text = output[0]["generated_text"]
|
| 117 |
-
match = re.search(r"Answer:(.*)", generated_text, re.DOTALL)
|
| 118 |
answer = generated_text[len(prompt):].strip()
|
| 119 |
|
| 120 |
|
|
|
|
| 84 |
"Entschuldigung. Leider kenne ich die Antwort auf diese Frage nicht."
|
| 85 |
4. If a formula is relevant, show the **exact formula** and explain it in **simple terms**.
|
| 86 |
5. Do not give vague or speculative answers — it's better to skip a question than guess.
|
| 87 |
+
6. **Never generate your own questions. Only respond to the given question.**
|
| 88 |
+
7. **Always respond in German.**
|
| 89 |
+
8. Make your answers clear, fact-based, and well-structured.
|
| 90 |
"""
|
| 91 |
|
| 92 |
+
prompt = f"""{system_instruction}
|
| 93 |
|
| 94 |
Vorlesungsinhalte:
|
| 95 |
{context}
|
| 96 |
|
| 97 |
+
--- Ende der Vorlesungsinhalte ---
|
| 98 |
+
|
| 99 |
+
Frage des Nutzers (bitte nur diese beantworten): {question}
|
| 100 |
|
| 101 |
Antwort:"""
|
| 102 |
+
|
| 103 |
return prompt
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
+
|
| 108 |
def respond(message, history):
|
| 109 |
try:
|
| 110 |
prompt = build_prompt(message)
|
| 111 |
|
| 112 |
payload = {
|
| 113 |
"inputs": prompt,
|
| 114 |
+
"parameters": {
|
| 115 |
+
"temperature": 0.2,
|
| 116 |
+
"max_new_tokens": 400,
|
| 117 |
+
"stop": ["Frage:", "Question:", "User:", "Frage des Nutzers"]
|
| 118 |
+
},
|
| 119 |
}
|
| 120 |
|
| 121 |
response = requests.post(HF_API_URL, headers=headers, json=payload, timeout=30)
|
| 122 |
response.raise_for_status()
|
| 123 |
output = response.json()
|
| 124 |
generated_text = output[0]["generated_text"]
|
|
|
|
| 125 |
answer = generated_text[len(prompt):].strip()
|
| 126 |
|
| 127 |
|