@@ -30,6 +30,7 @@ extension UserDefaults {
3030 case analysisMode = " com.loopkit.Loop.analysisMode "
3131 case foodSearchEnabled = " com.loopkit.Loop.foodSearchEnabled "
3232 case advancedDosingRecommendationsEnabled = " com.loopkit.Loop.advancedDosingRecommendationsEnabled "
33+ case useGPT5ForOpenAI = " com.loopkit.Loop.useGPT5ForOpenAI "
3334 }
3435
3536 var legacyPumpManagerRawValue : PumpManager . RawValue ? {
@@ -201,7 +202,36 @@ MANDATORY REQUIREMENTS:
201202
202203 var openAIQuery : String {
203204 get {
204- return string ( forKey: Key . openAIQuery. rawValue) ?? """
205+ // Check if using GPT-5 - use optimized prompt for better performance
206+ if UserDefaults . standard. useGPT5ForOpenAI {
207+ return string ( forKey: Key . openAIQuery. rawValue) ?? """
208+ Analyze this food image for diabetes management. Be specific and accurate.
209+
210+ JSON format required:
211+ {
212+ " food_items " : [{
213+ " name " : " specific food name with preparation details " ,
214+ " portion_estimate " : " portion size with visual reference " ,
215+ " carbohydrates " : grams_number,
216+ " protein " : grams_number,
217+ " fat " : grams_number,
218+ " calories " : kcal_number,
219+ " serving_multiplier " : decimal_servings
220+ }],
221+ " overall_description " : " detailed visual description " ,
222+ " total_carbohydrates " : sum_carbs,
223+ " total_protein " : sum_protein,
224+ " total_fat " : sum_fat,
225+ " total_calories " : sum_calories,
226+ " confidence " : decimal_0_to_1,
227+ " diabetes_considerations " : " carb sources and timing advice "
228+ }
229+
230+ Requirements: Use exact visual details, compare to visible objects, calculate from visual assessment.
231+ """
232+ } else {
233+ // Full detailed prompt for GPT-4 models
234+ return string ( forKey: Key . openAIQuery. rawValue) ?? """
205235You are a nutrition expert analyzing this food image for diabetes management. Describe EXACTLY what you see in vivid detail.
206236
207237EXAMPLE of the detailed description I expect:
@@ -242,6 +272,7 @@ MANDATORY REQUIREMENTS:
242272✅ ALWAYS compare portions to visible objects (fork, plate, hand if visible)
243273✅ ALWAYS calculate nutrition from YOUR visual portion assessment
244274"""
275+ }
245276 }
246277 set {
247278 set ( newValue, forKey: Key . openAIQuery. rawValue)
@@ -360,4 +391,13 @@ MANDATORY REQUIREMENTS:
360391 set ( newValue, forKey: Key . advancedDosingRecommendationsEnabled. rawValue)
361392 }
362393 }
394+
395+ var useGPT5ForOpenAI : Bool {
396+ get {
397+ return bool ( forKey: Key . useGPT5ForOpenAI. rawValue)
398+ }
399+ set {
400+ set ( newValue, forKey: Key . useGPT5ForOpenAI. rawValue)
401+ }
402+ }
363403}
0 commit comments