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: Parse and convert units using openAI #4508

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

Conversation

Gulianrdgd
Copy link

What type of PR is this?

  • feature

What this PR does / why we need it:

It adds some new routes which allow you to parse the ingredients and convert them using openAI. The code is the same as the parsing but with some additions to the prompt. The results from openAI (at least in my testing) were really great.

Which issue(s) this PR fixes:

#2731

Special notes for your reviewer:

I do not have a translation for the button and I am maybe not happy with the place of the button in the UI (maybe the mealie team has some insights). I also do not have a testing function for this, since I am also not very experienced in this field.

Testing

I imported many recipes and kept fine-tuning the prompt

Gulianrdgd and others added 7 commits October 29, 2024 21:51
prompt: I am Dutch so use imperial. You can approximate units like cups and depending on the ingredient use liters or grams. Obviously, ml should be used for ingredients that are liquid and grams for ingredients that are solid. Teaspoons and pinches you can keep the same. You may also convert inches to cm
@michael-genson
Copy link
Collaborator

Would you be able to share some screenshots of the UI? I think that will help others review.
Also, can you share some examples of before/after? Just curious to see some examples (and particularly to share them with users who are bilingual)

@Gulianrdgd
Copy link
Author

Gulianrdgd commented Nov 4, 2024

Sure! @michael-genson Here are some screenshots

This is the standard recipe just after it has been imported:
Screenshot 2024-11-04 at 20-38-26 Creamy Macaroni and Cheese

This is the view of the parser with the original openAI integration:
Screenshot 2024-11-04 at 20-39-01 Ingredient Parser

This is the view after the conversion:
Screenshot 2024-11-04 at 20-39-16 Ingredient Parser

This is the result:
Screenshot 2024-11-04 at 20-39-37 Creamy Macaroni and Cheese

@Gulianrdgd
Copy link
Author

Gulianrdgd commented Nov 4, 2024

Examples before and after. The before are withouth any parsing, the second are with the parsing and conversion.

4 tablespoons toasted sesame oil
2 tablespoons soy sauce or tamari
1 tablespoon rice vinegar
1 tablespoon honey
1 (2-inch) piece fresh ginger, peeled and finely grated (about 1 tablespoon)
1 garlic clove, finely grated
1 pound broccoli, trimmed and cut into florets, thick stems discarded
2 scallions, trimmed and cut diagonally into 1 1/2-inch segments, plus thinly sliced scallions for garnish
1 tablespoon olive oil, plus more for brushing the salmon
Kosher salt and black pepper
4 (6-ounce) skin-on salmon fillets
1/2 lime, for serving
Sesame seeds, for serving

=======

60 milliliters sesame oil
30 milliliters soy sauce or tamari
15 milliliters vinegar
15 milliliters honey
1 ginger peeled and finely grated (about 15ml)
1 clove garlic finely grated
450 grams broccoli trimmed and cut into florets, thick stems discarded
2 scallions trimmed and cut diagonally into 4 cm segments, plus thinly sliced scallions for garnish
15 milliliters olive oil plus more for brushing the salmon

680 grams salmon
1/2 lime for serving
sesame seeds for serving

=============

3 tablespoons honey
3/4 teaspoon black pepper, plus more to taste
Kosher salt (such as Diamond Crystal)
2 tablespoons all-purpose flour
1 1/2 teaspoons ground turmeric
1 pound boneless, skinless chicken thighs, cut into 1-inch pieces
1 tablespoon coconut or canola oil
12 ounces asparagus, trimmed and thinly sliced on an angle
1 teaspoon unseasoned rice vinegar or soy sauce
1 lime, cut into wedges (optional)

==========

45 milliliters honey
3/4 teaspoon black pepper plus more to taste
salt such as Diamond Crystal
30 grams flour
1 1/2 teaspoons ground turmeric
450 grams chicken thighs cut into 3cm pieces
15 milliliters coconut oil
340 grams asparagus trimmed and thinly sliced on an angle
1 teaspoon rice vinegar
1 lime cut into wedges (optional)

@Fuckingnameless
Copy link

can you please add language translation for recipes using either local whisper or openai API?

@khafatech
Copy link

@Gulianrdgd

I see some inaccuracies & missing info between the original and the converted recipe.

For example:

  • "toasted" is removed in the metrics conversion:
    "4 tablespoons toasted sesame oil"
    became
    "60 milliliters sesame oil"

  • The metric version is missing this item also:
    "4 (6-ounce) skin-on salmon fillets"

  • In the last conversion, it has non-metrics in the result: "1 1/2 teaspoons ground turmeric"

@Gulianrdgd
Copy link
Author

@khafatech

  • I think those differences are there because I removed them when I added the parsed ingredients. For instance, I already has the ingredient sesame oil, so instead of creating a new ingredient, I changed the field ingredient to sesame oil. I also reused most of the prompt which is used in the normal openAI parser, so perhaps these differences are also in that parser.

  • I put that into the prompt, Teaspoons and pinches you can keep the same. Because that seemed logical to me. If that isn't the case I could easily change it.

@michael-genson
Copy link
Collaborator

Sorry it took so long to get to this!

In general I like this. Have you considered merging this with the OpenAI parser logic, rather than having it be its own separate prompt? Something like "you may be asked to translate/convert units..." and adding a param. That way we're not duplicating prompts.

I did something similar with the image parsing prompt.

@Gulianrdgd
Copy link
Author

@michael-genson
No problem!

I have considered this and I was playing around with it but removed it later. So it's funny that you bring it up.

I had something like you suggested in the beginning but when the prompt got bigger I separated them. I figured that a longer prompt would perform worse., but did not test it.

I'll try to combine the prompts this weekend

@michael-genson
Copy link
Collaborator

michael-genson commented Nov 30, 2024

Ah okay, if you're getting better results/small requests from keeping it separate that's fine. More of just something to consider. I'll give it a proper look over in the next few days, but overall looks good!

Copy link
Contributor

This PR is stale because it has been open 45 days with no activity.

@michael-genson
Copy link
Collaborator

Looks like there are some failing tests on this one

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.

4 participants