You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ai/flows/assess-health-safety.ts
+61-61Lines changed: 61 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,67 @@ export async function assessHealthSafety(input: AssessHealthSafetyInput): Promis
50
50
};
51
51
}
52
52
53
+
constprompt=ai.definePrompt({
54
+
name: 'assessHealthSafetyPrompt',
55
+
input: {schema: AssessHealthSafetyInputSchema},
56
+
output: {schema: AssessHealthSafetyOutputSchema},
57
+
prompt: `You are a world-class nutritionist and food safety expert. Your task is to analyze the following list of food ingredients and provide a concise, objective, and non-overlapping health and safety assessment. Your analysis must be grounded in established nutritional science and presented with the authority and trustworthiness of a professional expert. Prioritize factual accuracy and clarity for the user.
58
+
59
+
Ingredients list:
60
+
"{{ingredients}}"
61
+
62
+
Based on the ingredients, perform the following actions and return the result in the specified JSON format:
63
+
64
+
1. **Health Rating (1-5):** Provide an overall health score from 1 (very unhealthy) to 5 (very healthy). Consider factors like processing level, presence of whole foods, additives, sugar content, etc.
65
+
2. **Pros:** List 2-4 distinct positive aspects. Focus on healthy, natural, or beneficial ingredients. Do not simply state the absence of a negative as a positive (e.g., instead of "Low in sugar", focus on "Made with whole grains"). Ensure these are genuine benefits.
66
+
3. **Cons:** List 2-4 distinct negative aspects that are separate from the 'Pros'. Focus on artificial additives, high sugar/sodium indicators, unhealthy fats, or heavily processed components. Ensure these are genuine drawbacks.
67
+
4. **Warnings:** This section is for CRITICAL alerts only. List only ingredients that are banned in major regions (e.g., certain food dyes in the EU), are part of a major scientific controversy regarding health dangers, or pose a significant, non-obvious risk (e.g., high saturated fat for heart conditions). Do not use this section for common allergens or generally unhealthy items; those belong in 'Cons' or dietary information. If there are no such critical warnings, return an empty array.
68
+
5. **Dietary Information:** Based on the ingredients, analyze for common dietary concerns. If the label explicitly states a status (e.g., "Certified Gluten-Free"), trust it. Otherwise, infer based on the ingredients.
69
+
- **allergens:** Identify and list common allergens such as Gluten, Dairy, Soy, Peanuts, Tree Nuts, Fish, Shellfish. Do not list an allergen if a "-free" version is specified (e.g. "soy lecithin" is an allergen, but if the label also says "soy-free", do not list it).
70
+
- **suitability:** Create a list of statements explaining why the product is NOT suitable for certain groups. For example: "Not suitable for vegans" if it contains honey or gelatin. "Not suitable for lactose intolerant individuals" if it contains milk. "Not suitable for people on low-sodium diets" if sodium is high. If there are no specific suitability issues, return an empty array.
71
+
- **isVegetarian:** Determine if the product is vegetarian (contains no meat, poultry, or fish).
72
+
- **isVegan:** Determine if the product is vegan (contains no animal products, including dairy, eggs, or honey).
73
+
- **isGlutenFree:** Determine if the product is gluten-free (contains no wheat, barley, rye, or their derivatives).
74
+
- **summary:** Provide a brief, human-readable summary of the key dietary points. For example: "Contains Dairy and Soy. Suitable for vegetarians but not vegans." If no specific concerns are found, state that.
75
+
76
+
Your analysis must be objective and based on general nutritional science. Be concise, clear, and ensure the 'Pros' and 'Cons' provide a balanced view without contradicting each other.`,
77
+
config: {
78
+
safetySettings: [
79
+
{
80
+
category: 'HARM_CATEGORY_HARASSMENT',
81
+
threshold: 'BLOCK_NONE',
82
+
},
83
+
{
84
+
category: 'HARM_CATEGORY_HATE_SPEECH',
85
+
threshold: 'BLOCK_NONE',
86
+
},
87
+
{
88
+
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
89
+
threshold: 'BLOCK_NONE',
90
+
},
91
+
{
92
+
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
93
+
threshold: 'BLOCK_NONE',
94
+
},
95
+
],
96
+
},
97
+
});
98
+
99
+
constassessHealthSafetyFlow=ai.defineFlow(
100
+
{
101
+
name: 'assessHealthSafetyFlow',
102
+
inputSchema: AssessHealthSafetyInputSchema,
103
+
outputSchema: AssessHealthSafetyOutputSchema,
104
+
},
105
+
async(input)=>{
106
+
const{output}=awaitprompt(input);
107
+
if(!output){
108
+
thrownewError('The AI model failed to provide an assessment.');
109
+
}
110
+
returnoutput;
111
+
}
112
+
);
113
+
53
114
try{
54
115
returnawaitassessHealthSafetyFlow(input);
55
116
}catch(error: any){
@@ -78,64 +139,3 @@ export async function assessHealthSafety(input: AssessHealthSafetyInput): Promis
78
139
};
79
140
}
80
141
}
81
-
82
-
constprompt=ai.definePrompt({
83
-
name: 'assessHealthSafetyPrompt',
84
-
input: {schema: AssessHealthSafetyInputSchema},
85
-
output: {schema: AssessHealthSafetyOutputSchema},
86
-
prompt: `You are a world-class nutritionist and food safety expert. Your task is to analyze the following list of food ingredients and provide a concise, objective, and non-overlapping health and safety assessment. Your analysis must be grounded in established nutritional science and presented with the authority and trustworthiness of a professional expert. Prioritize factual accuracy and clarity for the user.
87
-
88
-
Ingredients list:
89
-
"{{ingredients}}"
90
-
91
-
Based on the ingredients, perform the following actions and return the result in the specified JSON format:
92
-
93
-
1. **Health Rating (1-5):** Provide an overall health score from 1 (very unhealthy) to 5 (very healthy). Consider factors like processing level, presence of whole foods, additives, sugar content, etc.
94
-
2. **Pros:** List 2-4 distinct positive aspects. Focus on healthy, natural, or beneficial ingredients. Do not simply state the absence of a negative as a positive (e.g., instead of "Low in sugar", focus on "Made with whole grains"). Ensure these are genuine benefits.
95
-
3. **Cons:** List 2-4 distinct negative aspects that are separate from the 'Pros'. Focus on artificial additives, high sugar/sodium indicators, unhealthy fats, or heavily processed components. Ensure these are genuine drawbacks.
96
-
4. **Warnings:** This section is for CRITICAL alerts only. List only ingredients that are banned in major regions (e.g., certain food dyes in the EU), are part of a major scientific controversy regarding health dangers, or pose a significant, non-obvious risk (e.g., high saturated fat for heart conditions). Do not use this section for common allergens or generally unhealthy items; those belong in 'Cons' or dietary information. If there are no such critical warnings, return an empty array.
97
-
5. **Dietary Information:** Based on the ingredients, analyze for common dietary concerns. If the label explicitly states a status (e.g., "Certified Gluten-Free"), trust it. Otherwise, infer based on the ingredients.
98
-
- **allergens:** Identify and list common allergens such as Gluten, Dairy, Soy, Peanuts, Tree Nuts, Fish, Shellfish. Do not list an allergen if a "-free" version is specified (e.g. "soy lecithin" is an allergen, but if the label also says "soy-free", do not list it).
99
-
- **suitability:** Create a list of statements explaining why the product is NOT suitable for certain groups. For example: "Not suitable for vegans" if it contains honey or gelatin. "Not suitable for lactose intolerant individuals" if it contains milk. "Not suitable for people on low-sodium diets" if sodium is high. If there are no specific suitability issues, return an empty array.
100
-
- **isVegetarian:** Determine if the product is vegetarian (contains no meat, poultry, or fish).
101
-
- **isVegan:** Determine if the product is vegan (contains no animal products, including dairy, eggs, or honey).
102
-
- **isGlutenFree:** Determine if the product is gluten-free (contains no wheat, barley, rye, or their derivatives).
103
-
- **summary:** Provide a brief, human-readable summary of the key dietary points. For example: "Contains Dairy and Soy. Suitable for vegetarians but not vegans." If no specific concerns are found, state that.
104
-
105
-
Your analysis must be objective and based on general nutritional science. Be concise, clear, and ensure the 'Pros' and 'Cons' provide a balanced view without contradicting each other.`,
106
-
config: {
107
-
safetySettings: [
108
-
{
109
-
category: 'HARM_CATEGORY_HARASSMENT',
110
-
threshold: 'BLOCK_NONE',
111
-
},
112
-
{
113
-
category: 'HARM_CATEGORY_HATE_SPEECH',
114
-
threshold: 'BLOCK_NONE',
115
-
},
116
-
{
117
-
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
118
-
threshold: 'BLOCK_NONE',
119
-
},
120
-
{
121
-
category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
122
-
threshold: 'BLOCK_NONE',
123
-
},
124
-
],
125
-
},
126
-
});
127
-
128
-
constassessHealthSafetyFlow=ai.defineFlow(
129
-
{
130
-
name: 'assessHealthSafetyFlow',
131
-
inputSchema: AssessHealthSafetyInputSchema,
132
-
outputSchema: AssessHealthSafetyOutputSchema,
133
-
},
134
-
async(input)=>{
135
-
const{output}=awaitprompt(input);
136
-
if(!output){
137
-
thrownewError('The AI model failed to provide an assessment.');
Copy file name to clipboardExpand all lines: src/ai/flows/extract-ingredients.ts
+40-39Lines changed: 40 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -18,24 +18,12 @@ export async function extractIngredients(input: ExtractIngredientsInput): Promis
18
18
status: 'unreadable',
19
19
};
20
20
}
21
-
try{
22
-
returnawaitextractIngredientsFlow(input);
23
-
}catch(error){
24
-
console.error("Error in extractIngredientsFlow:",error);
25
-
// Return a structured error on any unexpected exception
26
-
return{
27
-
ingredients: [],
28
-
nutrition: {rawText: 'The AI model failed to process the image due to an unexpected error.',nutrients: []},
29
-
status: 'unreadable',
30
-
};
31
-
}
32
-
}
33
-
34
-
constprompt=ai.definePrompt({
35
-
name: 'extractIngredientsPrompt',
36
-
input: {schema: ExtractIngredientsInputSchema},
37
-
output: {schema: ExtractIngredientsOutputSchema},
38
-
prompt: `You are an expert Optical Character Recognition (OCR) system specializing in food labels. Your task is to extract the ingredients list and nutritional information from the provided image.
21
+
22
+
constprompt=ai.definePrompt({
23
+
name: 'extractIngredientsPrompt',
24
+
input: {schema: ExtractIngredientsInputSchema},
25
+
output: {schema: ExtractIngredientsOutputSchema},
26
+
prompt: `You are an expert Optical Character Recognition (OCR) system specializing in food labels. Your task is to extract the ingredients list and nutritional information from the provided image.
39
27
40
28
Analyze the image carefully and return the data in the specified JSON format.
41
29
@@ -52,28 +40,41 @@ Analyze the image carefully and return the data in the specified JSON format.
52
40
If a section is not found, return empty values for it, but adhere to the schema.
53
41
54
42
Image to analyze: {{media url=image}}`,
55
-
});
43
+
});
56
44
57
-
constextractIngredientsFlow=ai.defineFlow(
58
-
{
59
-
name: 'extractIngredientsFlow',
60
-
inputSchema: ExtractIngredientsInputSchema,
61
-
outputSchema: ExtractIngredientsOutputSchema,
62
-
},
63
-
async(input)=>{
64
-
const{output}=awaitprompt(input);
65
-
if(!output){
66
-
return{
67
-
ingredients: [],
68
-
nutrition: undefined,
69
-
status: 'unreadable',
70
-
};
71
-
}
72
-
// A simple check to refine status if model returns success but no data
0 commit comments