-
Notifications
You must be signed in to change notification settings - Fork 260
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
[Widgets] Refactor examples running #1023
Changes from 23 commits
667710d
85aac2e
c56c64f
aa2396e
d2374e4
d5325f9
2730c9c
3ba2298
7858186
fd40b25
756223d
580c830
f89936c
0654367
94249c4
353f172
23a2fe0
c36fcdc
06420aa
44eb4f1
ada2b70
37f2ccd
8446c3e
7ebca52
c89086b
4d03786
9ea310a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<script lang="ts"> | ||
import type { WidgetProps, ModelLoadInfo } from "../types"; | ||
import type { WidgetProps, ModelLoadInfo, ExampleRunOpts } from "../types"; | ||
import type { WidgetExample } from "../WidgetExample"; | ||
import type { QueryParam } from "../../shared/helpers"; | ||
|
||
type TWidgetExample = $$Generic<WidgetExample>; | ||
|
||
|
@@ -13,10 +14,11 @@ | |
import WidgetHeader from "../WidgetHeader/WidgetHeader.svelte"; | ||
import WidgetInfo from "../WidgetInfo/WidgetInfo.svelte"; | ||
import WidgetModelLoading from "../WidgetModelLoading/WidgetModelLoading.svelte"; | ||
import { getModelLoadInfo } from "../../shared/helpers"; | ||
import { getModelLoadInfo, getQueryParamVal, getWidgetExample } from "../../shared/helpers"; | ||
import { modelLoadStates } from "../../stores"; | ||
|
||
export let apiUrl: string; | ||
export let callApiOnMount: WidgetProps["callApiOnMount"]; | ||
export let computeTime: string; | ||
export let error: string; | ||
export let isLoading = false; | ||
|
@@ -28,9 +30,9 @@ | |
}; | ||
export let noTitle = false; | ||
export let outputJson: string; | ||
export let applyInputSample: (sample: TWidgetExample) => void = () => {}; | ||
export let previewInputSample: (sample: TWidgetExample) => void = () => {}; | ||
export let applyInputSample: (sample: TWidgetExample, opts?: ExampleRunOpts) => void = () => {}; | ||
export let validateExample: (sample: WidgetExample) => sample is TWidgetExample; | ||
export let exampleQueryParams: QueryParam[] = []; | ||
|
||
let isMaximized = false; | ||
let modelLoadInfo: ModelLoadInfo | undefined = undefined; | ||
|
@@ -64,6 +66,21 @@ | |
(async () => { | ||
modelLoadInfo = await getModelLoadInfo(apiUrl, model.id, includeCredentials); | ||
$modelLoadStates[model.id] = modelLoadInfo; | ||
|
||
// run widget example | ||
if (exampleQueryParams.length) { | ||
const example = {} as TWidgetExample; | ||
for (const key of exampleQueryParams) { | ||
const val = getQueryParamVal(key); | ||
example[key] = val; | ||
} | ||
applyInputSample(example); | ||
} else { | ||
const example = getWidgetExample<TWidgetExample>(model, validateExample); | ||
if (callApiOnMount && example) { | ||
mishig25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
applyInputSample(example, { inferenceOpts: { isOnLoadCall: true } }); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm not mistaken, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I tested it and I can confirm this behavior! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything that needs to be changed here?
I think this is the existing behaviour on main There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes
No Sorry I think my wording was not clear here. I'll try to reformulate. On main (hf.co)When accessing for example HuggingFaceH4/zephyr-7b-alpha, The widget picksan example at random and starts generating (expected behavior). On this branchThe widget does not try to get the example from the Let me know if anything remains unclear 🤗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, fixed the logic 7ebca52 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure but |
||
})(); | ||
}); | ||
|
||
|
@@ -107,7 +124,6 @@ | |
{isLoading} | ||
inputSamples={selectedInputSamples?.inputSamples ?? []} | ||
{applyInputSample} | ||
{previewInputSample} | ||
/> | ||
</div> | ||
{/if} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be typed further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this for example (requires some ugly casts in
onMount
but I think I'm fine with it as it makes it almost impossible to pass wrong query params)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, stronger typing is possible c89086b