KalooAI commited on
Commit
5d619fa
·
verified ·
1 Parent(s): ac80f0f

Update app.py

Browse files

def generate_answer(question, context):
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.generate(
prompt,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
repetition_penalty=1.05,
)

return response.generated_text.strip()

Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -100,21 +100,15 @@ def generate_answer(question, context):
100
  f"Question: {question}\nAnswer:"
101
  )
102
 
103
- response = llm.post(
104
- "/generate",
105
- json={
106
- "model": GRANITE_MODEL,
107
- "inputs": prompt,
108
- "parameters": {
109
- "max_new_tokens": 512,
110
- "temperature": 0.2,
111
- "top_p": 0.9,
112
- "repetition_penalty": 1.05,
113
- },
114
- },
115
  )
116
 
117
- return response["generated_text"].strip()
118
 
119
 
120
  # ============================================================
 
100
  f"Question: {question}\nAnswer:"
101
  )
102
 
103
+ response = llm.generate(
104
+ prompt,
105
+ max_new_tokens=512,
106
+ temperature=0.2,
107
+ top_p=0.9,
108
+ repetition_penalty=1.05,
 
 
 
 
 
 
109
  )
110
 
111
+ return response.generated_text.strip()
112
 
113
 
114
  # ============================================================