Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing keyword args to data in JS client #8197

Merged
merged 39 commits into from
May 10, 2024

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented May 2, 2024

Description

This PR adds support for passing keyword arguments as well as positional args to the data param in the JS client. This is backwards compatible, so the two usages will work:

const result = await app.predict("/predict", ["Chewbacca"]);
const result = await app.predict("/predict", { name: "Chewbacca" });

Also adds unit tests.

The CodeSnippet.svelte API usage has been updated, which you can see here: https://huggingface.co/spaces/hmb/test_args

Closes: #7831

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 2, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/bdd46e939181c30b67e55df1ce696932ab662b19/gradio-4.29.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@bdd46e939181c30b67e55df1ce696932ab662b19#subdirectory=client/python"

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 2, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/app minor
@gradio/client minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Add support for passing keyword args to data in JS client

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@hannahblair hannahblair requested review from abidlabs and pngwn May 2, 2024 13:10
@hannahblair
Copy link
Collaborator Author

hannahblair commented May 2, 2024

todo: need to update codesnippet.svelte

@hannahblair hannahblair marked this pull request as draft May 2, 2024 14:35
@hannahblair hannahblair changed the title Add support for keyword args when passing data in JS client Add support for passing keyword args to data in JS client May 2, 2024
@hannahblair hannahblair marked this pull request as ready for review May 9, 2024 11:50
Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Just left one small comment but everything else looks great + works as expected!

Thanks @hannahblair!

client/js/src/helpers/api_info.ts Outdated Show resolved Hide resolved
@abidlabs
Copy link
Member

abidlabs commented May 9, 2024

Nice @hannahblair! Just 2 nits with regards to the code snippets:

image
  • The code snippet itself looks good, but in the parameter table below, we should now put the name of the parameter, instead of the [0] to designate the positional argument
  • We can also remove the comment // string in... as that information is included in the parameter table

Matching the Python code snippet and parameter table:

image
  1. The RecordingSnippet.svelte code snippet still shows the positional format, would be great if we can update this as well:
image

@hannahblair
Copy link
Collaborator Author

thanks @pngwn @abidlabs! made those changes.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Tested and looks good, will file another issue for the API recorder because it is broken in the release.

@hannahblair hannahblair merged commit e09b4e8 into main May 10, 2024
8 checks passed
@hannahblair hannahblair deleted the js-client-kwargs branch May 10, 2024 17:46
@pngwn pngwn mentioned this pull request May 10, 2024
This was referenced Jun 6, 2024
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.

Add support for key-word arguments in JS client
4 participants