mamathew commited on
Commit
d9c8d4f
·
verified ·
1 Parent(s): 6a2c742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -20,7 +20,8 @@ TEXT_MODEL_REPO = os.environ.get("TEXT_MODEL_REPO", "<your-username>/text-ft-foo
20
  CLIP_MODEL_REPO = os.environ.get("CLIP_MODEL_REPO", "<your-username>/clip-ft-food-rag")
21
  DATASET_REPO = os.environ.get("DATASET_REPO", "<your-username>/food-rag-index")
22
  # LLM via Inference API (set HF_TOKEN in Space secrets). Change to your preferred instruct model.
23
- LLM_ID = os.environ.get("LLM_ID", "mistralai/Mistral-7B-Instruct-v0.3")
 
24
  # =================================================
25
 
26
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
@@ -105,11 +106,22 @@ def build_prompt(question: str, ctx: List[Pair]) -> str:
105
  return "\n".join(lines)
106
 
107
  def call_llm(prompt: str) -> str:
 
108
  if client is None:
109
  return "(LLM not configured)\n\n" + prompt
110
  try:
111
- out = client.text_generation(prompt=prompt, max_new_tokens=256, temperature=0.2, do_sample=True)
112
- return out.strip()
 
 
 
 
 
 
 
 
 
 
113
  except Exception as e:
114
  return f"(LLM error: {e})\n\n" + prompt
115
 
 
20
  CLIP_MODEL_REPO = os.environ.get("CLIP_MODEL_REPO", "<your-username>/clip-ft-food-rag")
21
  DATASET_REPO = os.environ.get("DATASET_REPO", "<your-username>/food-rag-index")
22
  # LLM via Inference API (set HF_TOKEN in Space secrets). Change to your preferred instruct model.
23
+ LLM_ID = os.environ.get("LLM_ID", "google/gemma-2-2b-it")
24
+
25
  # =================================================
26
 
27
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
106
  return "\n".join(lines)
107
 
108
  def call_llm(prompt: str) -> str:
109
+ # prompt already includes your Context + Question text
110
  if client is None:
111
  return "(LLM not configured)\n\n" + prompt
112
  try:
113
+ resp = client.chat_completion(
114
+ messages=[
115
+ {"role": "system", "content": (
116
+ "You are a helpful assistant. Use the provided context to answer in Persian language; "
117
+ "if it's not in the context, say you don't know."
118
+ )},
119
+ {"role": "user", "content": prompt},
120
+ ],
121
+ max_tokens=256,
122
+ temperature=0.2,
123
+ )
124
+ return resp.choices[0].message.content.strip()
125
  except Exception as e:
126
  return f"(LLM error: {e})\n\n" + prompt
127