KalooAI commited on
Commit
2267dfe
·
verified ·
1 Parent(s): fdefd9e

Update app.py

Browse files

def 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()

Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -101,17 +101,15 @@ def generate_answer(question, context):
101
  f"Question: {question}\nAnswer:"
102
  )
103
 
104
- response = llm.chat.completions.create(
105
- model=GRANITE_MODEL,
106
- messages=[
107
- {"role": "user", "content": prompt}
108
- ],
109
- max_tokens=512,
110
  temperature=0.2,
111
  top_p=0.9,
 
112
  )
113
 
114
- return response.choices[0].message["content"].strip()
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
  # ============================================================