Skip to content

Commit c86c197

Browse files
authored
Add drag-and-drop interface & add implementation of DAG running engine for drag-and-drop module (modelscope#114)
1 parent e88c708 commit c86c197

13 files changed

+1337
-3
lines changed

.flake8

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ avoid-escape = no
88
ignore =
99
F401
1010
F403
11-
W503
11+
W503
12+
E731

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ repos:
2929
pb2\.py$
3030
| grpc\.py$
3131
| ^docs
32+
| \.html$
3233
)
3334
args: [ --disallow-untyped-defs,
3435
--disallow-incomplete-defs,
@@ -66,6 +67,7 @@ repos:
6667
| grpc\.py$
6768
| \.demo$
6869
| \.md$
70+
| \.html$
6971
)
7072
args: [
7173
--disable=W0511,
@@ -91,6 +93,8 @@ repos:
9193
--disable=W0221,
9294
--disable=R0401,
9395
--disable=W0632,
96+
--disable=W0123,
97+
--disable=C3001,
9498
]
9599
- repo: https://github.com/regebro/pyroma
96100
rev: "4.0"

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
test_requires = ["pytest", "pytest-cov", "pre-commit"]
4444

45-
gradio_requires = ["gradio==4.19.1", "modelscope_studio==0.0.5"]
45+
gradio_requires = ["networkx", "gradio==4.19.1", "modelscope_studio==0.0.5"]
4646

4747
# released requires
4848
minimal_requires = [
@@ -113,6 +113,7 @@
113113
entry_points={
114114
"console_scripts": [
115115
"as_studio=agentscope.web.studio.studio:run_app",
116+
"as_workflow=agentscope.web.workstation.workflow:main",
116117
],
117118
},
118119
)

src/agentscope/web/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,21 @@ If you implement a video agent, `as_studio` will display the video as follows.
9494
**Principle:** When calling agent's `self.speak(msg)` method, it will
9595
output `msg.video_path` to the frontend. Here `msg.video_path` is a list of paths of videos.
9696

97+
## AgentScope Workstation
98+
A draggable interface for building AgentScope workflow, which is a tool for generating config for running with AgentScope.
99+
![](https://gw.alicdn.com/imgextra/i3/O1CN01uioF2Z1tYCsWgR3Cf_!!6000000005913-1-tps-2156-1080.gif)
97100

101+
### How to Use
102+
Go to the [AgentScope Workstation website](http://39.103.132.84:8080/) and log in with GitHub. Drag modules to the canvas and fill in the blanks. Link each module to build a workflow. Click the **EXPORT** button to get the final configurations. Then save the configurations as `config.json`. Then run with the following commands:
103+
104+
```bash
105+
# Run in command line
106+
as_workflow config.json
107+
108+
# Run in as_studio (gradio ui)
109+
as_studio config.json
110+
```
111+
112+
Or you can run your workflow on ModelScope Studio. Click the **RUN** button. Then, fill in the `API_KEY` environment variable in ModelScope Studio. After a few minutes, enjoy your journey on AgentScope!
113+
114+
More examples about AgentScope Workstation are coming soon!

src/agentscope/web/studio/studio.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ def run_app() -> None:
175175
def start_game(uid: str) -> None:
176176
"""Start the main game loop."""
177177
thread_local_data.uid = uid
178-
main = import_function_from_path(script_path, "main")
178+
if script_path.endswith(".py"):
179+
main = import_function_from_path(script_path, "main")
180+
elif script_path.endswith(".json"):
181+
from agentscope.web.workstation.workflow import (
182+
start_workflow,
183+
load_config,
184+
)
185+
186+
config = load_config(script_path)
187+
main = lambda: start_workflow(config)
188+
else:
189+
raise ValueError(f"Unrecognized file formats: {script_path}")
179190

180191
while True:
181192
try:

src/agentscope/web/workstation/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"4": {
3+
"name": "dashscope_chat",
4+
"data": {
5+
"args": {
6+
"config_name": "qwen",
7+
"model_name": "qwen-max",
8+
"api_key": "************",
9+
"temperature": 0.1,
10+
"seed": 1,
11+
"model_type": "dashscope_chat",
12+
"messages_key": "input"
13+
}
14+
},
15+
"inputs": {},
16+
"outputs": {}
17+
},
18+
"5": {
19+
"name": "Message",
20+
"data": {
21+
"args": {
22+
"name": "Host",
23+
"content": "Hello",
24+
"url": ""
25+
}
26+
},
27+
"inputs": {
28+
"input_1": {
29+
"connections": []
30+
}
31+
},
32+
"outputs": {
33+
"output_1": {
34+
"connections": [
35+
{
36+
"node": "7",
37+
"output": "input_1"
38+
}
39+
]
40+
}
41+
}
42+
},
43+
"6": {
44+
"name": "UserAgent",
45+
"data": {
46+
"args": {
47+
"name": "User"
48+
}
49+
},
50+
"inputs": {
51+
"input_1": {
52+
"connections": [
53+
{
54+
"node": "7",
55+
"input": "output_1"
56+
}
57+
]
58+
}
59+
},
60+
"outputs": {
61+
"output_1": {
62+
"connections": []
63+
}
64+
}
65+
},
66+
"7": {
67+
"name": "DialogAgent",
68+
"data": {
69+
"args": {
70+
"name": "Alice",
71+
"sys_prompt": "You are Alice.",
72+
"model_config_name": "qwen"
73+
}
74+
},
75+
"inputs": {
76+
"input_1": {
77+
"connections": [
78+
{
79+
"node": "5",
80+
"input": "output_1"
81+
}
82+
]
83+
}
84+
},
85+
"outputs": {
86+
"output_1": {
87+
"connections": [
88+
{
89+
"node": "6",
90+
"output": "input_1"
91+
}
92+
]
93+
}
94+
}
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"2": {
3+
"name": "dashscope_chat",
4+
"data": {
5+
"args": {
6+
"config_name": "qwen",
7+
"model_name": "qwen-max",
8+
"api_key": "************",
9+
"temperature": 0.1,
10+
"seed": 1,
11+
"model_type": "dashscope_chat",
12+
"messages_key": "input"
13+
}
14+
},
15+
"inputs": {},
16+
"outputs": {}
17+
},
18+
"3": {
19+
"name": "ForLoopPipeline",
20+
"data": {
21+
"elements": [
22+
"4"
23+
],
24+
"args": {
25+
"max_loop": 3,
26+
"break_func": ""
27+
}
28+
},
29+
"inputs": {
30+
"input_1": {
31+
"connections": [
32+
{
33+
"node": "7",
34+
"input": "output_1"
35+
}
36+
]
37+
}
38+
},
39+
"outputs": {
40+
"output_1": {
41+
"connections": []
42+
}
43+
}
44+
},
45+
"4": {
46+
"name": "SequentialPipeline",
47+
"data": {
48+
"elements": [
49+
"5",
50+
"6"
51+
]
52+
},
53+
"inputs": {
54+
"input_1": {
55+
"connections": []
56+
}
57+
},
58+
"outputs": {
59+
"output_1": {
60+
"connections": []
61+
}
62+
}
63+
},
64+
"5": {
65+
"name": "DialogAgent",
66+
"data": {
67+
"args": {
68+
"name": "Alice",
69+
"sys_prompt": "You are Alice.",
70+
"model_config_name": "qwen"
71+
}
72+
},
73+
"inputs": {
74+
"input_1": {
75+
"connections": []
76+
}
77+
},
78+
"outputs": {
79+
"output_1": {
80+
"connections": []
81+
}
82+
}
83+
},
84+
"6": {
85+
"name": "UserAgent",
86+
"data": {
87+
"args": {
88+
"name": "User"
89+
}
90+
},
91+
"inputs": {
92+
"input_1": {
93+
"connections": []
94+
}
95+
},
96+
"outputs": {
97+
"output_1": {
98+
"connections": []
99+
}
100+
}
101+
},
102+
"7": {
103+
"name": "Message",
104+
"data": {
105+
"args": {
106+
"name": "Host",
107+
"content": "Hello",
108+
"url": ""
109+
}
110+
},
111+
"inputs": {
112+
"input_1": {
113+
"connections": []
114+
}
115+
},
116+
"outputs": {
117+
"output_1": {
118+
"connections": [
119+
{
120+
"node": "3",
121+
"output": "input_1"
122+
}
123+
]
124+
}
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)