nagasurendra commited on
Commit
50ffddd
·
verified ·
1 Parent(s): f4f01e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -83,26 +83,25 @@ def get_dish_suggestions():
83
  selected_ingredients = request.json.get('ingredients', [])
84
  if not selected_ingredients:
85
  return jsonify({'error': 'No ingredients selected'}), 400
86
-
87
  ingredients_text = ', '.join([ingredient['name'] for ingredient in selected_ingredients])
88
  prompt = f"Suggest a recipe based on the following ingredients: {ingredients_text}"
89
 
90
  try:
91
- # Request a response from the OpenAI API (ChatGPT)
92
  response = openai.Completion.create(
93
- model="gpt-4", # or use another version (e.g., 'gpt-3.5-turbo')
94
  prompt=prompt,
95
- max_tokens=100, # Limit the response length
96
- n=1, # Number of responses
97
- stop=None, # Optional: define where the response should stop
98
- temperature=0.7 # Control the creativity of the response
99
  )
100
-
101
- dish_suggestions = response.choices[0].text.strip() # Get the suggested dishes
102
  return jsonify({"suggestions": dish_suggestions})
103
-
 
104
  except Exception as e:
105
- return jsonify({"error": f"Error generating suggestions: {str(e)}"}), 500
106
 
107
 
108
 
 
83
  selected_ingredients = request.json.get('ingredients', [])
84
  if not selected_ingredients:
85
  return jsonify({'error': 'No ingredients selected'}), 400
86
+
87
  ingredients_text = ', '.join([ingredient['name'] for ingredient in selected_ingredients])
88
  prompt = f"Suggest a recipe based on the following ingredients: {ingredients_text}"
89
 
90
  try:
 
91
  response = openai.Completion.create(
92
+ model="gpt-4", # Ensure you're using the correct model
93
  prompt=prompt,
94
+ max_tokens=100,
95
+ n=1,
96
+ stop=None,
97
+ temperature=0.7
98
  )
99
+ dish_suggestions = response.choices[0].text.strip()
 
100
  return jsonify({"suggestions": dish_suggestions})
101
+ except openai.error.OpenAIError as e:
102
+ return jsonify({"error": f"OpenAI API error: {str(e)}"}), 500
103
  except Exception as e:
104
+ return jsonify({"error": f"Unexpected error: {str(e)}"}), 500
105
 
106
 
107