Make importing and instantiating the client work the same way as before
Closed this issue · 8 comments
This should work in the new client, for consistency with the legacy client:
import replicateThis doesn't necessarily have to be the default or only way to import and instantiate, but it should continue to work for feature parity, and to minimize code changes for users upgrading.
Tasks
- Update README
- Update examples
- Update generated SDK docs
@zeke this should already work! see references to the "module client" https://github.com/replicate/replicate-python-stainless/blob/84a6a427de6be2d49f8ae5a165576be19d1bb4d1/src/replicate/_module_client.py#L70
import replicate
replicate.models.create(...)One useful way we can test this besides combing documentation is to actually swap out the client in some existing codebases and see if everything still works.
Here are some examples: https://replicate.com/docs/reference/open-source#demo-apps
Bump @dgellow @RobertCraigie
See https://github.com/replicate/replicate-typescript-stainless/issues/8 for context on the changes made in the TypeScript SDK.
While it isn't quite the same as your existing snippets yet, we did add b320609 (sorry for the bad commit message).
Though, while the examples are now using replicate = instead of client =, the import will still be from replicate import Replicate. And not the simplified import replicate Zeke mentioned initially.
Robert will correct me if I'm wrong here, but I do not believe that we currently have plans to support generating import <python project>, it's a bit too niche of a use case.
@zeke Given that you mentioned it is ok for import replicate to not be the default, should we consider this issue to be completed now that we generate replicate = for all examples?
I understand it's niche, but this is so much leaner:
import replicate
replicate.models.create(
hardware="cpu",
name="hot-dog-detector",
owner="alice",
visibility="public",
)Than this:
import os
from replicate import Replicate
replicate = Replicate(
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
)
replicate.models.create(
hardware="cpu",
name="hot-dog-detector",
owner="alice",
visibility="public",
)I wonder if there is some creative way we can pull this off... 🤔
Note: The shorter code above actually works!
It's just a matter of making it show up in the documentation that way.
