-
Notifications
You must be signed in to change notification settings - Fork 616
feat(py): loading prompts automatically #3992
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
Conversation
…test flow with Dev UI
…test flow with Dev UI
Summary of ChangesHello @MengqinShen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant enhancements to how prompts are managed and used within the Genkit framework. The primary goal is to streamline the developer experience by enabling automatic loading of prompts from designated directories and providing more flexible ways to customize prompt rendering through Handlebars helpers. These changes aim to make prompt-driven development more intuitive and less verbose, reducing boilerplate code for prompt initialization and improving template functionality. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a convenient feature to automatically load prompts from a directory upon Genkit initialization. The implementation is mostly solid, with related changes to prompt loading functions and updates to a sample application to demonstrate the new functionality. My main concerns are:
- A large test file (
generate_test.py) has been deleted without an apparent replacement, which is a critical issue that could lead to regressions. - An existing test case in
prompt_test.pywas emptied of its implementation. - There are a few opportunities for code cleanup and clarification in the new
Genkitinitialization logic and the updated sample code.
Overall, the feature is a good addition, but the testing-related changes need to be addressed before merging.
I am having trouble creating individual review comments. Click here to see my feedback.
py/packages/genkit/tests/genkit/blocks/generate_test.py (1-419)
This entire test file, which contains numerous tests for generate_action (including middleware, streaming, and spec-based tests), has been removed. Deleting tests without replacing them is risky and can lead to regressions. If these tests are still relevant, they should be restored or equivalent coverage should be added elsewhere. Could you clarify the reason for this removal?
py/packages/genkit/src/genkit/ai/_aio.py (84-85)
The docstring for prompt_dir is a bit misleading. It states that it defaults to './prompts', but the argument's default value is None. The behavior is to check for './prompts' only if prompt_dir is not provided. A more accurate description would improve clarity.
prompt_dir: Directory to automatically load prompts from.
If not provided, defaults to loading from './prompts' if it exists.
py/packages/genkit/src/genkit/ai/_aio.py (91-94)
This logic for determining which prompt directory to load is a bit repetitive. It can be simplified by using a variable to hold the path to load, which avoids calling load_prompt_folder in two different places and hardcoding the './prompts' path.
load_path = prompt_dir
if load_path is None:
default_prompts_path = Path('./prompts')
if default_prompts_path.is_dir():
load_path = default_prompts_path
if load_path:
load_prompt_folder(self.registry, dir_path=load_path)py/packages/genkit/tests/genkit/blocks/prompt_test.py (544)
The implementation of test_prompt_function_uses_lookup_prompt has been removed, leaving an empty test. Empty tests provide no value and can be misleading. This test should either be completed to verify the prompt() helper function or removed entirely.
py/samples/prompt_demo/prompts/nested/nested_hello.prompt (1-2)
The frontmatter from the original nested_hello.prompt file, which defined the model and input schema, has been removed. While the default model is now set during Genkit initialization, removing the input schema definition could be confusing, as there's no longer a defined contract for its input. If this prompt is intended as a complete example, please consider re-adding the frontmatter, at least for the input schema, to make it self-contained.
py/samples/prompt_demo/src/prompt_demo.py (34)
The my_helper function accepts *args and **kwargs but does not use them. To improve clarity, it's best to remove unused parameters from function signatures.
def my_helper(content):
CHANGELOG: