Skip to content

Conversation

@zeke
Copy link
Member

@zeke zeke commented Sep 24, 2025

This PR adds backward compatibility for the legacy models.get("owner/name") format while maintaining full compatibility with the new models.get(model_owner="owner", model_name="name") format.

Changes

  • Modified the get() method in both sync and async ModelsResource classes to accept an optional positional argument for legacy format
  • Added comprehensive error handling with clear messages for invalid usage
  • Added extensive test coverage for both sync and async versions
  • Supports complex model names with hyphens, numbers, and multiple slashes

Implementation Approach

The implementation directly modifies the generated get() method to:

  • Accept model_or_owner as an optional positional parameter
  • Parse and validate "owner/name" strings with clear error messages
  • Maintain all existing functionality and parameters
  • Work seamlessly with both sync and async versions

This approach is 50% less code than a patching system and integrates cleanly with the existing codebase structure.

Testing locally

gh repo clone replicate/replicate-python-stainless
cd replicate-python-stainless  
gh pr checkout feat/models-backward-compatibility
pip install -e .
python -c "
import replicate
client = replicate.Client(api_token='your-token')
# Legacy format
model = client.models.get('stability-ai/stable-diffusion')
# New format  
model = client.models.get(model_owner='stability-ai', model_name='stable-diffusion')
print('Both formats work!')
"

This adds support for the legacy models.get("owner/name") format while maintaining
compatibility with the new models.get(model_owner="owner", model_name="name") format.

The implementation directly modifies the generated get() method to:
- Accept an optional positional argument for "owner/name" strings
- Parse and validate the format with clear error messages
- Support both sync and async versions
- Maintain all existing functionality and parameters

This approach is 50% less code than a patching system and integrates cleanly
with the existing codebase structure.
@zeke zeke requested a review from a team as a code owner September 24, 2025 19:36
@stainless-app stainless-app bot force-pushed the next branch 2 times, most recently from 6f10116 to 2804bd6 Compare September 29, 2025 19:58
Copy link
Collaborator

@dgellow dgellow left a comment

Choose a reason for hiding this comment

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

Reviewing my own implementation :)

@zeke
Copy link
Member Author

zeke commented Oct 10, 2025

Per our discussion IRL yesterday, let's scrap this. If it turns out to be a big issue for users we can consider supporting it.

This change between v1 and v2 is covered in the migration guide: #76

@zeke zeke closed this Oct 10, 2025
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.

3 participants