Skip to content

Conversation

@stainless-app
Copy link
Contributor

@stainless-app stainless-app bot commented Aug 28, 2025

Automated Release PR

2.0.0-alpha.22 (2025-08-28)

Full Changelog: v2.0.0-alpha.21...v2.0.0-alpha.22

Bug Fixes

  • implement lazy client creation in replicate.use() (#57) (caf4c4e)

This pull request is managed by Stainless's GitHub App.

The semver version number is based on included commit messages. Alternatively, you can manually set the version number in the title of this pull request.

For a better experience, it is recommended to use either rebase-merge or squash-merge when merging this pull request.

🔗 Stainless website
📚 Read the docs
🙋 Reach out for help or questions

zeke and others added 2 commits August 28, 2025 10:03
* fix: implement lazy client creation in replicate.use()

Fixes issue where replicate.use() would fail if no API token was available at call time,
even when token becomes available later (e.g., from cog.current_scope).

Changes:
- Modified Function/AsyncFunction classes to accept client factories
- Added _client property that creates client on demand
- Updated module client to pass factory functions instead of instances
- Token is now retrieved from current scope when model is called

This maintains full backward compatibility while enabling use in Cog pipelines
where tokens are provided through the execution context.

* style: fix linter issues

- Remove unused *args parameter in test function
- Fix formatting issues from linter

* fix: resolve async detection and test issues

- Fix async detection to not call client factory prematurely
- Add use_async parameter to explicitly indicate async mode
- Update test to avoid creating client during verification
- Fix test mocking to use correct module path

* test: simplify lazy client test

Replace complex mocking test with simpler verification that:
- use() works without token initially
- Lazy client factory is properly configured
- Client can be created when needed

This avoids complex mocking while still verifying the core functionality.

* lint

* fix: add type ignore for final linter warning

* fix: add arg-type ignore for type checker warnings

* refactor: simplify lazy client creation to use Type[Client] only

Address PR feedback by removing Union types and using a single consistent approach:

- Change Function/AsyncFunction constructors to accept Type[Client] only
- Remove Union[Client, Type[Client]] in favor of just Type[Client]
- Simplify _client property logic by removing isinstance checks
- Update all use() overloads to accept class types only
- Use issubclass() for async client detection instead of complex logic
- Update tests to check for _client_class attribute

This maintains the same lazy client creation behavior while being
much simpler and more consistent.

* Update tests/test_simple_lazy.py

Co-authored-by: Aron Carroll <aron@aroncarroll.com>

* test: improve lazy client test to follow project conventions

- Remove verbose comments and print statements
- Focus on observable behavior rather than internal implementation
- Use proper mocking that matches actual cog integration
- Test that cog.current_scope() is called on client creation
- Address code review feedback from PR discussion

* lint

* lint

---------

Co-authored-by: Aron Carroll <aron@aroncarroll.com>
@stainless-app stainless-app bot requested a review from a team as a code owner August 28, 2025 17:03
@stainless-app
Copy link
Contributor Author

stainless-app bot commented Aug 28, 2025

🧪 Testing

To try out this version of the SDK, run:

pip install 'https://pkg.stainless.com/s/replicate-client-python/caf4c4efa2be271144b22b93a38ea490b10ad86b/replicate-2.0.0a21-py3-none-any.whl'

Expires: Sat, 27 Sep 2025 17:03:51 GMT

@zeke zeke merged commit 2959d2d into main Aug 28, 2025
7 checks passed
@zeke zeke deleted the release-please--branches--main--changes--next branch August 28, 2025 17:16
@stainless-app
Copy link
Contributor Author

stainless-app bot commented Aug 28, 2025

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants