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

fix(client): fix js compatible with multi args in online eval #1728

Merged
merged 1 commit into from
Jan 28, 2023

Conversation

jialeicui
Copy link
Contributor

@jialeicui jialeicui commented Jan 28, 2023

Description

The problem:

image

The reason:

gradio will make sure the return value is a list

dependencies.forEach((d) => {
if (d.js) {
	try {
		d.frontend_fn = new AsyncFunction(
			"__fn_args",
			`let result = await (${d.js})(...__fn_args);
			return ${d.outputs.length} === 1 ? [result] : result;`
		);
	} catch (e) {
		console.error("Could not parse custom js method.");
		console.error(e);
	}
}
});

ref: https://github.com/gradio-app/gradio/blob/v3.15.0/ui/packages/app/src/Blocks.svelte#L67

gradio expands the payload.data.concat(output_data) as fn_args

So, when there is only one output, nothing wrong, and when there are multiple outputs, we return the wrong response.

if (frontend_fn !== undefined) {
	payload.data = await frontend_fn(payload.data.concat(output_data));
}

ref: https://github.com/gradio-app/gradio/blob/v3.15.0/ui/packages/app/src/api.ts#L102

gradio docs:
https://www.gradio.app/custom-CSS-and-JS/

Modules

  • UI
  • Controller
  • Agent
  • Client
  • Python-SDK
  • Others

Checklist

  • run code format and lint check
  • add unit test
  • add necessary doc

@codecov
Copy link

codecov bot commented Jan 28, 2023

Codecov Report

Merging #1728 (a4e66c8) into main (d6ea14c) will increase coverage by 7.94%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #1728      +/-   ##
============================================
+ Coverage     82.27%   90.22%   +7.94%     
============================================
  Files           352       79     -273     
  Lines         18967     9634    -9333     
  Branches       1030        0    -1030     
============================================
- Hits          15606     8692    -6914     
+ Misses         2932      942    -1990     
+ Partials        429        0     -429     
Flag Coverage Δ
controller ?
standalone 90.22% <100.00%> (ø)
unittests 90.22% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/starwhale/api/_impl/service.py 94.66% <100.00%> (ø)
...set/dataloader/converter/DataReadLogConverter.java
...rwhale/mlops/domain/job/spec/ModelServingSpec.java
...lops/domain/job/step/status/StepStatusMachine.java
...starwhale/mlops/schedule/k8s/K8sTaskScheduler.java
...le/mlops/domain/dataset/dataloader/DataLoader.java
...java/ai/starwhale/mlops/domain/model/ModelDao.java
...n/java/ai/starwhale/mlops/domain/task/bo/Task.java
...n/dataset/dataloader/mapper/DataReadLogMapper.java
...va/ai/starwhale/mlops/storage/fs/FileIterator.java
... and 264 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@waynelwz waynelwz left a comment

Choose a reason for hiding this comment

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

LGTM

@waynelwz waynelwz changed the title fix(client): fix js in online eval fix(client): fix js compatible with multi args in online eval Jan 28, 2023
@waynelwz waynelwz merged commit d880b75 into star-whale:main Jan 28, 2023
@jialeicui jialeicui deleted the fix-js branch January 28, 2023 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working client 🌈
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants