Thiophai commited on
Commit
c4b7ae4
·
verified ·
1 Parent(s): e6b3d7a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -12
main.py CHANGED
@@ -95,29 +95,33 @@ def PredictFoodIngredients(menu_name: str, ingredient_file: str) -> dict:
95
 
96
  prompt = (
97
  f"Generate a JSON for menu '{menu_name}' with these rules: "
98
- "1. Accept inputs for any food, beverage, or dessert from any culture, especially Thai cuisine. "
 
 
 
99
  " For Thai food names that might be ambiguous (e.g. น้ำตกหมู, หมูน้ำตก, บวบผัดไข่, ยำหมูกรอบ, หมี่กระเฉด, กระเพราทะเลไข่ดาว, ผัดผักรวมมิตร, ยำวุ้นเส้นหมูสับ etc.), "
100
  " treat the input as a valid food name and attempt to generate a menu accordingly. "
101
- "2. JSON format: {\"menu\": \"<menu name>\", \"ingredients\": [ {\"name\": \"<ingredient>\", \"weight (g)\": <weight>} ], "
102
  " \"unit\": \"<appropriate serving unit in Thai (e.g. จาน, ชาม, แก้ว)>\", \"weight (g)\": <appropriate total weight>}. "
103
- f"3. All ingredients must be selected from the following allowed list only: {allowed_str}. "
104
  " Note: The ingredient names in the input menu do not need to exactly match the allowed list. Instead, infer the intended ingredients from the menu name and choose the closest matching items from the allowed list, using their exact names as provided. "
105
- "4. If the input is not a food, beverage, or dessert name (e.g. person names, places, or non-food related terms), "
106
  " or if the menu requires main ingredients not available in the provided list, return JSON in exactly this format: "
107
- "{\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
108
- "5. Ingredient weights and quantities must follow standard nutritional guidelines, using appropriate average values for one serving. "
109
- "6. For soup-based dishes, noodle soups, broths, or any dish with liquid as a main component (e.g. ก๋ยเตอน้ำตก, ซุปฟักทอ, ตมยำปลทู), always include \"น้ำเปล่า\" as one of the ingredients with appropriate weight. "
110
- "7. Do not generate menus that are not food or edible items, or menus where the main ingredients are unavailable in the database or are unrealistic (e.g. ม้าบิน, อึ่งอ่างย่าง, ดอกไม้). "
111
- "8. Before generating the menu, analyze whether the input is a realistic and culturally acceptable food or beverage. If the input includes mythical creatures, endangered species, or unrealistic food (e.g. ม้าบิน, แมวปิ้ง, หมีย่าง, เสือทอด, นกฮูกตุ๋น, ซุปนางฟ้า), "
112
  " return the JSON format: {\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
113
- "9. If the input contains offensive, illegal, or culturally inappropriate ingredients, return the JSON format: "
114
- "{\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
115
- "10. Return only the JSON in the specified format without any additional explanation."
 
 
116
  )
117
 
118
 
119
 
120
 
 
121
  llm = ChatOpenAI(model="gpt-4o", temperature=0)
122
  messages = [{"role": "user", "content": prompt}]
123
 
 
95
 
96
  prompt = (
97
  f"Generate a JSON for menu '{menu_name}' with these rules: "
98
+ "1. Check for spelling errors or misspellings in the input menu name first. If the input contains minor spelling mistakes, correct them before proceeding with menu generation. "
99
+ " Use common spelling variations to determine the intended food item. If the corrected name is still ambiguous or unrecognizable, return the JSON format: "
100
+ " {\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
101
+ "2. Accept inputs for any food, beverage, or dessert from any culture, especially Thai cuisine. "
102
  " For Thai food names that might be ambiguous (e.g. น้ำตกหมู, หมูน้ำตก, บวบผัดไข่, ยำหมูกรอบ, หมี่กระเฉด, กระเพราทะเลไข่ดาว, ผัดผักรวมมิตร, ยำวุ้นเส้นหมูสับ etc.), "
103
  " treat the input as a valid food name and attempt to generate a menu accordingly. "
104
+ "3. JSON format: {\"menu\": \"<menu name>\", \"ingredients\": [ {\"name\": \"<ingredient>\", \"weight (g)\": <weight>} ], "
105
  " \"unit\": \"<appropriate serving unit in Thai (e.g. จาน, ชาม, แก้ว)>\", \"weight (g)\": <appropriate total weight>}. "
106
+ f"4. All ingredients must be selected from the following allowed list only: {allowed_str}. "
107
  " Note: The ingredient names in the input menu do not need to exactly match the allowed list. Instead, infer the intended ingredients from the menu name and choose the closest matching items from the allowed list, using their exact names as provided. "
108
+ "5. If the input is not a food, beverage, or dessert name (e.g. person names, places, or non-food related terms), "
109
  " or if the menu requires main ingredients not available in the provided list, return JSON in exactly this format: "
110
+ " {\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
111
+ "6. Do not generate menus that are not food or edible items, or menus where the main ingredients are unavailable in the database or are unrealistic (e.g. ม้าบิน, อึ่งอ่างย่าง, ดอกไม้). "
112
+ "7. If the input includes mythical creatures, endangered species, or unrealistic food (e.g. ม้าบิน, แมปิ้ง, หมีย่าง, ือทอด, นกฮูกตุ๋น, ซุปนา้า), "
 
 
113
  " return the JSON format: {\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
114
+ "8. If the input contains offensive, illegal, or culturally inappropriate ingredients, return the JSON format: "
115
+ " {\"menu\": \"ไม่สามารถสร้างเมนูนี้ได้\", \"ingredients\": null, \"unit\": null, \"weight (g)\": null} "
116
+ "9. Ingredient weights and quantities must follow standard nutritional guidelines, using appropriate average values for one serving. "
117
+ "10. For soup-based dishes, noodle soups, broths, or any dish with liquid as a main component (e.g. ก๋วยเตี๋ยวเนื้อน้ำตก, ซุปฟักทอง, ต้มยำปลาทู), always include \"น้ำเปล่า\" as one of the ingredients with appropriate weight. "
118
+ "11. Return only the JSON in the specified format without any additional explanation."
119
  )
120
 
121
 
122
 
123
 
124
+
125
  llm = ChatOpenAI(model="gpt-4o", temperature=0)
126
  messages = [{"role": "user", "content": prompt}]
127