-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
667710d
Rm `previewInputSample` by reusing `applyInputSample`
mishig25 85aac2e
Rm unneeded `getDemoInputs` function
mishig25 c56c64f
better naming
mishig25 aa2396e
format
mishig25 d2374e4
correct typing
mishig25 d5325f9
add missing await
mishig25 2730c9c
Update js/src/lib/components/InferenceWidget/shared/helpers.ts
mishig25 3ba2298
format
mishig25 7858186
use `opts` syntax
mishig25 fd40b25
run onMount widget example inside WidgetWrapper
mishig25 756223d
all widgets run onMount example inside WidgetWrapper
mishig25 580c830
Rm `previewInputSample` by reusing `applyInputSample`
mishig25 f89936c
Rm unneeded `getDemoInputs` function
mishig25 0654367
better naming
mishig25 94249c4
format
mishig25 353f172
correct typing
mishig25 23a2fe0
add missing await
mishig25 c36fcdc
Update js/src/lib/components/InferenceWidget/shared/helpers.ts
mishig25 06420aa
format
mishig25 44eb4f1
use `opts` syntax
mishig25 ada2b70
run onMount widget example inside WidgetWrapper
mishig25 37f2ccd
all widgets run onMount example inside WidgetWrapper
mishig25 8446c3e
Merge branch 'rebase' into refactor_examples_running
mishig25 7ebca52
fix logic
mishig25 c89086b
stronger typing
mishig25 4d03786
format
mishig25 9ea310a
more refactor
mishig25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,24 @@ | |
(async () => { | ||
modelLoadInfo = await getModelLoadInfo(apiUrl, model.id, includeCredentials); | ||
$modelLoadStates[model.id] = modelLoadInfo; | ||
|
||
const exampleFromQueryParams = {} as TWidgetExample; | ||
for (const key of exampleQueryParams) { | ||
const val = getQueryParamVal(key); | ||
if (val) { | ||
exampleFromQueryParams[key] = val; | ||
} | ||
} | ||
if (Object.keys(exampleFromQueryParams).length) { | ||
// run widget example from query params | ||
applyInputSample(exampleFromQueryParams); | ||
} else { | ||
// run random widget example | ||
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. Not sure but |
||
})(); | ||
}); | ||
|
||
|
@@ -107,7 +127,6 @@ | |
{isLoading} | ||
inputSamples={selectedInputSamples?.inputSamples ?? []} | ||
{applyInputSample} | ||
{previewInputSample} | ||
/> | ||
</div> | ||
{/if} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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