Skip to content

fix(py): align quickstart, readme examples, and docstrings with 1.0 runtime - #7135

Closed
huangjeff5 wants to merge 15 commits into
mainfrom
fix/py-1.0-pr1-docs-quickstart
Closed

huangjeff5 wants to merge 15 commits into
mainfrom
fix/py-1.0-pr1-docs-quickstart

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

Aligns documentation, READMEs, and docstrings with the 1.0 runtime contracts and verified against a fresh uv init project.

Main Changes

  • Verified fresh-venv quickstart: Quick Start in py/README.md runs end-to-end without extra undocumented packages.
  • Dropped obsolete partial templates in examples: Removed legacy template syntax from generate prompt strings.
  • Docstring return shape updates: Updated return signature annotations and # => examples to match current runtime.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates documentation, READMEs, and samples across the Genkit Python SDK to align with recent API changes, including model reference updates, streaming context managers, and middleware hooks. The review feedback suggests improving the PII redaction middleware sample by using model_copy to preserve metadata on Part objects and considering structured tool outputs for robustness.

Comment on lines +37 to +38
def _redact_parts(parts: list[Part]) -> list[Part]:
return [Part.from_text(_redact(p.text), metadata=p.metadata) if p.text is not None else p for p in parts]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of manually reconstructing the Part object using Part.from_text, you can use p.model_copy(update={'text': _redact(p.text)}). This is more idiomatic for Pydantic models and ensures that all other fields on the Part object (such as custom or other metadata) are safely preserved.

Suggested change
def _redact_parts(parts: list[Part]) -> list[Part]:
return [Part.from_text(_redact(p.text), metadata=p.metadata) if p.text is not None else p for p in parts]
def _redact_parts(parts: list[Part]) -> list[Part]:
return [p.model_copy(update={'text': _redact(p.text)}) if p.text is not None else p for p in parts]

Comment on lines +75 to +77
if isinstance(result.output, str):
update['output'] = _redact(result.output)
if result.content:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While checking isinstance(result.output, str) works perfectly for this sample tool (which returns a flat string), in real-world applications, tool outputs are often structured objects (such as dictionaries or Pydantic models). Consider adding a comment or handling nested structures to make this middleware example more robust and educational for users.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

Closing: migrated to standalone repository genkit-ai/genkit-python (PR #44): genkit-ai/genkit-python#44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant