apps/ai/services/remix.py (Line 230:13 - Line 245:21), apps/ai/services/remix.py (Line 109:17 - Line 124:15)
,
modification=modification,
)
# Call AI service
service = OpenRouterService()
response = service.complete(
system_prompt=prompt.system_prompt,
user_prompt=user_prompt,
model=prompt.model,
json_response=True,
)
# Validate response
validator = AIResponseValidator()
validated = validator.validate("nutrition_estimate"
apps/ai/services/remix.py (Line 260:5 - Line 275:16), apps/ai/services/scaling.py (Line 28:5 - Line 43:13)
numbers = re.findall(r"\d+", time_str)
if not numbers:
return None
minutes = int(numbers[0])
# Convert hours to minutes if needed
if "hour" in time_str:
minutes *= 60
if len(numbers) > 1:
minutes += int(numbers[1])
return minutes
def _parse_servings
apps/ai/services/openrouter.py (Line 167:11 - Line 193:2), apps/ai/services/openrouter.py (Line 116:5 - Line 142:6)
(
messages=messages,
model=model,
stream=False,
)
# Extract the response content
if not response or not hasattr(response, "choices"):
raise AIResponseError("Invalid response structure from OpenRouter")
if not response.choices:
raise AIResponseError("No choices in OpenRouter response")
content = response.choices[0].message.content
if json_response:
return self._parse_json_response(content)
return {"content": content}
except AIServiceError:
raise
except Exception as e:
logger.exception("OpenRouter API error")
raise AIResponseError(f"OpenRouter API error: {e}")
@
apps/ai/api.py (Line 436:5 - Line 467:4), apps/ai/api.py (Line 345:5 - Line 376:6)
from apps.profiles.utils import get_current_profile_or_none
profile = get_current_profile_or_none(request)
if not profile:
return 404, {
"error": "not_found",
"message": "Profile not found",
}
# Verify the profile_id in the request matches the session profile
if data.profile_id != profile.id:
return 404, {
"error": "not_found",
"message": f"Profile {data.profile_id} not found",
}
try:
recipe = Recipe.objects.get(id=data.recipe_id)
except Recipe.DoesNotExist:
return 404, {
"error": "not_found",
"message": f"Recipe {data.recipe_id} not found",
}
if recipe.profile_id != profile.id:
return 404, {
"error": "not_found",
"message": f"Recipe {data.recipe_id} not found",
}
try
apps/ai/api.py (Line 527:5 - Line 545:46), apps/ai/api.py (Line 315:5 - Line 333:12)
from apps.profiles.utils import get_current_profile_or_none
profile = get_current_profile_or_none(request)
try:
recipe = Recipe.objects.get(id=data.recipe_id)
except Recipe.DoesNotExist:
return 404, {
"error": "not_found",
"message": f"Recipe {data.recipe_id} not found",
}
if not profile or recipe.profile_id != profile.id:
return 404, {
"error": "not_found",
"message": f"Recipe {data.recipe_id} not found",
}
# Clear existing tips if regenerate requested