Skip to content

Commit 78b35d5

Browse files
committed
[fix] Fix example web
- Updated the prompt parameter in multiple instances of TextRewriterTask to a single string format, removing the array structure for clarity and consistency. - Adjusted the download model configuration in the workflow to streamline model usage. - Refactored imports in main.tsx to enhance task registration and reduce redundancy.
1 parent 5aaa422 commit 78b35d5

3 files changed

Lines changed: 22 additions & 48 deletions

File tree

docs/developers/01_getting_started.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ workflow
5757
.downloadModel({ model: "onnx:Xenova/LaMini-Flan-T5-783M:q8" })
5858
.textRewriter({
5959
text: "The quick brown fox jumps over the lazy dog.",
60-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
60+
prompt: "Rewrite the following text in reverse:",
6161
})
6262
.rename("text", "console")
6363
.debugLog();
@@ -88,7 +88,7 @@ graph.addTask(
8888
new TextRewriterTask(
8989
{
9090
text: "The quick brown fox jumps over the lazy dog.",
91-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
91+
prompt: "Rewrite the following text in reverse:",
9292
// model will be provided by the dataflow below
9393
},
9494
{ id: "2" }
@@ -184,7 +184,7 @@ graph.addTask(
184184
new TextRewriterTask(
185185
{
186186
text: "The quick brown fox jumps over the lazy dog.",
187-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
187+
prompt: "Rewrite the following text in reverse:",
188188
},
189189
{ id: "2" }
190190
)
@@ -289,19 +289,13 @@ There is a JSONTask that can be used to build a graph. This is useful for saving
289289
290290
```json
291291
[
292-
{
293-
"id": "1",
294-
"type": "DownloadModelTask",
295-
"input": {
296-
"model": ["onnx:Xenova/LaMini-Flan-T5-783M:q8", "onnx:Xenova/m2m100_418M:q8"]
297-
}
298-
},
299292
{
300293
"id": "2",
301294
"type": "TextRewriterTask",
302295
"input": {
296+
"model": "onnx:Xenova/LaMini-Flan-T5-783M:q8",
303297
"text": "The quick brown fox jumps over the lazy dog.",
304-
"prompt": ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"]
298+
"prompt": "Rewrite the following text in reverse:"
305299
},
306300
"dependencies": {
307301
"model": {
@@ -379,7 +373,7 @@ graph.addTask(
379373
new TextRewriterCompoundTask({
380374
model: "onnx:Xenova/LaMini-Flan-T5-783M:q8",
381375
text: "The quick brown fox jumps over the lazy dog.",
382-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
376+
prompt: "Rewrite the following text in reverse:",
383377
})
384378
);
385379
```
@@ -397,7 +391,7 @@ graph.addTask(
397391
{
398392
model: "onnx:Xenova/LaMini-Flan-T5-783M:q8",
399393
text: "The quick brown fox jumps over the lazy dog.",
400-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
394+
prompt: "Rewrite the following text in reverse:",
401395
},
402396
{ id: "1" }
403397
)

examples/web/src/App.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@ const resetGraph = () => {
3838
const workflow = window["workflow"];
3939
workflow
4040
.reset()
41-
.downloadModel({
42-
model: ["onnx:Xenova/LaMini-Flan-T5-783M:q8", "onnx:Xenova/m2m100_418M:q8"],
43-
})
41+
.downloadModel({ model: "onnx:Xenova/LaMini-Flan-T5-783M:q8" })
4442
.textRewriter({
4543
text: "The quick brown fox jumps over the lazy dog.",
46-
prompt: ["Rewrite the following text in reverse:", "Rewrite this to sound like a pirate:"],
44+
prompt: "Rewrite the following text in reverse:",
4745
})
48-
.rename("model", "model", -2)
46+
.downloadModel({ model: "onnx:Xenova/m2m100_418M:q8" })
4947
.textTranslation({
5048
source_lang: "en",
5149
target_lang: "es",
5250
})
5351
.rename("*", "console")
54-
.rename("*", "console", -2)
5552
.debugLog({ log_level: "info" });
5653
taskGraphRepo.saveTaskGraph("default", workflow.graph);
5754
};

examples/web/src/main.tsx

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {
8-
DownloadModelTask,
9-
TextEmbeddingTask,
10-
TextRewriterTask,
11-
TextTranslationTask,
12-
} from "@workglow/ai";
7+
import { registerAiTasks } from "@workglow/ai";
138
import { installDevToolsFormatters, isDarkMode } from "@workglow/debug";
14-
import { Task, TaskGraph, Workflow } from "@workglow/task-graph";
15-
import { DebugLogTask, DelayTask, FetchUrlTask, JsonTask, LambdaTask } from "@workglow/tasks";
9+
import { registerBaseTasks, Workflow } from "@workglow/task-graph";
10+
import { registerCommonTasks } from "@workglow/tasks";
1611
import ReactDOM from "react-dom/client";
1712
import { App } from "./App";
13+
1814
import "./main.css";
1915

2016
ReactDOM.createRoot(document.getElementById("root")!).render(
@@ -24,24 +20,12 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
2420
);
2521

2622
installDevToolsFormatters();
27-
28-
[
29-
Workflow,
30-
DownloadModelTask,
31-
TextRewriterTask,
32-
TextEmbeddingTask,
33-
TextTranslationTask,
34-
TextRewriterTask,
35-
DebugLogTask,
36-
Task,
37-
TaskGraph,
38-
JsonTask,
39-
DelayTask,
40-
FetchUrlTask,
41-
LambdaTask,
42-
].forEach((item) => {
43-
window[item.name] = item;
44-
});
23+
const tasks = [...registerBaseTasks()];
24+
[Workflow, ...registerBaseTasks(), ...registerCommonTasks(), ...registerAiTasks()].forEach(
25+
(item) => {
26+
window[item.name] = item;
27+
}
28+
);
4529

4630
const dark = isDarkMode();
4731
const grey = dark ? "#aaa" : "#333";
@@ -60,10 +44,9 @@ console.log(
6044
console.log(
6145
` %cworkflow = new Workflow();
6246
workflow.%creset%c();
63-
workflow.%cDownloadModel%c({ %cmodel%c: [%c'onnx:Xenova/LaMini-Flan-T5-783M:q8']%c });
64-
workflow.%cTextRewriter%c({ %ctext%c: %c'The quick brown fox jumps over the lazy dog.'%c, %cprompt%c: [%c'Rewrite the following text in reverse:'%c, %c'Rewrite this to sound like a pirate:'%c] });
47+
workflow.%ctextRewriter%c({%cmodel%c: %c'onnx:Xenova/LaMini-Flan-T5-783M:q8'%c, %ctext%c: %c'The quick brown fox jumps over the lazy dog.'%c, %cprompt%c: %c'Rewrite the following text in reverse:'%c });
6548
workflow.%crename%c(%c'*'%c, %c'console'%c);
66-
workflow.%cDebugLog%c({ %clevel%c: %c'info'%c });
49+
workflow.%cdebugLog%c({ %clevel%c: %c'info'%c });
6750
6851
console.log(JSON.stringify(workflow.toDependencyJSON(),null,2));
6952
`,

0 commit comments

Comments
 (0)