Skip to content

Commit

Permalink
[Widget] Fix examples (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishig authored Mar 27, 2024
1 parent 4f70dba commit 220ac8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@
}
function _applyWidgetExample(idx: number) {
if (!isOptionsVisible) {
return;
}
hideOptions();
const sample = examples[idx];
title = sample.example_title as string;
applyWidgetExample(sample);
}
function _previewInputSample(idx: number) {
if (!isOptionsVisible) {
return;
}
const sample = examples[idx];
applyWidgetExample(sample, { isPreview: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,16 @@
}
async function applyWidgetExample(example: Example, opts: ExampleRunOpts = {}): Promise<void> {
if (isLoading) {
return;
if ("text" in example) {
messages = [{ role: "user", content: example.text }];
} else {
messages = [...example.messages];
}
isLoading = true;
try {
if ("text" in example) {
messages = [{ role: "user", content: example.text }];
} else {
messages = [...example.messages];
}
if (opts.isPreview) {
return;
}
const exampleOutput = example.output;
await getOutput({ ...opts.inferenceOpts, exampleOutput });
} finally {
isLoading = false;
if (opts.isPreview) {
return;
}
const exampleOutput = example.output;
await getOutput({ ...opts.inferenceOpts, exampleOutput });
}
function validateExample(sample: WidgetExample): sample is Example {
Expand Down

0 comments on commit 220ac8f

Please sign in to comment.