Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -183,14 +183,14 @@ def generate_session_key():
|
|
183 |
def answer_generator(formated_input, session_id):
|
184 |
# QA system prompt and chain
|
185 |
qa_system_prompt = """
|
186 |
-
You are an AI assistant developed by Nutrigenics AI, specializing in intelligent recipe information retrieval and recipe suggestions. Your purpose is to help users by recommending recipes, providing detailed nutritional values, listing ingredients, offering step-by-step cooking instructions, and filtering recipes based on
|
187 |
Operational Guidelines:
|
188 |
1. Input Structure:
|
189 |
- Context: You may receive contextual information related to recipes, such as specific data sets, user preferences, dietary restrictions, or previously selected dishes.
|
190 |
- User Query: Users will pose questions or requests related to recipes, nutritional information, ingredient substitutions, cooking instructions, and more.
|
191 |
2. Response Strategy:
|
192 |
- Utilize Provided Context: If the context contains relevant information that addresses the user's query, base your response on this provided data to ensure accuracy and relevance.
|
193 |
-
- Respond to User Query Directly: If the context does not contain the necessary information to answer the user's query, kindly state that you do not have
|
194 |
Core Functionalities:
|
195 |
- Nutritional Information: Accurately provide nutritional values for each recipe, including calories, macronutrients (proteins, fats, carbohydrates), and essential vitamins and minerals, using contextual data when available.
|
196 |
- Ingredient Details: List all ingredients required for recipes, including substitute options for dietary restrictions or ingredient availability, utilizing context when relevant.
|
@@ -198,10 +198,11 @@ def answer_generator(formated_input, session_id):
|
|
198 |
- Recipe Recommendations: Suggest dishes based on user preferences, dietary restrictions, available ingredients, and contextual data if provided.
|
199 |
Additional Instructions:
|
200 |
- Precision and Personalization: Always aim to provide precise, personalized, and relevant information to users based on both the provided context and their specific queries.
|
201 |
-
- Clarity and Coherence: Ensure
|
202 |
-
- Substitute Suggestions:
|
203 |
- Dynamic Adaptation: Adapt your responses dynamically based on whether the context is relevant to the user's current request, ensuring optimal use of available information.
|
204 |
-
Don't mention about context in the response, format the answer in a natural and friendly way.
|
|
|
205 |
Context:
|
206 |
{context}
|
207 |
"""
|
@@ -237,8 +238,8 @@ def router_node(query):
|
|
237 |
# Prompt
|
238 |
router_instructions = """You are an expert at determining the appropriate task for a user’s question based on chat history and the current query context. You have two available tasks:
|
239 |
|
240 |
-
1. Retrieval: Fetch information based on user's chat history and current query.
|
241 |
-
2. Recommendation/Suggestion: Recommend recipes
|
242 |
|
243 |
Return a JSON response with a single key named “task” indicating either “retrieval” or “recommendation” based on your decision.
|
244 |
"""
|
@@ -263,14 +264,14 @@ def recommendation_node(query):
|
|
263 |
"recipe_time": integer,
|
264 |
"recipe_yields": string,
|
265 |
"recipe_ingredients": list of ingredients,
|
266 |
-
"recipe_instructions": list of
|
267 |
"recipe_image": string,
|
268 |
"blogger": string,
|
269 |
-
"recipe_nutrients": JSON object with key
|
270 |
-
"tags": list of tags related to recipe
|
271 |
} \n
|
272 |
|
273 |
-
Here is the example of
|
274 |
{
|
275 |
"recipe_name": "Asian Potato Salad with Seven Minute Egg",
|
276 |
"recipe_time": 0,
|
@@ -320,19 +321,19 @@ def recommendation_node(query):
|
|
320 |
]
|
321 |
} \n
|
322 |
|
323 |
-
Based on the user query, provide a Python function to filter the JSON data. The output of the function should be a list of
|
324 |
|
325 |
Recipe filtering instructions:
|
326 |
-
- If a user asked for the highest nutrient recipe such as "high protein or high calories" then filtered recipes should be the top highest recipes from all the recipes with high
|
327 |
-
- sort or rearrange recipes based which recipes are more appropriate for the user.
|
328 |
|
329 |
Your output instructions:
|
330 |
-
- The function name should be filter_recipes. The input to the function should be file name.
|
331 |
- The length of output recipes should not be more than 6.
|
332 |
-
- Only give me output function. Do not call the function.
|
333 |
-
- Give the
|
334 |
-
- Do not include any other text with the output, only give
|
335 |
-
- If you do not follow the above
|
336 |
"""
|
337 |
max_tries = 3
|
338 |
while True:
|
@@ -420,7 +421,8 @@ def get_answer(image=[], message='', sessionID='abc123'):
|
|
420 |
response = recommendation_node(message)
|
421 |
if not response:
|
422 |
response = {'content':"An error occurred while processing your request."}
|
423 |
-
|
|
|
424 |
else:
|
425 |
formated_input = {
|
426 |
'input': message,
|
|
|
183 |
def answer_generator(formated_input, session_id):
|
184 |
# QA system prompt and chain
|
185 |
qa_system_prompt = """
|
186 |
+
You are an AI assistant developed by Nutrigenics AI, specializing in intelligent recipe information retrieval and recipe suggestions. Your purpose is to help users by recommending recipes, providing detailed nutritional values, listing ingredients, offering step-by-step cooking instructions, and filtering recipes based on context and user queries.
|
187 |
Operational Guidelines:
|
188 |
1. Input Structure:
|
189 |
- Context: You may receive contextual information related to recipes, such as specific data sets, user preferences, dietary restrictions, or previously selected dishes.
|
190 |
- User Query: Users will pose questions or requests related to recipes, nutritional information, ingredient substitutions, cooking instructions, and more.
|
191 |
2. Response Strategy:
|
192 |
- Utilize Provided Context: If the context contains relevant information that addresses the user's query, base your response on this provided data to ensure accuracy and relevance.
|
193 |
+
- Respond to User Query Directly: If the context does not contain the necessary information to answer the user's query, kindly state that you do not have the required information.
|
194 |
Core Functionalities:
|
195 |
- Nutritional Information: Accurately provide nutritional values for each recipe, including calories, macronutrients (proteins, fats, carbohydrates), and essential vitamins and minerals, using contextual data when available.
|
196 |
- Ingredient Details: List all ingredients required for recipes, including substitute options for dietary restrictions or ingredient availability, utilizing context when relevant.
|
|
|
198 |
- Recipe Recommendations: Suggest dishes based on user preferences, dietary restrictions, available ingredients, and contextual data if provided.
|
199 |
Additional Instructions:
|
200 |
- Precision and Personalization: Always aim to provide precise, personalized, and relevant information to users based on both the provided context and their specific queries.
|
201 |
+
- Clarity and Coherence: Ensure all responses are clear, well-structured, and easy to understand, facilitating a seamless user experience.
|
202 |
+
- Substitute Suggestions: Consider user preferences and dietary restrictions outlined in the context or user query when suggesting ingredient substitutes.
|
203 |
- Dynamic Adaptation: Adapt your responses dynamically based on whether the context is relevant to the user's current request, ensuring optimal use of available information.
|
204 |
+
- Don't mention about the context in the response, format the answer in a natural and friendly way.
|
205 |
+
|
206 |
Context:
|
207 |
{context}
|
208 |
"""
|
|
|
238 |
# Prompt
|
239 |
router_instructions = """You are an expert at determining the appropriate task for a user’s question based on chat history and the current query context. You have two available tasks:
|
240 |
|
241 |
+
1. Retrieval: Fetch information based on the user's chat history and current query.
|
242 |
+
2. Recommendation/Suggestion: Recommend user recipes based on the query.
|
243 |
|
244 |
Return a JSON response with a single key named “task” indicating either “retrieval” or “recommendation” based on your decision.
|
245 |
"""
|
|
|
264 |
"recipe_time": integer,
|
265 |
"recipe_yields": string,
|
266 |
"recipe_ingredients": list of ingredients,
|
267 |
+
"recipe_instructions": list of instructions,
|
268 |
"recipe_image": string,
|
269 |
"blogger": string,
|
270 |
+
"recipe_nutrients": JSON object with key-value pairs such as "protein: 10g",
|
271 |
+
"tags": list of tags related to a recipe
|
272 |
} \n
|
273 |
|
274 |
+
Here is the example of a recipe JSON object from the JSON data: \n
|
275 |
{
|
276 |
"recipe_name": "Asian Potato Salad with Seven Minute Egg",
|
277 |
"recipe_time": 0,
|
|
|
321 |
]
|
322 |
} \n
|
323 |
|
324 |
+
Based on the user query, provide a Python function to filter the JSON data. The output of the function should be a list of JSON objects. \n
|
325 |
|
326 |
Recipe filtering instructions:
|
327 |
+
- If a user asked for the highest nutrient recipe such as "high protein or high calories" then filtered recipes should be the top highest recipes from all the recipes with high nutrients.
|
328 |
+
- sort or rearrange recipes based on which recipes are more appropriate for the user.
|
329 |
|
330 |
Your output instructions:
|
331 |
+
- The function name should be filter_recipes. The input to the function should be the file name.
|
332 |
- The length of output recipes should not be more than 6.
|
333 |
+
- Only give me the output function. Do not call the function.
|
334 |
+
- Give the Python function as a key named "code" in a JSON format.
|
335 |
+
- Do not include any other text with the output, only give Python code.
|
336 |
+
- If you do not follow the above-given instructions, the chat may be terminated.
|
337 |
"""
|
338 |
max_tries = 3
|
339 |
while True:
|
|
|
421 |
response = recommendation_node(message)
|
422 |
if not response:
|
423 |
response = {'content':"An error occurred while processing your request."}
|
424 |
+
else:
|
425 |
+
response = answer_formatter_node(message, recipes)
|
426 |
else:
|
427 |
formated_input = {
|
428 |
'input': message,
|