Skip to content

fix(py): hotfix anthropic dependency cap and flask[async] - #7132

Closed
huangjeff5 wants to merge 3 commits into
mainfrom
fix/py-0.13.1-hotfix-pins
Closed

huangjeff5 wants to merge 3 commits into
mainfrom
fix/py-0.13.1-hotfix-pins

Conversation

@huangjeff5

Copy link
Copy Markdown
Contributor

Hotfixes dependency issues in genkit-anthropic and genkit-flask that caused fresh venv installations from PyPI to fail on runtime calls.

Main Changes

  • Capped Anthropic below 1.0: Anthropic SDK 1.0+ dropped sampling parameters (temperature, top_p, top_k) from AsyncMessages.create() and migrated transport to httpx2. We pinned genkit-anthropic to anthropic>=0.96.0,<1.0.0 to prevent TypeError: AsyncMessages.create() got an unexpected keyword argument 'temperature'.
  • Added async extra to Flask dependency: genkit-flask previously depended on plain flask. Without asgiref, running an async route threw 500 RuntimeError: Install Flask with the 'async' extra. We updated the dependency to flask[async].
  • Isolated wheel verification: Added an isolated wheel smoke check (py/bin/check_isolated_wheels) to verify every built wheel installs and imports cleanly in a fresh virtual environment.

anthropic 1.0.0 removed temperature/top_p/top_k from messages.create()
and moved the transport to httpx2. genkit-anthropic forwards those kwargs
and catches httpx exceptions, so every fresh install that resolved
anthropic>=1 raised TypeError on sampling config. Cap at <1 until the
plugin is adapted (BL-22).
genkit_flask_handler returns an async view. Flask needs asgiref (the
async extra) to run it; without it the first request fails with
'Install Flask with the async extra'. The monorepo venv masked this
because genkit-django pulls asgiref.
The workspace venv carries every package's dependencies, so a package
that forgets one (genkit-flask without flask[async]) passes CI and
breaks on PyPI. check_isolated_wheels installs each built genkit wheel
into its own venv and imports it, with targeted smokes for genkit-flask
(async view request) and genkit-anthropic (SDK create() signature).

@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 introduces isolated wheel smoke-testing via a new bash script, restricts the anthropic dependency to under version 1.0 in genkit-anthropic, and updates genkit-flask to require flask[async]. It also adds corresponding contract and dependency tests. The review feedback points out a potential issue in the test files where the regular expressions used to match package names could incorrectly match other packages starting with those names (such as flask-hello) because hyphens are treated as word boundaries. Using negative lookaheads is recommended to make the package name matching more robust.


def test_declared_anthropic_range_excludes_1x() -> None:
"""``genkit-anthropic`` caps ``anthropic`` below 1.0 until it supports 1.x."""
reqs = [r for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)]

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

The regular expression anthropic\b matches any package name starting with anthropic- (such as anthropic-perspective) because the hyphen - is a non-word character, which satisfies the \b word boundary. If any such dependency is added in the future, this test will incorrectly include it in reqs and fail.

To prevent this, use a negative lookahead to ensure that the character following anthropic is not a valid package name character (i.e., not alphanumeric, underscore, hyphen, or period).

Suggested change
reqs = [r for r in requires('genkit-anthropic') or [] if re.match(r'anthropic\b', r)]
reqs = [r for r in requires('genkit-anthropic') or [] if re.match(r'anthropic(?![a-zA-Z0-9_.-])', r, re.IGNORECASE)]


def test_declares_flask_async_extra() -> None:
"""``genkit-flask`` requires ``flask[async]``, not bare ``flask``."""
reqs = [r for r in requires('genkit-flask') or [] if re.match(r'flask\b', r, re.IGNORECASE)]

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

The regular expression flask\b matches any package name starting with flask- (such as flask-cors or flask-hello) because the hyphen - is a non-word character, which satisfies the \b word boundary. If any such dependency is added to genkit-flask in the future, this test will incorrectly include it in reqs and fail.

To prevent this, use a negative lookahead to ensure that the character following flask is not a valid package name character (i.e., not alphanumeric, underscore, hyphen, or period).

Suggested change
reqs = [r for r in requires('genkit-flask') or [] if re.match(r'flask\b', r, re.IGNORECASE)]
reqs = [r for r in requires('genkit-flask') or [] if re.match(r'flask(?![a-zA-Z0-9_.-])', r, re.IGNORECASE)]

@huangjeff5

Copy link
Copy Markdown
Contributor Author

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

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