Repository navigation
feat(py)!: build data objects with their class; rename evaluator types before 1.0 - #6682
Conversation
There was a problem hiding this comment.
Code Review
This pull request renames several core concepts and types in Genkit Python, including changing 'response' to 'tool_response', 'EvalStatusEnum' to 'EvalStatus', and 'Details' to 'ScoreDetails'. It also moves 'BaseDataPoint' to the 'genkit.evaluator' module and removes unsupported action kinds ('reranker', 'indexer', 'retriever'), updating key parsing and reflection endpoints to return a 404 error instead of a server error for invalid keys. Feedback on the changes suggests restoring a deleted test for metadata validation using the new 'tool_response' function to preserve test coverage.
I am having trouble creating individual review comments. Click here to see my feedback.
py/packages/genkit/tests/genkit/ai/tool_multipart_test.py (110-116)
The test test_response_rejects_non_dict_metadata was removed, but the validation logic in _tools.py remains. This test should be updated to use tool_response instead of being removed to maintain test coverage.
def test_tool_response_rejects_non_dict_metadata() -> None:
with pytest.raises(GenkitError) as ei:
tool_response(1, metadata='nope') # type: ignore[arg-type]
assert ei.value.status == 'INVALID_ARGUMENT'
assert ei.value.reason is RuntimeErrorReason.INVALID_INPUT
assert 'metadata' in ei.value.original_message
assert 'INVALID_INPUT' not in ei.value.original_message
- Tools return `tool_response(output, parts=..., metadata=...)` instead of
`response(...)`; error messages now say `tool_response()`.
- `BaseDataPoint` is imported from `genkit.evaluator` instead of `genkit`.
- Evaluators build `Score(status=EvalStatus.PASS, details=ScoreDetails(...))`
instead of `EvalStatusEnum` / `Details`. The JSON is the same ('PASS',
details.reasoning).
- `ActionKind` no longer has `RETRIEVER`, `INDEXER`, or `RERANKER`.
- Running an action key the Dev UI can't parse (for example '/retriever/x' or
'/tool/x') returns 404 "Action not found" instead of a 500, and the
JSON-RPC runAction returns its usual not-found error.
a9ba105 to
f880a9c
Compare
|
Re gemini's metadata test note: valid, that one got dropped in the rename by accident. Restored as |
Score.status, Score.details now read as one family: Score, ScoreStatus, ScoreDetails. EvalStatus read like the status of a whole eval run. Wire values (PASS/FAIL/UNKNOWN) are unchanged. Matches Go's ScoreStatus.
Genkit Python has no reranker primitive, so Bedrock.rerank() was a one-off plugin method with its own request/response types. Drop it, its exported types, the rerank-model resolve guard, tests, and docs before the plugin's first release. It can come back as a registered reranker action once core has one.
Rerank models have no Converse path and the plugin registers no reranker action, so bedrock/cohere.rerank-* declines at resolve instead of failing on the first call. is_rerank_model moves to model_info as pure ID routing.
# Conflicts: # py/docs/index.md # py/docs/types.md # py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py # py/packages/genkit/src/genkit/__init__.py # py/packages/genkit/src/genkit/evaluator/__init__.py # py/packages/genkit/tests/genkit/veneer/veneer_test.py # py/samples/evaluators/src/main.py
# Conflicts: # py/packages/genkit-amazon-bedrock/CHANGELOG.md # py/packages/genkit-amazon-bedrock/README.md # py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/__init__.py # py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/_plugin.py # py/packages/genkit-amazon-bedrock/tests/live_test.py # py/packages/genkit-amazon-bedrock/tests/plugin_test.py # py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/__init__.py
# Conflicts: # py/packages/genkit-google-genai/src/genkit_google_genai/_evaluators/_evaluation.py
…r functions - Remove tool_response(); construct MultipartToolResponse(output=, content=, metadata=). Its argument checks move onto the class. - Remove new_middleware, embedder_ref, and evaluator_ref in favor of GenerateMiddleware, EmbedderRef, and EvaluatorRef. - Document.from_text/from_media are classmethods. - Share the reflection run-key guard as resolve_runnable_key. - Bedrock README: rerank IDs don't resolve on demand.
A few public names change before 1.0 so the API reads the same way everywhere: if you're building a data object, you call its class.
MultipartToolResponse(...)directly. Theresponsehelper is removed. Build the class you already annotate, withcontent=for the parts.new_middleware,embedder_ref, andevaluator_refare removed. UseGenerateMiddleware(cls=..., name=...),EmbedderRef(name=...), andEvaluatorRef(name=...).EvalStatusEnumis nowScoreStatus, andDetailsis nowScoreDetails. Serialized values don't change ("status": "PASS","details": {"reasoning": ...}).ActionKind.RETRIEVER,ActionKind.INDEXER, andActionKind.RERANKERare removed.Document.from_textandDocument.from_mediaare classmethods, so aDocumentsubclass gets its own type back./retriever/x) now returns 404 "Action not found" instead of a 500.Writing tools
A tool returns its value, or a
MultipartToolResponsewhen it also sends media:Answering an interrupt is unchanged:
interrupt.respond(output)andinterrupt.restart(resumed_metadata=...)build the reply from the interrupt you hold.Decisions
MultipartToolResponse(...),Score(...),EvaluatorRef(...).Part.from_media(url, content_type=...).interrupt.respond(...).parts=vscontent=).new_middlewarealso droppedmetadata=.MultipartToolResponseover a renamed helper.tool_responsecollided withPart.tool_responseandToolResponsePart(tool_response=...). It also read like it built aToolResponse, soPart(tool_response=tool_response(...))looked right but was the wrong type. The class name matches Go'sMultipartToolResponse{Output, Content, Metadata}and the wire'soutput/content/metadata.MultipartToolResponserejects non-dictmetadataand non-partcontentwith the sameINVALID_ARGUMENTstatus and reason the helper raised. The messages now name the class, for exampleMultipartToolResponse metadata must be a dict, got str.Parts with no payload, or with data that can't be serialized to JSON, fail when the tool returns, with an error that names the tool.Score.statusandScore.detailsread as one family:Score,ScoreStatus,ScoreDetails.EvalStatusread like the status of a whole eval run, andDetailsdidn't say what it held. Go already usesScoreStatusand a generatedScoreDetails. JS and the tools schema keepEvalStatusEnumon the wire-schema side.ActionKindvalues are gone. Adding enum values later is safe, but removing them after 1.0 isn't. If your plugin referencedActionKind.RETRIEVER, drop it.Also
genkit-amazon-bedrockREADME now says rerank model IDs don't resolve on demand. The plugin already declines them.genkit-evaluators, the google-genai Vertex evaluators, and theevaluatorsandmultipart-toolssamples use the new names.