-
Notifications
You must be signed in to change notification settings - Fork 678
feat(py): menu example #2416
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
Merged
Merged
feat(py): menu example #2416
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| [ | ||
| { | ||
| "title": "Mozzarella Sticks", | ||
| "price": 8, | ||
| "description": "Crispy fried mozzarella sticks served with marinara sauce." | ||
| }, | ||
| { | ||
| "title": "Chicken Wings", | ||
| "price": 10, | ||
| "description": "Crispy fried chicken wings tossed in your choice of sauce." | ||
| }, | ||
| { | ||
| "title": "Nachos", | ||
| "price": 12, | ||
| "description": "Crispy tortilla chips topped with melted cheese, chili, sour cream, and salsa." | ||
| }, | ||
| { | ||
| "title": "Onion Rings", | ||
| "price": 7, | ||
| "description": "Crispy fried onion rings served with ranch dressing." | ||
| }, | ||
| { | ||
| "title": "French Fries", | ||
| "price": 5, | ||
| "description": "Crispy fried french fries." | ||
| }, | ||
| { | ||
| "title": "Mashed Potatoes", | ||
| "price": 6, | ||
| "description": "Creamy mashed potatoes." | ||
| }, | ||
| { | ||
| "title": "Coleslaw", | ||
| "price": 4, | ||
| "description": "Homemade coleslaw." | ||
| }, | ||
| { | ||
| "title": "Classic Cheeseburger", | ||
| "price": 12, | ||
| "description": "A juicy beef patty topped with melted American cheese, lettuce, tomato, and onion on a toasted bun." | ||
| }, | ||
| { | ||
| "title": "Bacon Cheeseburger", | ||
| "price": 14, | ||
| "description": "A classic cheeseburger with the addition of crispy bacon." | ||
| }, | ||
| { | ||
| "title": "Mushroom Swiss Burger", | ||
| "price": 15, | ||
| "description": "A beef patty topped with sautéed mushrooms, melted Swiss cheese, and a creamy horseradish sauce." | ||
| }, | ||
| { | ||
| "title": "Chicken Sandwich", | ||
| "price": 13, | ||
| "description": "A crispy chicken breast on a toasted bun with lettuce, tomato, and your choice of sauce." | ||
| }, | ||
| { | ||
| "title": "Pulled Pork Sandwich", | ||
| "price": 14, | ||
| "description": "Slow-cooked pulled pork on a toasted bun with coleslaw and barbecue sauce." | ||
| }, | ||
| { | ||
| "title": "Reuben Sandwich", | ||
| "price": 15, | ||
| "description": "Thinly sliced corned beef, Swiss cheese, sauerkraut, and Thousand Island dressing on rye bread." | ||
| }, | ||
| { | ||
| "title": "House Salad", | ||
| "price": 8, | ||
| "description": "Mixed greens with your choice of dressing." | ||
| }, | ||
| { | ||
| "title": "Caesar Salad", | ||
| "price": 9, | ||
| "description": "Romaine lettuce with croutons, Parmesan cheese, and Caesar dressing." | ||
| }, | ||
| { | ||
| "title": "Greek Salad", | ||
| "price": 10, | ||
| "description": "Mixed greens with feta cheese, olives, tomatoes, cucumbers, and red onions." | ||
| }, | ||
| { | ||
| "title": "Chocolate Lava Cake", | ||
| "price": 8, | ||
| "description": "A warm, gooey chocolate cake with a molten chocolate center." | ||
| }, | ||
| { | ||
| "title": "Apple Pie", | ||
| "price": 7, | ||
| "description": "A classic apple pie with a flaky crust and warm apple filling." | ||
| }, | ||
| { | ||
| "title": "Cheesecake", | ||
| "price": 8, | ||
| "description": "A creamy cheesecake with a graham cracker crust." | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "input": { | ||
| "question": "Which of your burgers would you recommend for someone like me who loves bacon?" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from menu_ai import ai | ||
| from menu_schemas import MenuQuestionInputSchema | ||
|
|
||
| from genkit.plugins.google_genai import google_genai_name | ||
| from genkit.plugins.google_genai.models.gemini import GeminiVersion | ||
|
|
||
| s01_vanillaPrompt = ai.define_prompt( | ||
| variant='s01_vanillaPrompt', | ||
| input_schema=MenuQuestionInputSchema, | ||
| system="""You are acting as a helpful AI assistant named "Walt" that can answer questions about the food available on the menu at Walt's Burgers.""", | ||
| config={'temperature': 0.3}, | ||
| ) | ||
|
|
||
| s01_staticMenuDotPrompt = ai.define_prompt( | ||
| variant='s01_staticMenuDotPrompt', | ||
| model=google_genai_name(GeminiVersion.GEMINI_1_5_FLASH), | ||
| input_schema=MenuQuestionInputSchema, | ||
| system=""" | ||
| You are acting as a helpful AI assistant named "Walt" that can answer | ||
| questions about the food available on the menu at Walt's Burgers. | ||
| Here is today's menu: | ||
|
|
||
| - The Regular Burger $12 | ||
| The classic charbroiled to perfection with your choice of cheese | ||
|
|
||
| - The Fancy Burger $13 | ||
| Classic burger topped with bacon & Blue Cheese | ||
|
|
||
| - The Bacon Burger $13 | ||
| Bacon cheeseburger with your choice of cheese. | ||
|
|
||
| - Everything Burger $14 | ||
| Heinz 57 sauce, American cheese, bacon, fried egg & crispy onion bits | ||
|
|
||
| - Chicken Breast Sandwich $12 | ||
| Tender juicy chicken breast on a brioche roll. | ||
| Grilled, blackened, or fried | ||
|
|
||
| Our fresh 1/2 lb. beef patties are made using choice cut | ||
| brisket, short rib & sirloin. Served on a toasted | ||
| brioche roll with chips. Served with lettuce, tomato & pickles. | ||
| Onions upon request. Substitute veggie patty $2 | ||
|
|
||
| Answer this customer's question, in a concise and helpful manner, | ||
| as long as it is about food. | ||
|
|
||
| Question: | ||
| {{question}} ?""", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "question": "I'd like to try something spicy. What do you recommend?" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| from menu_ai import ai | ||
| from menu_schemas import AnswerOutputSchema, MenuQuestionInputSchema | ||
|
|
||
| from .prompts import s02_dataMenuPrompt | ||
|
|
||
|
|
||
| @ai.flow(name='s02_menuQuestion') | ||
| async def s02_menuQuestionFlow( | ||
| my_input: MenuQuestionInputSchema, | ||
| ) -> AnswerOutputSchema: | ||
| text = await s02_dataMenuPrompt({'question': my_input.question}) | ||
| return AnswerOutputSchema( | ||
| answer=text, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from menu_ai import ai | ||
| from menu_schemas import MenuQuestionInputSchema | ||
|
|
||
| from genkit.plugins.google_genai import google_genai_name | ||
| from genkit.plugins.google_genai.models.gemini import GeminiVersion | ||
|
|
||
| s02_dataMenuPrompt = ai.define_prompt( | ||
| variant='s02_dataMenu', | ||
| model=google_genai_name(GeminiVersion.GEMINI_1_5_FLASH), | ||
| input_schema=MenuQuestionInputSchema, | ||
| tools=['menu_tool'], | ||
| system="""You are acting as a helpful AI assistant named Walt that can answer | ||
| questions about the food available on the menu at Walt's Burgers. | ||
|
|
||
| Answer this customer's question, in a concise and helpful manner, | ||
| as long as it is about food on the menu or something harmless like sports. | ||
| Use the tools available to answer menu questions. | ||
| DO NOT INVENT ITEMS NOT ON THE MENU. | ||
|
|
||
| Question: | ||
| {{question}} ? | ||
| """, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| import json | ||
| import os | ||
|
|
||
| from menu_ai import ai | ||
| from menu_schemas import MenuToolOutputSchema | ||
|
|
||
| menu_json_path = os.path.join(os.path.dirname(__file__), '..', '..', 'data', 'menu.json') | ||
| with open(menu_json_path, 'r') as f: | ||
| menu_data = json.load(f) | ||
|
|
||
|
|
||
| @ai.tool( | ||
| description="Use this tool to retrieve all the items on today's menu", | ||
| name='menu_tool', | ||
| ) | ||
| def menu_tool(input=None) -> MenuToolOutputSchema: | ||
| return MenuToolOutputSchema( | ||
| menu_data=menu_data, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.