mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-29 21:37:15 -05:00
feat: Import + Translate recipe images with OpenAI (#3974)
Co-authored-by: Johan Lindell <johan@lindell.me> Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
@@ -34,6 +34,7 @@ class AdminAboutController(BaseAdminController):
|
||||
oidc_redirect=settings.OIDC_AUTO_REDIRECT,
|
||||
oidc_provider_name=settings.OIDC_PROVIDER_NAME,
|
||||
enable_openai=settings.OPENAI_ENABLED,
|
||||
enable_openai_image_services=settings.OPENAI_ENABLED and settings.OPENAI_ENABLE_IMAGE_SERVICES,
|
||||
)
|
||||
|
||||
@router.get("/statistics", response_model=AppStatistics)
|
||||
|
||||
@@ -33,6 +33,7 @@ def get_app_info(session: Session = Depends(generate_session)):
|
||||
oidc_redirect=settings.OIDC_AUTO_REDIRECT,
|
||||
oidc_provider_name=settings.OIDC_PROVIDER_NAME,
|
||||
enable_openai=settings.OPENAI_ENABLED,
|
||||
enable_openai_image_services=settings.OPENAI_ENABLED and settings.OPENAI_ENABLE_IMAGE_SERVICES,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -254,6 +254,9 @@ class RecipeController(BaseRecipeController):
|
||||
|
||||
return "recipe_scrapers was unable to scrape this URL"
|
||||
|
||||
# ==================================================================================================================
|
||||
# Other Create Operations
|
||||
|
||||
@router.post("/create-from-zip", status_code=201)
|
||||
def create_recipe_from_zip(self, archive: UploadFile = File(...)):
|
||||
"""Create recipe from archive"""
|
||||
@@ -266,6 +269,31 @@ class RecipeController(BaseRecipeController):
|
||||
|
||||
return recipe.slug
|
||||
|
||||
@router.post("/create-from-image", status_code=201)
|
||||
async def create_recipe_from_image(
|
||||
self,
|
||||
images: list[UploadFile] = File(...),
|
||||
translate_language: str | None = Query(None, alias="translateLanguage"),
|
||||
):
|
||||
"""
|
||||
Create a recipe from an image using OpenAI.
|
||||
Optionally specify a language for it to translate the recipe to.
|
||||
"""
|
||||
|
||||
if not (self.settings.OPENAI_ENABLED and self.settings.OPENAI_ENABLE_IMAGE_SERVICES):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=ErrorResponse.respond("OpenAI image services are not enabled"),
|
||||
)
|
||||
|
||||
recipe = await self.service.create_from_images(images, translate_language)
|
||||
self.publish_event(
|
||||
event_type=EventTypes.recipe_created,
|
||||
document_data=EventRecipeData(operation=EventOperation.create, recipe_slug=recipe.slug),
|
||||
)
|
||||
|
||||
return recipe.slug
|
||||
|
||||
# ==================================================================================================================
|
||||
# CRUD Operations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user