Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -68,22 +68,27 @@ def get_food_suggestions():
|
|
68 |
if not selected_ingredients:
|
69 |
return jsonify({"error": "No ingredients selected"}), 400
|
70 |
|
71 |
-
#
|
72 |
-
prompt = f"Suggest 3-5 recipe ideas using only the following ingredients: {', '.join(selected_ingredients)}. Provide the recipe names in a numbered list format, ensuring the
|
73 |
|
74 |
try:
|
75 |
response = openai_client.chat.completions.create(
|
76 |
-
model="gpt-3.5-turbo", #
|
77 |
messages=[
|
78 |
-
{"role": "system", "content": "You are a
|
79 |
{"role": "user", "content": prompt}
|
80 |
],
|
81 |
-
max_tokens=
|
82 |
)
|
83 |
suggestions = response.choices[0].message.content.strip().split('\n')
|
84 |
return jsonify({"suggestions": [s.strip() for s in suggestions if s.strip()]})
|
85 |
except Exception as e:
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
if __name__ == '__main__':
|
89 |
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
68 |
if not selected_ingredients:
|
69 |
return jsonify({"error": "No ingredients selected"}), 400
|
70 |
|
71 |
+
# Detailed prompt for tailored recipe generation
|
72 |
+
prompt = f"Suggest 3-5 creative, realistic, and simple recipe ideas using only the following ingredients: {', '.join(selected_ingredients)}. Provide the recipe names in a numbered list format, ensuring each recipe is feasible with the exact ingredients provided and avoids additional ingredients."
|
73 |
|
74 |
try:
|
75 |
response = openai_client.chat.completions.create(
|
76 |
+
model="gpt-3.5-turbo", # Upgrade to "gpt-4" if available
|
77 |
messages=[
|
78 |
+
{"role": "system", "content": "You are a highly skilled chef assistant specializing in creating recipes from a limited set of ingredients."},
|
79 |
{"role": "user", "content": prompt}
|
80 |
],
|
81 |
+
max_tokens=200 # Sufficient for detailed suggestions
|
82 |
)
|
83 |
suggestions = response.choices[0].message.content.strip().split('\n')
|
84 |
return jsonify({"suggestions": [s.strip() for s in suggestions if s.strip()]})
|
85 |
except Exception as e:
|
86 |
+
error_message = str(e)
|
87 |
+
if "429" in error_message or "insufficient_quota" in error_message.lower():
|
88 |
+
return jsonify({
|
89 |
+
"error": f"Failed to get food suggestions: Error code: 429 - You exceeded your current OpenAI quota. Please upgrade your plan at https://platform.openai.com/account/billing or check the documentation at https://platform.openai.com/docs/guides/error-codes/api-errors."
|
90 |
+
}), 429
|
91 |
+
return jsonify({"error": f"Failed to get food suggestions: {error_message}. Please contact support if the issue persists."}), 500
|
92 |
|
93 |
if __name__ == '__main__':
|
94 |
app.run(debug=True, host='0.0.0.0', port=7860)
|