Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add tts / text-based recipe import feature #4561

Open
wants to merge 9 commits into
base: mealie-next
Choose a base branch
from

Conversation

itsrubberduck
Copy link
Contributor

@itsrubberduck itsrubberduck commented Nov 15, 2024

What type of PR is this?

  • feature

What this PR does / why we need it:

This PR introduces a new text-based recipe import feature using OpenAI's API to automatically parse and structure recipe content. This allows users to paste in plain text recipes and have them automatically formatted into Mealie's recipe structure, with optional translation support.

Changes include:

  • Add new /api/recipes/create/text endpoint for text-based recipe creation
  • Implement OpenAI integration for intelligent recipe parsing:
    • recipe_service.py: Add create_from_text and build_recipe_from_text methods
    • Update OpenAI service to handle text-based recipe extraction
    • Add JSON schema validation for parsed recipes

The changes make recipe import more accessible by allowing users to simply paste text / use tts rather than requiring structured input or image uploads.

Special notes for your reviewer:

  • Currently, no automated tests have been implemented for this feature yet
  • The feature requires proper recipe input with actual ingredients and instructions
  • OpenAI will reject the processing if the input doesn't resemble a proper recipe format
  • Successfully tested with real recipe inputs containing ingredients and preparation steps
  • The OpenAI integration requires the OPENAI_ENABLED setting to be true
  • Translation support is optional and uses the user's locale settings

Current Limitations:

  • Only works with proper recipe formats (ingredients list + instructions)
  • Invalid or too short inputs will be rejected by OpenAI
  • Empty responses will be returned for non-recipe text input
  • Automated testing still needs to be implemented

Testing

Manual testing has been performed with:

  • Real recipe inputs in different formats
  • Various recipe lengths and complexities
  • Different languages with translation
  • Error cases for invalid inputs

TODO:

  • Add automated tests for the text import feature
  • Add input validation tests
  • Add OpenAI response validation tests
  • Add translation functionality tests

• 🎯 Add new endpoints for text-based recipe creation
• 🔍 Implement OpenAI integration for recipe parsing
• 🌐 Add language translation support
• 🏷️ Add new translation keys
• ♻️  Refactor OpenAI service for better text handling
• 🐛 Fix model configuration for OpenAI API
• 📝 Update prompts for better recipe extraction
• 🚨 Add proper error handling and validation
✨ Allow reasonable interpretation of ambiguous text
🎯 Focus on practical usability over strict formatting
@Kuchenpirat
Copy link
Collaborator

Hey, thanks for your PR.
Please prepend your PR title with feat: and check your poetry file. It seems like you upgraded a whole bunch of dependencies with this PR which should not be part of this PR as we use renovate to keep our deps up to date.

@itsrubberduck itsrubberduck changed the title ✨ Add tts / text-based recipe import feature feat: Add tts / text-based recipe import feature Nov 15, 2024
@itsrubberduck
Copy link
Contributor Author

Thanks, didn't get the part with the PR naming and somehow also overlooked the poetry.lock file. Is there anything else - would you like me to delete the german translation file as well?

@Kuchenpirat
Copy link
Collaborator

Yeah, you should only include the english base translation.
Also you should not delete the poetry file in this repo, just don't include changes to it if you are not adding/removing any dependencies in this PR.

@itsrubberduck
Copy link
Contributor Author

Sorry, I must admit my git skills aren't advanced enough to remove the poetry.lock and translation files from the existing commits. I apologize for including these files in the first place - I should have been more careful. Would you be able to guide me through the process, or would it be better to close this PR and create a new one with just the feature-related changes?

@Kuchenpirat
Copy link
Collaborator

git checkout upstream/mealie-next -- poetry.lock

I think this sould revert it to the state in main

@Fuckingnameless
Copy link

in view of #4582 i approve this PR

Fuckingnameless

This comment was marked as duplicate.

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this PR! I think this adds a ton of accessibility to creating recipes, and makes things easier for "weird" imports from unstructured sources (like a text document or similar).

A few comments, but nothing major. Other than those, if you could write a test for this that would be great. We don't want to actually call an OpenAI endpoint for the tests so you'll need to mock a response; you can check out the "create from image" test. If you run into any issues let me know, happy to jump in and write the test myself as well.

The create from image test: https://github.com/mealie-recipes/mealie/blob/mealie-next/tests/integration_tests/user_recipe_tests/test_recipe_create_from_image.py

Comment on lines +60 to +62
{
// just textarea dump voice actived icon
icon: $globals.icons.text,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
// just textarea dump voice actived icon
icon: $globals.icons.text,
{
icon: $globals.icons.text,

message += f" Please translate the recipe to {translate_language}."

try:
# Explizit das model und response_format setzen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Explizit das model und response_format setzen
# Explicitly set the model and response_format

</v-row>
</v-container>
</v-card-text>
<v-card-actions v-if="recipeText">
Copy link
Collaborator

@michael-genson michael-genson Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hiding this, can we disable the create button? It's a bit jarring to see it pop in and out. Something like:
<BaseButton :disabled="!recipeText" ... />

Comment on lines +37 to +39
<p v-if="loading" class="mb-0">
{{ $t('recipe.please-wait-processing') }}
</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably get rid of this since the submit button already indicates that it's loading

frontend/lang/messages/en-US.json Outdated Show resolved Hide resolved
frontend/pages/g/_groupSlug/r/create.vue Outdated Show resolved Hide resolved
Copy link
Contributor Author

@itsrubberduck itsrubberduck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did everything

@itsrubberduck
Copy link
Contributor Author

is there anything left to do for the pr?

@michael-genson
Copy link
Collaborator

Hey there! Sorry for the delay, been swamped with the holidays. Once I get the chance I'll take a look and approve if it's good to go or add some more feedback. Appreciate your patience!

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like some of my feedback got marked as resolved, but wasn't addressed. If you could take a look at those that would be great. I went and marked the ones not addressed as unresolved above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants