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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -20
main.py CHANGED
@@ -212,6 +212,7 @@ def get_streams():
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,30 +221,17 @@ def get_streams():
220
  do_sample=True,
221
  seed=42,
222
  )
223
-
224
- # Updated prompt to enforce strict JSON output
225
- prompt = """You are a recommendation engine.
226
- List 40+ academic streams like "Artificial Intelligence", "Chemical Engineering", etc.
227
- Output **must be** a valid JSON array **without extra text**:
228
- ["Artificial Intelligence", "Computer Science", "Data Science", "Cyber Security", ...]
229
- No additional formatting, no extra text, just the JSON array.
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
- # Debugging: Print raw API response
237
- print("Raw API Response:", stream)
238
-
239
- # Clean and validate response
240
- try:
241
- stream_cleaned = stream.strip().replace("\n", "").replace("`", "").replace("json", "")
242
- stream_list = json.loads(stream_cleaned) # Convert string to Python list
243
- return jsonify({"ans": stream_list})
244
- except json.JSONDecodeError as e:
245
- print("JSON Decode Error:", e)
246
- return jsonify({"error": "Invalid response format"}), 500
247
 
248
 
249
 
 
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
  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