Repository navigation
fix(py): align quickstart, readme examples, and docstrings with 1.0 runtime - #7135
huangjeff5 wants to merge 15 commits into
Conversation
…ne_helper, plugin error)
…ngo 5.0 requirement
…d image/Veo ids in docstrings
…results, close streams in fastapi README
…mini rejects the combination)
There was a problem hiding this comment.
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.
| 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] |
There was a problem hiding this comment.
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.
| 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] |
| if isinstance(result.output, str): | ||
| update['output'] = _redact(result.output) | ||
| if result.content: |
There was a problem hiding this comment.
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.
|
Closing: migrated to standalone repository genkit-ai/genkit-python (PR #44): genkit-ai/genkit-python#44 |
Aligns documentation, READMEs, and docstrings with the 1.0 runtime contracts and verified against a fresh
uv initproject.Main Changes
py/README.mdruns end-to-end without extra undocumented packages.# =>examples to match current runtime.