When users log food with a specific unit of measure (e.g., "3 ounces of ground pork at 10am"), the AI extracts:
name: "ground pork"value: "3.00"- Missing: the unit "ounces"
This forces users to manually convert between units when selecting products from the catalog (e.g., converting ounces to grams or cups).
{
"event_type": "food",
"event_data": {
"name": "ground pork",
"value": "3.00"
},
"confidence": 90,
"time_info": {
"specific_time": "10:00"
}
}{
"event_type": "food",
"event_data": {
"name": "ground pork",
"value": "3.00",
"quantity_unit": "oz"
},
"confidence": 90,
"time_info": {
"specific_time": "10:00"
}
}File: mobile/src/utils/eventParser.ts
- Add
quantity_unitto the response schemas:
quantity_unit: {
type: "STRING",
nullable: true,
description: "Unit of measure for food quantity (oz, g, cup, tbsp, tsp, ml, lb, piece, slice, serving, each)"
}- Update system prompts in
buildSystemPrompt()andparseAudioWithAI()to instruct the AI to extract quantity units:
For FOOD events: Extract quantity (value) and unit (quantity_unit) separately.
Examples:
- "3 ounces of chicken" → value: "3", quantity_unit: "oz"
- "2 cups of rice" → value: "2", quantity_unit: "cup"
- "a tablespoon of olive oil" → value: "1", quantity_unit: "tbsp"
- "an apple" → value: "1", quantity_unit: "each"
- "chicken breast" (no quantity specified) → value: null, quantity_unit: null
Standard unit abbreviations:
- Weight: oz, g, kg, lb
- Volume: cup, tbsp, tsp, ml, l, fl oz
- Count: each, piece, slice, serving
Files to update:
mobile/src/utils/voiceEventParser.js- Ensurequantity_unitpasses through- Product selection screen - Receive and use
quantity_unit
The quantity_unit should flow from:
- AI parsing →
- Event confirmation screen →
- Product selection screen →
- Final event storage (in
event_data)
New file: mobile/src/utils/unitConversion.js
// Weight conversions to grams
const WEIGHT_TO_GRAMS = {
oz: 28.3495,
lb: 453.592,
g: 1,
kg: 1000
};
// Volume conversions to milliliters
const VOLUME_TO_ML = {
cup: 236.588,
tbsp: 14.787,
tsp: 4.929,
ml: 1,
l: 1000,
'fl oz': 29.574
};
// Convert quantity from one unit to another
export function convertQuantity(value, fromUnit, toUnit) {
// Implementation
}
// Check if two units are compatible (both weight or both volume)
export function areUnitsCompatible(unit1, unit2) {
// Implementation
}
// Get gram weight for a quantity (for nutrition calculation)
export function toGrams(value, unit) {
// Implementation
}When the user selects a product:
-
If units match: Use directly (user said "3 oz", product has oz serving)
-
If units are compatible but different: Convert automatically
- User: "3 oz" of ground pork
- Product: serving size is "1 cup = 135g"
- Calculate: 3 oz = 85g ≈ 0.63 cups
- Pre-fill: 0.63 cups (or show "3 oz ≈ 0.6 cups")
-
If units are incompatible: Show the user's original quantity and let them adjust
- User: "2 pieces" of chicken
- Product: serving size is "100g"
- Show: quantity field with note about original input
-
Display conversion help:
- Show a small helper text: "3 oz = 85g" when relevant
| Unit | Abbreviation | Grams |
|---|---|---|
| Ounce | oz | 28.35 |
| Pound | lb | 453.59 |
| Gram | g | 1 |
| Kilogram | kg | 1000 |
| Unit | Abbreviation | Milliliters |
|---|---|---|
| Cup | cup | 236.59 |
| Tablespoon | tbsp | 14.79 |
| Teaspoon | tsp | 4.93 |
| Fluid ounce | fl oz | 29.57 |
| Milliliter | ml | 1 |
| Liter | l | 1000 |
| Unit | Usage |
|---|---|
| each | Individual items (an apple, a banana) |
| piece | Portions (a piece of chicken) |
| slice | Sliced items (a slice of bread) |
| serving | Generic serving |
-
Weight unit specified:
- Input: "3 ounces of ground pork"
- Expected:
value: "3", quantity_unit: "oz"
-
Volume unit specified:
- Input: "2 cups of rice"
- Expected:
value: "2", quantity_unit: "cup"
-
Count unit implied:
- Input: "an apple"
- Expected:
value: "1", quantity_unit: "each"
-
No unit specified:
- Input: "chicken breast"
- Expected:
value: null, quantity_unit: null
-
Mixed with time:
- Input: "3 oz ground beef at noon"
- Expected:
value: "3", quantity_unit: "oz", time_info: { specific_time: "12:00" }
- AI extracts
quantity_unitfrom food inputs - Unit flows through to product selection screen
- Product selection pre-populates with converted quantity when possible
- User sees helpful conversion hints when units differ
- No manual unit conversion required for common cases (oz ↔ g, cups ↔ ml)
| Phase | Effort | Files Changed |
|---|---|---|
| Phase 1: Schema | Small | 1 file (eventParser.ts) |
| Phase 2: Data Flow | Small | 2-3 files |
| Phase 3: Conversion Utility | Medium | 1 new file |
| Phase 4: UI Enhancement | Medium | Product selection component |
Total: ~2-3 hours of development