Swapnil-101 commited on
Commit
7226a4c
·
verified ·
1 Parent(s): 676abcb

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -9
main.py CHANGED
@@ -211,7 +211,6 @@ def get_streams():
211
  top_p = 0.95
212
  repetition_penalty = 1.0
213
 
214
-
215
  generate_kwargs = dict(
216
  temperature=temperature,
217
  max_new_tokens=max_new_tokens,
@@ -220,17 +219,25 @@ def get_streams():
220
  do_sample=True,
221
  seed=42,
222
  )
223
- prompt = f""" prompt:
224
- You need to act like as recommendation engine.
225
- List all 40+ streams/branches in like computer science, chemical engineering, aerospace , etc
226
- Note: Output should be list in below format:
227
- [branch1, branch2, branch3,...]
228
- Return only answer not prompt and unnecessary stuff, also dont add any special characters or punctuation marks
229
- """
230
  formatted_prompt = format_prompt(prompt)
231
 
232
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
233
- return jsonify({"ans": stream})
 
 
 
 
 
 
 
 
234
 
235
 
236
  @app.route('/get_education_profiles', methods=['GET'])
 
211
  top_p = 0.95
212
  repetition_penalty = 1.0
213
 
 
214
  generate_kwargs = dict(
215
  temperature=temperature,
216
  max_new_tokens=max_new_tokens,
 
219
  do_sample=True,
220
  seed=42,
221
  )
222
+
223
+ prompt = """You need to act as a recommendation engine.
224
+ List all 40+ streams/branches in computer science, chemical engineering, aerospace engineering, etc.
225
+ Note: The output should be a valid JSON list in the format:
226
+ ["Artificial Intelligence", "Computer Science", "Data Science", "Cyber Security", ...]
227
+ Return only the list, no additional text, and ensure it is properly formatted as JSON."""
228
+
229
  formatted_prompt = format_prompt(prompt)
230
 
231
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=False, return_full_text=False)
232
+
233
+ # Ensure the response is correctly formatted as a JSON list
234
+ try:
235
+ stream_list = json.loads(stream) # Convert string to list
236
+ except json.JSONDecodeError:
237
+ return jsonify({"error": "Invalid response format"}), 500
238
+
239
+ return jsonify({"ans": stream_list})
240
+
241
 
242
 
243
  @app.route('/get_education_profiles', methods=['GET'])