Skip to content

Commit 1e65f30

Browse files
update publish.yaml: ubuntu-22.04
1 parent dc2f8b6 commit 1e65f30

File tree

5 files changed

+92
-81
lines changed

5 files changed

+92
-81
lines changed

apps/mcp-playground/env.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import os
2+
23
import json
34

45
is_cn_env = os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio'
56

67
api_key = os.getenv('MODELSCOPE_API_KEY')
78

89
internal_mcp_config = json.loads(
9-
os.getenv("INTERNAL_MCP_CONFIG", '{"mcpServers": {}}'))
10+
os.getenv('INTERNAL_MCP_CONFIG', '{"mcpServers": {}}'))
1011

1112
# oss
12-
endpoint = os.getenv("OSS_ENDPOINT")
13+
endpoint = os.getenv('OSS_ENDPOINT')
1314

14-
region = os.getenv("OSS_REGION")
15+
region = os.getenv('OSS_REGION')
1516

16-
bucket_name = os.getenv("OSS_BUCKET_NAME")
17+
bucket_name = os.getenv('OSS_BUCKET_NAME')

apps/mcp-playground/tools/oss.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
from http import HTTPStatus
21
import uuid
2+
from http import HTTPStatus
3+
34
import oss2
5+
from env import bucket_name, endpoint, region
46
from oss2.credentials import EnvironmentVariableCredentialsProvider
5-
from env import endpoint, bucket_name, region
7+
68
# OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET。
79
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
810

911
bucket = oss2.Bucket(auth, endpoint, bucket_name, region=region)
1012

1113

1214
def file_path_to_oss_url(file_path: str):
13-
if file_path.startswith("http"):
15+
if file_path.startswith('http'):
1416
return file_path
1517
ext = file_path.split('.')[-1]
1618
object_name = f'studio-temp/mcp-playground/{uuid.uuid4()}.{ext}'
1719
response = bucket.put_object_from_file(object_name, file_path)
1820
file_url = file_path
1921
if response.status == HTTPStatus.OK:
20-
file_url = bucket.sign_url('GET',
21-
object_name,
22-
60 * 60,
23-
slash_safe=True)
22+
file_url = bucket.sign_url(
23+
'GET', object_name, 60 * 60, slash_safe=True)
2424
return file_url
Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
1-
import modelscope_studio.components.antd as antd
2-
import modelscope_studio.components.base as ms
1+
# flake8: noqa: F401
32
import gradio as gr
43
import json
4+
import modelscope_studio.components.antd as antd
5+
import modelscope_studio.components.base as ms
56

67

78
def AddMcpServerButton():
8-
with antd.Button("添加 MCP Server", type="primary",
9-
size="small") as add_mcp_server_btn:
10-
with ms.Slot("icon"):
11-
antd.Icon("PlusOutlined")
9+
with antd.Button(
10+
'添加 MCP Server', type='primary',
11+
size='small') as add_mcp_server_btn:
12+
with ms.Slot('icon'):
13+
antd.Icon('PlusOutlined')
1214
with antd.Modal(
13-
title="添加 MCP Server",
15+
title='添加 MCP Server',
1416
footer=False,
15-
styles=dict(footer=dict(display="none"))) as add_mcp_server_modal:
17+
styles=dict(footer=dict(display='none'))) as add_mcp_server_modal:
1618
with antd.Tabs():
17-
with antd.Tabs.Item(label="表单添加"):
18-
with antd.Form(layout="vertical") as add_mcp_server_form:
19-
with antd.Form.Item(form_name="name",
20-
label="名称",
21-
rules=[{
22-
"required": True
23-
}]):
24-
antd.Input(placeholder="MCP Server 名称,如 fetch、time 等")
25-
with antd.Form.Item(form_name="url",
26-
label="SSE 链接",
27-
rules=[{
28-
"required": True
29-
}]):
30-
antd.Input(placeholder="MCP Server SSE 链接")
31-
with antd.Flex(gap="small", justify="end"):
32-
add_mcp_server_modal_cancel_btn = antd.Button("取消")
33-
antd.Button("确定", html_type="submit", type="primary")
34-
with antd.Tabs.Item(label="JSON 添加"):
35-
with antd.Form(layout="vertical") as add_mcp_server_json_form:
36-
with antd.Form.Item(form_name="json",
37-
label="JSON",
38-
rules=[{
39-
"required":
40-
True,
41-
"validator":
42-
"""(_, value) => {
19+
with antd.Tabs.Item(label='表单添加'):
20+
with antd.Form(layout='vertical') as add_mcp_server_form:
21+
with antd.Form.Item(
22+
form_name='name',
23+
label='名称',
24+
rules=[{
25+
'required': True
26+
}]):
27+
antd.Input(placeholder='MCP Server 名称,如 fetch、time 等')
28+
with antd.Form.Item(
29+
form_name='url',
30+
label='SSE 链接',
31+
rules=[{
32+
'required': True
33+
}]):
34+
antd.Input(placeholder='MCP Server SSE 链接')
35+
with antd.Flex(gap='small', justify='end'):
36+
add_mcp_server_modal_cancel_btn = antd.Button('取消')
37+
antd.Button('确定', html_type='submit', type='primary')
38+
with antd.Tabs.Item(label='JSON 添加'):
39+
with antd.Form(layout='vertical') as add_mcp_server_json_form:
40+
with antd.Form.Item(
41+
form_name='json',
42+
label='JSON',
43+
rules=[{
44+
'required':
45+
True,
46+
'validator':
47+
"""(_, value) => {
4348
if (!value) {
4449
return Promise.reject('请输入 JSON 值');
4550
}
@@ -53,40 +58,43 @@ def AddMcpServerButton():
5358
return Promise.reject('请输入有效的 JSON 值');
5459
}
5560
} """
56-
}]):
61+
}]):
5762
antd.Input.Textarea(
5863
auto_size=dict(minRows=4, maxRows=8),
5964
placeholder=json.dumps(
6065
{
61-
"mcpServers": {
62-
"fetch": {
63-
"type": "sse",
64-
"url": "mcp server sse url"
66+
'mcpServers': {
67+
'fetch': {
68+
'type': 'sse',
69+
'url': 'mcp server sse url'
6570
}
6671
}
6772
},
6873
indent=4))
69-
with antd.Flex(gap="small", justify="end"):
74+
with antd.Flex(gap='small', justify='end'):
7075
add_mcp_server_modal_json_cancel_btn = antd.Button(
71-
"取消")
72-
antd.Button("确定", html_type="submit", type="primary")
73-
add_mcp_server_btn.click(fn=lambda: gr.update(open=True),
74-
outputs=[add_mcp_server_modal],
75-
queue=False)
76-
gr.on(triggers=[
77-
add_mcp_server_modal_cancel_btn.click,
78-
add_mcp_server_modal_json_cancel_btn.click, add_mcp_server_modal.cancel
79-
],
80-
queue=False,
81-
fn=lambda: gr.update(open=False),
82-
outputs=[add_mcp_server_modal])
76+
'取消')
77+
antd.Button('确定', html_type='submit', type='primary')
78+
add_mcp_server_btn.click(
79+
fn=lambda: gr.update(open=True),
80+
outputs=[add_mcp_server_modal],
81+
queue=False)
82+
gr.on(
83+
triggers=[
84+
add_mcp_server_modal_cancel_btn.click,
85+
add_mcp_server_modal_json_cancel_btn.click,
86+
add_mcp_server_modal.cancel
87+
],
88+
queue=False,
89+
fn=lambda: gr.update(open=False),
90+
outputs=[add_mcp_server_modal])
8391
add_mcp_server_form.finish(
8492
lambda: (gr.update(value={
85-
"name": "",
86-
"url": "",
93+
'name': '',
94+
'url': '',
8795
}), gr.update(open=False)),
8896
outputs=[add_mcp_server_form, add_mcp_server_modal])
8997
add_mcp_server_json_form.finish(
90-
lambda: (gr.update(value={"json": ""}), gr.update(open=False)),
98+
lambda: (gr.update(value={'json': ''}), gr.update(open=False)),
9199
outputs=[add_mcp_server_json_form, add_mcp_server_modal])
92100
return add_mcp_server_form, add_mcp_server_json_form

modelscope_agent/tools/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import json5
99
import requests
10-
1110
from modelscope_agent.constants import (BASE64_FILES,
1211
DEFAULT_CODE_INTERPRETER_DIR,
1312
DEFAULT_TOOL_MANAGER_SERVICE_URL,

test_single.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22

33
import os
44

5+
56
def test():
67

78
# input tool name
89
mcp_servers = {
9-
"mcpServers": {
10-
"time": {
11-
"type": "sse",
12-
"url": "https://agenttor-mod-dd-cbwtrtihpn.cn-zhangjiakou.fcapp.run/sse"
10+
'mcpServers': {
11+
'time': {
12+
'type':
13+
'sse',
14+
'url':
15+
'https://agenttor-mod-dd-cbwtrtihpn.cn-zhangjiakou.fcapp.run/sse'
1316
},
14-
"fetch": {
15-
"type":
16-
"sse",
17-
"url":
18-
"https://mcp-cdb79f47-15a7-4a72.api-inference.modelscope.cn/sse"
17+
'fetch': {
18+
'type':
19+
'sse',
20+
'url':
21+
'https://mcp-cdb79f47-15a7-4a72.api-inference.modelscope.cn/sse'
1922
}
2023
}
2124
}
2225

23-
default_system = ('You are an assistant which helps me to finish a complex job. Tools may be given to you '
24-
'and you must choose some of them one per round to finish my request.')
26+
default_system = (
27+
'You are an assistant which helps me to finish a complex job. Tools may be given to you '
28+
'and you must choose some of them one per round to finish my request.')
2529

2630
llm_config = {
2731
'model': 'Qwen/Qwen2.5-72B-Instruct',
@@ -36,8 +40,7 @@ def test():
3640
# 'api_key': os.getenv('DASHSCOPE_API_KEY_YH')
3741
# }
3842

39-
bot = Agent(
40-
mcp=mcp_servers, llm=llm_config, instruction=default_system)
43+
bot = Agent(mcp=mcp_servers, llm=llm_config, instruction=default_system)
4144

4245
response = bot.run('上周日几号?那天北京天气情况如何')
4346

@@ -48,4 +51,4 @@ def test():
4851
assert isinstance(text, str)
4952

5053

51-
test()
54+
test()

0 commit comments

Comments
 (0)