Spaces:
Sleeping
Update app.py
Browse filesdef generate_answer(question, context):
"""Generate an answer using IBM Granite."""
if context:
prompt = (
"You are a helpful assistant answering questions strictly from the provided context.\n"
"If the answer is not in the context, say you don't know.\n\n"
f"Context:\n{context}\n\n"
f"Question: {question}\nAnswer:"
)
else:
prompt = (
"You are a helpful assistant. The user asked a question but no document context is available.\n\n"
f"Question: {question}\nAnswer:"
)
response = llm.text_generation(
prompt=prompt,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
repetition_penalty=1.05,
)
return response.strip()
|
@@ -101,17 +101,15 @@ def generate_answer(question, context):
|
|
| 101 |
f"Question: {question}\nAnswer:"
|
| 102 |
)
|
| 103 |
|
| 104 |
-
response = llm.
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
{"role": "user", "content": prompt}
|
| 108 |
-
],
|
| 109 |
-
max_tokens=512,
|
| 110 |
temperature=0.2,
|
| 111 |
top_p=0.9,
|
|
|
|
| 112 |
)
|
| 113 |
|
| 114 |
-
return response.
|
| 115 |
|
| 116 |
|
| 117 |
# ============================================================
|
|
|
|
| 101 |
f"Question: {question}\nAnswer:"
|
| 102 |
)
|
| 103 |
|
| 104 |
+
response = llm.text_generation(
|
| 105 |
+
prompt=prompt,
|
| 106 |
+
max_new_tokens=512,
|
|
|
|
|
|
|
|
|
|
| 107 |
temperature=0.2,
|
| 108 |
top_p=0.9,
|
| 109 |
+
repetition_penalty=1.05,
|
| 110 |
)
|
| 111 |
|
| 112 |
+
return response.strip()
|
| 113 |
|
| 114 |
|
| 115 |
# ============================================================
|