Swapnil-101 commited on
Commit
ebcdc0f
·
verified ·
1 Parent(s): 54bd033

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -8
main.py CHANGED
@@ -212,7 +212,6 @@ def get_streams():
212
  top_p = 0.95
213
  repetition_penalty = 1.0
214
 
215
-
216
  generate_kwargs = dict(
217
  temperature=temperature,
218
  max_new_tokens=max_new_tokens,
@@ -221,17 +220,30 @@ def get_streams():
221
  do_sample=True,
222
  seed=42,
223
  )
224
- prompt = f""" prompt:
225
- You need to act like as recommendation engine.
226
- List all 40+ streams/branches in like computer science, chemical engineering, aerospace , etc
227
- Note: Output should be list in below format:
228
- [branch1, branch2, branch3,...]
229
- Return only answer not prompt and unnecessary stuff, also dont add any special characters or punctuation marks
 
230
  """
 
231
  formatted_prompt = format_prompt(prompt)
232
 
233
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
234
- return jsonify({"ans": stream})
 
 
 
 
 
 
 
 
 
 
 
235
 
236
 
237
 
 
212
  top_p = 0.95
213
  repetition_penalty = 1.0
214
 
 
215
  generate_kwargs = dict(
216
  temperature=temperature,
217
  max_new_tokens=max_new_tokens,
 
220
  do_sample=True,
221
  seed=42,
222
  )
223
+
224
+ prompt = """
225
+ You need to act as a recommendation engine.
226
+ List all 40+ streams/branches like Computer Science, Chemical Engineering, Aerospace, etc.
227
+ Note: Output should be a **valid JSON list**:
228
+ ["branch1", "branch2", "branch3", ...]
229
+ Return only the list, **do not return text or explanations**.
230
  """
231
+
232
  formatted_prompt = format_prompt(prompt)
233
 
234
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
235
+
236
+ try:
237
+ # Ensure output is valid JSON
238
+ cleaned_data = stream.strip()
239
+ if not cleaned_data.startswith("["):
240
+ raise ValueError("Invalid response format")
241
+
242
+ parsed_data = json.loads(cleaned_data)
243
+ return jsonify({"ans": parsed_data}) # Send as proper JSON
244
+ except Exception as e:
245
+ return jsonify({"error": "Invalid response format", "details": str(e)})
246
+
247
 
248
 
249