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

Proposal: widget types #980

Merged
merged 12 commits into from
Sep 29, 2023
Merged

Proposal: widget types #980

merged 12 commits into from
Sep 29, 2023

Conversation

SBrandeis
Copy link
Contributor

…s/WidgetInputSamples.svelte

Co-authored-by: Julien Chaumond <[email protected]>
@julien-c julien-c marked this pull request as ready for review September 29, 2023 14:12
import type { WidgetExample } from "../WidgetExample";
type T = $$Generic<WidgetExample>;
Copy link
Collaborator

@mishig25 mishig25 Sep 29, 2023

Choose a reason for hiding this comment

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

like TOutput, maybe a more descriptive name like TWidgetInput or TWidgetExample would make it clear. If so, should apply to other files as well

Copy link
Member

Choose a reason for hiding this comment

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

you prefer this syntax to the generics="T extends WidgetExample"> syntax BTW @SBrandeis?

(i think both are equivalent no?)

Copy link
Collaborator

@mishig25 mishig25 left a comment

Choose a reason for hiding this comment

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

Except this nit & failing svelte-check, lgtm!

Comment on lines +38 to 40
export interface WidgetExampleTextAndTableInput<TOutput = WidgetExampleOutput> extends WidgetExampleTextInput<TOutput> {
table: (string | number)[][];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this one is not compatible with the server-side validation of https://github.com/huggingface/moon-landing/pull/7601 @julien-c

Copy link
Member

Choose a reason for hiding this comment

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

arf yes, correct. will fix the moon-landing PR

function _isZeroShotTextInput<TOutput>(
sample: WidgetExample<TOutput>
): sample is Exclude<WidgetExampleZeroShotTextInput<TOutput>, "text"> {
return "candidate_labels" in sample && "multi_class" in sample;
Copy link
Member

Choose a reason for hiding this comment

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

you don't check the types because you trust moon-landing validation, is that correct?

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

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

LOVE IT ❤️❤️❤️

@SBrandeis SBrandeis merged commit 5b91fc5 into widgets-typing Sep 29, 2023
2 checks passed
@SBrandeis SBrandeis deleted the proposal-widgets-type branch September 29, 2023 16:06
julien-c added a commit that referenced this pull request Sep 29, 2023
* Typings for all kinds of widget examples

* Add a //#region block

* Tweaks

* Fix some part of the CI already(?)

cc @krampstudio @mishig25 for review 🙏

* Revert "Fix some part of the CI already(?)"

This reverts commit 3e89028.

* nvm, probably better like this

* sorry this was wrong

* 🤯 Use generics in Svelte (i guess...)

* Proposal: widget types (#980)

* wip

* 🩹 Fix types in widgets

* 🩹 Minimize diff

* 💄 Lint

* Update js/src/lib/components/InferenceWidget/shared/WidgetInputSamples/WidgetInputSamples.svelte

Co-authored-by: Julien Chaumond <[email protected]>

* 🧹 cleanup unwanted change

* 🩹 wip: type safety

* ✨ Typing & validation for ALL widgets

* ♻️ Slightly less verbose version

* 🩹

* 🩹 Import type?

* 🩹 Alternative generic syntax to satisfy svelte-check

---------

Co-authored-by: Julien Chaumond <[email protected]>

* 💄 Lint & checks

* Go for same syntax everywhere

---------

Co-authored-by: Simon Brandeis <[email protected]>
Co-authored-by: SBrandeis <[email protected]>
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