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
5 changes: 4 additions & 1 deletion py/packages/genkit/src/genkit/blocks/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,10 @@ async def create_prompt_from_file():
'type': 'prompt',
'lazy': True,
'source': 'file',
'_async_factory': create_prompt_from_file,
'prompt': {
'name': name,
'variant': variant or '',
},
}

# Create two separate action functions :
Expand Down
2 changes: 2 additions & 0 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ genkit-plugin-ollama = { workspace = true }
genkit-plugin-vertex-ai = { workspace = true }
google-genai-hello = { workspace = true }
google-genai-image = { workspace = true }
prompt-demo = { workspace = true }


[tool.uv.workspace]
members = ["packages/*", "plugins/*", "samples/*"]
Expand Down
4 changes: 4 additions & 0 deletions py/samples/prompt_demo/data/_shared_partial.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
model: googleai/gemini-1.5-flash
---
This is a PARTIAL that says: {{my_helper "Partial content with helper"}}
1 change: 1 addition & 0 deletions py/samples/prompt_demo/data/dot.name.test.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{name}}, I am a dot name test!
1 change: 1 addition & 0 deletions py/samples/prompt_demo/data/hello.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{name}}!
1 change: 1 addition & 0 deletions py/samples/prompt_demo/data/hello.variant.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hola {{name}}!
9 changes: 9 additions & 0 deletions py/samples/prompt_demo/data/nested/nested_hello.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
model: googleai/gemini-1.5-flash
input:
schema:
name: string
---

This is a nested prompt, hello {{name}}!
{{> shared_partial}}
55 changes: 55 additions & 0 deletions py/samples/prompt_demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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

[project]
authors = [{ name = "Google" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Libraries",
]
dependencies = ["genkit", "structlog>=25.2.0", "genkit-plugin-google-genai"]
description = "Genkit prompt demo"
license = { text = "Apache-2.0" }
name = "prompt-demo"
requires-python = ">=3.10"
version = "0.0.1"

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]

[tool.hatch.build.targets.wheel]
packages = ["src"]

[tool.hatch.metadata]
allow-direct-references = true

[tool.uv.sources]
genkit = { workspace = true }
genkit-plugin-google-genai = { workspace = true }
53 changes: 53 additions & 0 deletions py/samples/prompt_demo/src/prompt_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 asyncio
from pathlib import Path

import structlog

from genkit.ai import Genkit
from genkit.blocks.prompt import load_prompt_folder
from genkit.plugins.google_genai import GoogleAI

logger = structlog.get_logger(__name__)


# Initialize with GoogleAI plugin
ai = Genkit(plugins=[GoogleAI()])


async def main():
# Load the prompts from the directory (data)
current_dir = Path(__file__).resolve().parent
prompts_path = current_dir.parent / 'data'
load_prompt_folder(ai.registry, prompts_path)

# List actions to verify loading
actions = ai.registry.list_serializable_actions()

# Filter for prompts to be specific
# Keys start with /prompt
prompts = [key for key in actions.keys() if key.startswith(('/prompt/', '/executable-prompt/'))]

await logger.ainfo('Registry Status', total_actions=len(actions), loaded_prompts=prompts)

if not prompts:
await logger.awarning('No prompts found! Check directory structure.')


if __name__ == '__main__':
ai.run_main(main())
20 changes: 19 additions & 1 deletion py/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading