Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion py/packages/genkit-ai/tests/genkit/core/action_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_action_enum_behaves_like_str() -> None:
assert ActionKind.EVALUATOR == 'evaluator'
assert ActionKind.EXECUTABLE_PROMPT == 'executable-prompt'
assert ActionKind.FLOW == 'flow'
assert ActionKind.INDEXER == 'indexer'
assert ActionKind.MODEL == 'model'
assert ActionKind.PROMPT == 'prompt'
assert ActionKind.RERANKER == 'reranker'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import logging

from genkit.ai import Action, GenkitRegistry, Plugin
from genkit.ai import GenkitRegistry, Plugin
from genkit.core.action import Action
from genkit.plugins.dev_local_vector_store.constant import Params
from genkit.plugins.dev_local_vector_store.indexer import (
DevLocalVectorStoreIndexer,
Expand Down
Binary file added py/samples/menu/data/menu.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions py/samples/menu/data/menu.json
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."
}
]
1 change: 1 addition & 0 deletions py/samples/menu/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers = [
]
dependencies = [
"genkit-ai",
"genkit-plugin-dev-local-vectorstore",
"genkit-plugin-firebase",
"genkit-plugin-google-ai",
"genkit-plugin-google-cloud",
Expand Down
26 changes: 25 additions & 1 deletion py/samples/menu/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,28 @@
#
# SPDX-License-Identifier: Apache-2.0

"""Menu sample."""
# 01
from case_01.prompts import s01_staticMenuDotPrompt, s01_vanillaPrompt
from case_02.flows import s02_menuQuestionFlow
from case_02.prompts import s02_dataMenuPrompt

# 02
from case_02.tools import menu_tool

# 03
from case_03.flows import s03_multiTurnChatFlow
from case_03.prompts import s03_chatPreamblePrompt

# 04
# TODO: uncomment once implemented
# from case_04.flows import s04_indexMenuItemsFlow, s04_ragMenuQuestionFlow
# from case_04.prompts import s04_ragDataMenuPrompt
# 05
from case_05.flows import (
s05_readMenuFlow,
s05_textMenuQuestionFlow,
s05_visionMenuQuestionFlow,
)
from case_05.prompts import s05_readMenuPrompt, s05_textMenuPrompt

print('All prompts and flows loaded, use the Developer UI to test them out')
17 changes: 17 additions & 0 deletions py/samples/menu/src/case_01/__init__.py
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


5 changes: 5 additions & 0 deletions py/samples/menu/src/case_01/example.json
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?"
}
}
64 changes: 64 additions & 0 deletions py/samples/menu/src/case_01/prompts.py
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}} ?""",
)
17 changes: 17 additions & 0 deletions py/samples/menu/src/case_02/__init__.py
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


3 changes: 3 additions & 0 deletions py/samples/menu/src/case_02/example.json
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?"
}
31 changes: 31 additions & 0 deletions py/samples/menu/src/case_02/flows.py
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,
)
38 changes: 38 additions & 0 deletions py/samples/menu/src/case_02/prompts.py
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}} ?
""",
)
36 changes: 36 additions & 0 deletions py/samples/menu/src/case_02/tools.py
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,
)
17 changes: 17 additions & 0 deletions py/samples/menu/src/case_03/__init__.py
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


Loading
Loading