Skip to content

feat(client): first pass at .run() helper#5

Merged
zeke merged 34 commits into
nextfrom
sam/run-helper
May 8, 2025
Merged

feat(client): first pass at .run() helper#5
zeke merged 34 commits into
nextfrom
sam/run-helper

Conversation

@dgellow

@dgellow dgellow commented Apr 17, 2025

Copy link
Copy Markdown
Collaborator

Part of #11

@dgellow dgellow requested a review from zeke April 17, 2025 14:56
@dgellow

dgellow commented Apr 17, 2025

Copy link
Copy Markdown
Collaborator Author

@zeke It's the same version that has been discussed in the staging repo. Do you want to already merge it as-is?

@dgellow dgellow marked this pull request as ready for review April 17, 2025 17:16
@dtmeadows

Copy link
Copy Markdown
Collaborator

@zeke / @dgellow tested this live and this was the result!

image

@zeke

zeke commented Apr 18, 2025

Copy link
Copy Markdown
Member

what was the prompt!!? haha

@mpatankar

Copy link
Copy Markdown

Added context from staging repo: https://github.com/stainless-sdks/replicate-client-python/pull/5

Comment thread examples/demo.py Outdated
Comment thread src/replicate/types/prediction_create_params.py
Comment thread src/replicate_client/lib/.keep

@zeke zeke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for opening this, @dgellow

A few thoughts:

  • Can you add a description to the PR body with a summary of the changes? What's covered? What's missing?
  • There seem to be a lot of changes to the auto-generated code here. Are there any mitigations we can make here to minize that? Moving code to lib, adding code comments around human code, moving human code to a separate block in the file, etc.?
  • Is it possible to add some tests?

@dgellow

dgellow commented Apr 23, 2025

Copy link
Copy Markdown
Collaborator Author

There seem to be a lot of changes to the auto-generated code here. Are there any mitigations we can make here to minize that? Moving code to lib, adding code comments around human code, moving human code to a separate block in the file, etc.?

I think that we already extracted to ./lib everything that could be. For example the new error class ModelError cannot be extracted to ./lib without resulting in an import cycle (./lib imports _exceptions.py, which itself imports ./lib) due to the inheritance.

But I can add comments around the custom code if you would find this helpful

Edit: Paraphrasing what I said in Slack:

I'm really not too sure about adding region comments to delimitate human code vs generated code. The main issue I see is that there is no guarantee they will stay correct over time, it is possible that a git operation ends up with generated code between those comments. So that would be something that you have to maintain yourself.

What I would instead recommend is to document branch comparison in CONTRIBUTING.md, such as https://github.com/replicate/replicate-typescript-stainless/compare/generated..next.
By comparing generated and next you always get the current state of human-code (aka custom code).

@dgellow

dgellow commented Apr 23, 2025

Copy link
Copy Markdown
Collaborator Author

Still a bit of work to do on tests — I'm using https://github.com/replicate/replicate-python/blob/main/tests/test_run.py for the list of test cases.
Then I will add a PR description to clarify the scope of this PR.

@zeke

zeke commented Apr 24, 2025

Copy link
Copy Markdown
Member

Awesome! Excited to see the progress.

@zeke

zeke commented May 5, 2025

Copy link
Copy Markdown
Member

I've created an issue to track this work:

I know this PR has been tossed around a bit as folks move on and off of projects, or are on leave.

@mpatankar who is the current owner of this?

@mpatankar

Copy link
Copy Markdown

@RobertCraigie is the assignee and the one who will see this through! Assigned him to the issue you created

@dtmeadows dtmeadows requested a review from RobertCraigie May 6, 2025 16:37
Comment thread pyproject.toml Outdated
"anyio>=3.5.0, <5",
"distro>=1.7.0, <2",
"sniffio",
"asyncio>=3.4.3",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this isn't quite right, asyncio is stdlib

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fixed!

@zeke

zeke commented May 6, 2025

Copy link
Copy Markdown
Member

Thanks for the update, @dtmeadows. Great to see this getting close!

@dtmeadows

Copy link
Copy Markdown
Collaborator

@zeke this is ready for your review! The only remaining pending item is the file upload functionality that we discussed here: https://stainless-workspace.slack.com/archives/C08H2L2E0KT/p1745613017872449

Would your preference be for us to wait and have that be code-generated (once it's added to your OpenAPI spec) or to just manually create the endpoint for now?

@zeke

zeke commented May 7, 2025

Copy link
Copy Markdown
Member

Amazing! Great timing.

I actually just shipped a change to our OpenAPI schema to document the Files API, so we can generate them. That should be live in production within the next few minutes.

Screenshot 2025-05-07 at 10 52 05

Comment thread examples/run_a_model.py Outdated
Comment thread examples/run_async.py Outdated

from replicate import AsyncReplicate

client = AsyncReplicate()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we rename client to replicate here? Will that work?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

done!

(we can't change the from replicate import AsyncReplicate unfortunately though here, since the module client only returns the sync client)

@zeke zeke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is looking great. Left a few small suggestions but nothing major.

Happy to ship this without File upload support. It would probably be easier to review that in a separate PR anyway.

@dtmeadows dtmeadows linked an issue May 7, 2025 that may be closed by this pull request
5 tasks
@dtmeadows

Copy link
Copy Markdown
Collaborator

This is looking great. Left a few small suggestions but nothing major.

Happy to ship this without File upload support. It would probably be easier to review that in a separate PR anyway.

Sounds good! I've added file upload support on this branch: dmeadows/use-files-in-run. I'll open a PR for that once this goes in.

@dtmeadows dtmeadows requested review from RobertCraigie and zeke May 8, 2025 17:16
@dtmeadows

Copy link
Copy Markdown
Collaborator

@zeke I think this is good to merge in now! You okay blessing it with your approval?

@zeke zeke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Whoop whoop! :shipit:

@zeke zeke merged commit 686d4d7 into next May 8, 2025
2 checks passed
@dgellow dgellow deleted the sam/run-helper branch July 31, 2025 14:34
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.

Implement replicate.run() method for Python client

5 participants