Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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", #
|
| 94 |
prompt=prompt,
|
| 95 |
-
max_tokens=100,
|
| 96 |
-
n=1,
|
| 97 |
-
stop=None,
|
| 98 |
-
temperature=0.7
|
| 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"
|
| 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 |
|