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

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.post(
"/generate",
json={
"model": GRANITE_MODEL,
"inputs": prompt,
"parameters": {
"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 +13 -8
app.py CHANGED
@@ -87,7 +87,6 @@ def retrieve_context(question, state, k=4):
87
  # ============================================================
88
 
89
  def generate_answer(question, context):
90
- """Generate an answer using IBM Granite."""
91
  if context:
92
  prompt = (
93
  "You are a helpful assistant answering questions strictly from the provided context.\n"
@@ -101,15 +100,21 @@ def generate_answer(question, context):
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
  # ============================================================
 
87
  # ============================================================
88
 
89
  def generate_answer(question, context):
 
90
  if context:
91
  prompt = (
92
  "You are a helpful assistant answering questions strictly from the provided context.\n"
 
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
  # ============================================================