Skip to content

Commit

Permalink
use opts syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mishig25 committed Oct 16, 2023
1 parent 3ba2298 commit 7858186
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,11 @@
throw new TypeError("Invalid output: output must be of type Array<label: string, score:number>");
}
function applyInputSample(
sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>, opts: ExampleRunOpts = {}) {
filename = sample.example_title!;
fileUrl = sample.src;
if (isPreview) {
if (opts.isPreview) {
if (isValidOutputLabels(sample.output)) {
output = sample.output;
outputJson = "";
Expand All @@ -141,7 +138,7 @@
}
file = null;
selectedSampleUrl = sample.src;
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
function validateExample(sample: WidgetExample): sample is WidgetExampleAssetInput<WidgetExampleOutputLabels> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,17 @@
throw new TypeError("Invalid output: output must be of type Array<blob:string, label:string, content-type:string>");
}
function applyInputSample(
sample: WidgetExampleAssetInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
filename = sample.example_title ?? "";
fileUrl = sample.src;
if (isPreview) {
if (opts.isPreview) {
output = [];
outputJson = "";
return;
}
file = null;
selectedSampleUrl = sample.src;
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
onMount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,10 @@
throw new TypeError("Invalid output: output must be of type <text:string>");
}
function applyInputSample(
sample: WidgetExampleAssetInput<WidgetExampleOutputText>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleAssetInput<WidgetExampleOutputText>, opts: ExampleRunOpts = {}) {
filename = sample.example_title!;
fileUrl = sample.src;
if (isPreview) {
if (opts.isPreview) {
if (isValidOutputText(sample.output)) {
output = sample.output.text;
outputJson = "";
Expand All @@ -142,7 +139,7 @@
}
file = null;
selectedSampleUrl = sample.src;
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
function updateModelLoading(isLoading: boolean, estimatedTime: number = 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@
);
}
function applyInputSample(
sample: WidgetExampleTextInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
text = sample.text;
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,12 @@
return Math.ceil(total_elems / SINGLE_DIM_COLS);
};
function applyInputSample(
sample: WidgetExampleTextInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
text = sample.text;
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,17 @@
throw new TypeError("Invalid output: output must be of type Array");
}
function applyInputSample(
sample: WidgetExampleTextInput<WidgetExampleOutputLabels>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput<WidgetExampleOutputLabels>, opts: ExampleRunOpts = {}) {
setTextAreaValue(sample.text);
if (isPreview) {
if (opts.isPreview) {
if (sample.output) {
output = sample.output;
} else {
output = [];
}
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
function validateExample(sample: WidgetExample): sample is WidgetExampleTextInput<WidgetExampleOutputLabels> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
async function applyInputSample(
sample: WidgetExampleAssetInput<WidgetExampleOutputLabels>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
opts: ExampleRunOpts = {}
) {
imgSrc = sample.src;
if (isPreview) {
if (opts.isPreview) {
if (isValidOutputLabels(sample.output)) {
output = sample.output;
outputJson = "";
Expand All @@ -110,7 +110,7 @@
return;
}
const blob = await getBlobFromUrl(imgSrc);
getOutput(blob, inferenceOpts);
getOutput(blob, opts.inferenceOpts);
}
function validateExample(sample: WidgetExample): sample is WidgetExampleAssetInput<WidgetExampleOutputLabels> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,15 @@
};
}
async function applyInputSample(
sample: WidgetExampleAssetInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
imgSrc = sample.src;
if (isPreview) {
if (opts.isPreview) {
output = [];
outputJson = "";
return;
}
const blob = await getBlobFromUrl(imgSrc);
getOutput(blob, inferenceOpts);
getOutput(blob, opts.inferenceOpts);
}
onMount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,16 @@
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
}
async function applyInputSample(
sample: WidgetExampleAssetAndPromptInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
async function applyInputSample(sample: WidgetExampleAssetAndPromptInput, opts: ExampleRunOpts = {}) {
prompt = sample.prompt;
imgSrc = sample.src;
if (isPreview) {
if (opts.isPreview) {
return;
}
const res = await fetch(imgSrc);
const blob = await res.blob();
await updateImageBase64(blob);
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
async function getOutput({ withModelLoading = false, isOnLoadCall = false }: InferenceRunFlags = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@
throw new TypeError("Invalid output: output must be of type Array & non-empty");
}
async function applyInputSample(
sample: WidgetExampleAssetInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
imgSrc = sample.src;
if (isPreview) {
if (opts.isPreview) {
output = "";
outputJson = "";
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,15 @@
highlightIndex = index;
}
async function applyInputSample(
sample: WidgetExampleAssetInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
async function applyInputSample(sample: WidgetExampleAssetInput, opts: ExampleRunOpts = {}) {
imgSrc = sample.src;
if (isPreview) {
if (opts.isPreview) {
output = [];
outputJson = "";
return;
}
const blob = await getBlobFromUrl(imgSrc);
getOutput(blob, inferenceOpts);
getOutput(blob, opts.inferenceOpts);
}
onMount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@
function applyInputSample(
sample: WidgetExampleTextAndContextInput<WidgetExampleOutputAnswerScore>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
opts: ExampleRunOpts = {}
) {
question = sample.text;
setTextAreaValue(sample.context);
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
function validateExample(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,14 @@
throw new TypeError("Invalid output: output must be of type Array");
}
function applyInputSample(
sample: WidgetExampleSentenceSimilarityInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleSentenceSimilarityInput, opts: ExampleRunOpts = {}) {
sourceSentence = sample.source_sentence;
comparisonSentences = sample.sentences;
nComparisonSentences = comparisonSentences.length;
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
onMount(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@
throw new TypeError("Invalid output: output must be of type Array & non-empty");
}
function applyInputSample(
sample: WidgetExampleTextInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput, opts: ExampleRunOpts = {}) {
setTextAreaValue(sample.text);
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,13 @@
);
}
function applyInputSample(
sample: WidgetExampleTextAndTableInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextAndTableInput, opts: ExampleRunOpts = {}) {
query = sample.text;
table = convertDataToTable(sample.table);
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,12 @@
}, {});
}
function applyInputSample(
sample: WidgetExampleStructuredDataInput,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleStructuredDataInput, opts: ExampleRunOpts = {}) {
table = convertDataToTable(sample.structuredData);
if (isPreview) {
if (opts.isPreview) {
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,9 @@
throw new TypeError("Invalid output: output must be of type Array & non-empty");
}
function applyInputSample(
sample: WidgetExampleTextInput<WidgetExampleOutputText>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput<WidgetExampleOutputText>, opts: ExampleRunOpts = {}) {
setTextAreaValue(sample.text);
if (isPreview) {
if (opts.isPreview) {
if (sample.output) {
output = sample.output.text;
outputJson = "";
Expand All @@ -190,7 +187,7 @@
}
return;
}
getOutput({ useCache, ...inferenceOpts });
getOutput({ useCache, ...opts.inferenceOpts });
}
function validateExample(sample: WidgetExample): sample is WidgetExampleTextInput<WidgetExampleOutputText> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,17 @@
throw new TypeError("Invalid output: output must be of type object & of instance Blob");
}
function applyInputSample(
sample: WidgetExampleTextInput<WidgetExampleOutputUrl>,
{ isPreview = false, inferenceOpts = {} }: ExampleRunOpts = {}
) {
function applyInputSample(sample: WidgetExampleTextInput<WidgetExampleOutputUrl>, opts: ExampleRunOpts = {}) {
text = sample.text;
if (isPreview) {
if (opts.isPreview) {
if (sample.output) {
output = sample.output.url;
} else {
output = "";
}
return;
}
getOutput(inferenceOpts);
getOutput(opts.inferenceOpts);
}
function validateExample(sample: WidgetExample): sample is WidgetExampleTextInput<WidgetExampleOutputUrl> {
Expand Down
Loading

0 comments on commit 7858186

Please sign in to comment.