Skip to content

Commit d68ccfe

Browse files
committed
feat(py): py menu sample
1 parent d37711d commit d68ccfe

28 files changed

+911
-0
lines changed

py/samples/menu/data/menu.jpeg

482 KB
Loading

py/samples/menu/data/menu.json

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
[
2+
{
3+
"title": "Mozzarella Sticks",
4+
"price": 8,
5+
"description": "Crispy fried mozzarella sticks served with marinara sauce."
6+
},
7+
{
8+
"title": "Chicken Wings",
9+
"price": 10,
10+
"description": "Crispy fried chicken wings tossed in your choice of sauce."
11+
},
12+
{
13+
"title": "Nachos",
14+
"price": 12,
15+
"description": "Crispy tortilla chips topped with melted cheese, chili, sour cream, and salsa."
16+
},
17+
{
18+
"title": "Onion Rings",
19+
"price": 7,
20+
"description": "Crispy fried onion rings served with ranch dressing."
21+
},
22+
{
23+
"title": "French Fries",
24+
"price": 5,
25+
"description": "Crispy fried french fries."
26+
},
27+
{
28+
"title": "Mashed Potatoes",
29+
"price": 6,
30+
"description": "Creamy mashed potatoes."
31+
},
32+
{
33+
"title": "Coleslaw",
34+
"price": 4,
35+
"description": "Homemade coleslaw."
36+
},
37+
{
38+
"title": "Classic Cheeseburger",
39+
"price": 12,
40+
"description": "A juicy beef patty topped with melted American cheese, lettuce, tomato, and onion on a toasted bun."
41+
},
42+
{
43+
"title": "Bacon Cheeseburger",
44+
"price": 14,
45+
"description": "A classic cheeseburger with the addition of crispy bacon."
46+
},
47+
{
48+
"title": "Mushroom Swiss Burger",
49+
"price": 15,
50+
"description": "A beef patty topped with sautéed mushrooms, melted Swiss cheese, and a creamy horseradish sauce."
51+
},
52+
{
53+
"title": "Chicken Sandwich",
54+
"price": 13,
55+
"description": "A crispy chicken breast on a toasted bun with lettuce, tomato, and your choice of sauce."
56+
},
57+
{
58+
"title": "Pulled Pork Sandwich",
59+
"price": 14,
60+
"description": "Slow-cooked pulled pork on a toasted bun with coleslaw and barbecue sauce."
61+
},
62+
{
63+
"title": "Reuben Sandwich",
64+
"price": 15,
65+
"description": "Thinly sliced corned beef, Swiss cheese, sauerkraut, and Thousand Island dressing on rye bread."
66+
},
67+
{
68+
"title": "House Salad",
69+
"price": 8,
70+
"description": "Mixed greens with your choice of dressing."
71+
},
72+
{
73+
"title": "Caesar Salad",
74+
"price": 9,
75+
"description": "Romaine lettuce with croutons, Parmesan cheese, and Caesar dressing."
76+
},
77+
{
78+
"title": "Greek Salad",
79+
"price": 10,
80+
"description": "Mixed greens with feta cheese, olives, tomatoes, cucumbers, and red onions."
81+
},
82+
{
83+
"title": "Chocolate Lava Cake",
84+
"price": 8,
85+
"description": "A warm, gooey chocolate cake with a molten chocolate center."
86+
},
87+
{
88+
"title": "Apple Pie",
89+
"price": 7,
90+
"description": "A classic apple pie with a flaky crust and warm apple filling."
91+
},
92+
{
93+
"title": "Cheesecake",
94+
"price": 8,
95+
"description": "A creamy cheesecake with a graham cracker crust."
96+
}
97+
]

py/samples/menu/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ classifiers = [
1616
]
1717
dependencies = [
1818
"genkit-ai",
19+
"genkit-plugin-dev-local-vectorstore",
1920
"genkit-plugin-firebase",
2021
"genkit-plugin-google-ai",
2122
"genkit-plugin-google-cloud",

py/samples/menu/src/__init__.py

+25
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,28 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17+
# 01
18+
from case_01.prompts import s01_staticMenuDotPrompt, s01_vanillaPrompt
19+
from case_02.flows import s02_menuQuestionFlow
20+
from case_02.prompts import s02_dataMenuPrompt
21+
22+
# 02
23+
from case_02.tools import menu_tool
24+
25+
# 03
26+
from case_03.flows import s03_multiTurnChatFlow
27+
from case_03.prompts import s03_chatPreamblePrompt
28+
29+
# 04
30+
# TODO: uncomment once implemented
31+
# from case_04.flows import s04_indexMenuItemsFlow, s04_ragMenuQuestionFlow
32+
# from case_04.prompts import s04_ragDataMenuPrompt
33+
# 05
34+
from case_05.flows import (
35+
s05_readMenuFlow,
36+
s05_textMenuQuestionFlow,
37+
s05_visionMenuQuestionFlow,
38+
)
39+
from case_05.prompts import s05_readMenuPrompt, s05_textMenuPrompt
40+
41+
print('All prompts and flows loaded, use the Developer UI to test them out')
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"input": {
3+
"question": "Which of your burgers would you recommend for someone like me who loves bacon?"
4+
}
5+
}
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
from menu_ai import ai
17+
from menu_schemas import MenuQuestionInputSchema
18+
19+
from genkit.plugins.google_genai import google_genai_name
20+
from genkit.plugins.google_genai.models.gemini import GeminiVersion
21+
22+
s01_vanillaPrompt = ai.define_prompt(
23+
variant='s01_vanillaPrompt',
24+
input_schema=MenuQuestionInputSchema,
25+
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.""",
26+
config={'temperature': 0.3},
27+
)
28+
29+
s01_staticMenuDotPrompt = ai.define_prompt(
30+
variant='s01_staticMenuDotPrompt',
31+
model=google_genai_name(GeminiVersion.GEMINI_1_5_FLASH),
32+
input_schema=MenuQuestionInputSchema,
33+
system="""
34+
You are acting as a helpful AI assistant named "Walt" that can answer
35+
questions about the food available on the menu at Walt's Burgers.
36+
Here is today's menu:
37+
38+
- The Regular Burger $12
39+
The classic charbroiled to perfection with your choice of cheese
40+
41+
- The Fancy Burger $13
42+
Classic burger topped with bacon & Blue Cheese
43+
44+
- The Bacon Burger $13
45+
Bacon cheeseburger with your choice of cheese.
46+
47+
- Everything Burger $14
48+
Heinz 57 sauce, American cheese, bacon, fried egg & crispy onion bits
49+
50+
- Chicken Breast Sandwich $12
51+
Tender juicy chicken breast on a brioche roll.
52+
Grilled, blackened, or fried
53+
54+
Our fresh 1/2 lb. beef patties are made using choice cut
55+
brisket, short rib & sirloin. Served on a toasted
56+
brioche roll with chips. Served with lettuce, tomato & pickles.
57+
Onions upon request. Substitute veggie patty $2
58+
59+
Answer this customer's question, in a concise and helpful manner,
60+
as long as it is about food.
61+
62+
Question:
63+
{{question}} ?""",
64+
)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"question": "I'd like to try something spicy. What do you recommend?"
3+
}

py/samples/menu/src/case_02/flows.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
18+
from menu_ai import ai
19+
from menu_schemas import AnswerOutputSchema, MenuQuestionInputSchema
20+
21+
from .prompts import s02_dataMenuPrompt
22+
23+
24+
@ai.flow(name='s02_menuQuestion')
25+
async def s02_menuQuestionFlow(
26+
my_input: MenuQuestionInputSchema,
27+
) -> AnswerOutputSchema:
28+
text = await s02_dataMenuPrompt({'question': my_input.question})
29+
return AnswerOutputSchema(
30+
answer=text,
31+
)
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
from menu_ai import ai
17+
from menu_schemas import MenuQuestionInputSchema
18+
19+
from genkit.plugins.google_genai import google_genai_name
20+
from genkit.plugins.google_genai.models.gemini import GeminiVersion
21+
22+
s02_dataMenuPrompt = ai.define_prompt(
23+
variant='s02_dataMenu',
24+
model=google_genai_name(GeminiVersion.GEMINI_1_5_FLASH),
25+
input_schema=MenuQuestionInputSchema,
26+
tools=['menu_tool'],
27+
system="""You are acting as a helpful AI assistant named Walt that can answer
28+
questions about the food available on the menu at Walt's Burgers.
29+
30+
Answer this customer's question, in a concise and helpful manner,
31+
as long as it is about food on the menu or something harmless like sports.
32+
Use the tools available to answer menu questions.
33+
DO NOT INVENT ITEMS NOT ON THE MENU.
34+
35+
Question:
36+
{{question}} ?
37+
""",
38+
)

py/samples/menu/src/case_02/tools.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
18+
import json
19+
import os
20+
21+
from menu_ai import ai
22+
from menu_schemas import MenuToolOutputSchema
23+
24+
menu_json_path = os.path.join(
25+
os.path.dirname(__file__), '..', '..', 'data', 'menu.json'
26+
)
27+
with open(menu_json_path, 'r') as f:
28+
menu_data = json.load(f)
29+
30+
31+
@ai.tool(
32+
description="Use this tool to retrieve all the items on today's menu",
33+
name='menu_tool',
34+
)
35+
def menu_tool(input=None) -> MenuToolOutputSchema:
36+
return MenuToolOutputSchema(
37+
menu_data=menu_data,
38+
)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+

0 commit comments

Comments
 (0)