Skip to content

Commit 6e8b1a7

Browse files
feat(service): add method to retrieve nutritional facts
1 parent 1407ef8 commit 6e8b1a7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/main/java/com/otavio/aifoodapp/service/ChatService.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,47 @@ public Mono<String> suggestDietaryAdjustments(List<FoodItem> foodItems, String d
9090

9191
return null;
9292
}
93+
94+
public Mono <String> GetNutrictionFacts (String foodName) {
95+
String prompt = String.format("""
96+
Provide detailed nutritional information for the following food item: %s.
97+
The information should include:
98+
1. Calories
99+
2. Proteins
100+
3. Carbohydrates
101+
4. Fats
102+
5. Vitamins and Minerals
103+
6. Dietary Fiber
104+
7. Serving Size
105+
8. Health Benefits
106+
9. Potential Allergens
107+
10. Recommended Daily Intake
108+
109+
Please present the information in a clear and organized manner.
110+
111+
**Criteria:**
112+
1. **Language:** Portuguese
113+
2. **Output Required:** Nutritional Facts
114+
3. **Output Format:** Valid JSON array with key-value pairs for each nutritional fact.
115+
4. **Example Output:**
116+
[
117+
{"Nutrient": "Calories", "Amount": "200 kcal"},
118+
{"Nutrient": "Proteins", "Amount": "5 g"},
119+
{"Nutrient": "Carbohydrates", "Amount": "30 g"},
120+
{"Nutrient": "Fats", "Amount": "10 g"},
121+
{"Nutrient": "Vitamins and Minerals", "Amount": "Vitamin A, Vitamin C, Calcium"},
122+
{"Nutrient": "Dietary Fiber", "Amount": "3 g"},
123+
{"Nutrient": "Serving Size", "Amount": "100 g"},
124+
{"Nutrient": "Health Benefits", "Amount": "Rich in antioxidants, supports immune health"},
125+
{"Nutrient": "Potential Allergens", "Amount": "None"},
126+
{"Nutrient": "Recommended Daily Intake", "Amount": "Varies by age
127+
""", foodName);
128+
129+
Prompt nutritionPrompt = new Prompt(List.of(
130+
new SystemMessage(systemPrompt),
131+
new UserMessage(prompt)));
132+
133+
return maritacaChatClient.call(nutritionPrompt)
134+
.map(response -> response.getResult().getOutput().getText());
135+
}
93136
}

0 commit comments

Comments
 (0)