Skip to content

Commit 9000fff

Browse files
Mcp playground (#621)
1 parent b701610 commit 9000fff

File tree

21 files changed

+1638
-76
lines changed

21 files changed

+1638
-76
lines changed

apps/mcp-playground/app.py

Lines changed: 545 additions & 0 deletions
Large diffs are not rendered by default.
130 KB
Loading
4.27 KB
Loading

apps/mcp-playground/assets/mcp.png

4.61 KB
Loading
7.92 KB
Loading
19.4 KB
Loading
80.9 KB
Loading

apps/mcp-playground/config.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import os
2+
3+
import json
4+
from modelscope_studio.components.pro.chatbot import (ChatbotActionConfig,
5+
ChatbotBotConfig,
6+
ChatbotUserConfig,
7+
ChatbotWelcomeConfig)
8+
9+
max_mcp_server_count = 10
10+
11+
default_mcp_config = json.dumps({'mcpServers': {}},
12+
indent=4,
13+
ensure_ascii=False)
14+
15+
default_sys_prompt = 'You are a helpful assistant.'
16+
17+
# for internal
18+
default_mcp_prompts = {
19+
# "arxiv": ["查找最新的5篇关于量子计算的论文并简要总结", "根据当前时间,找到近期关于大模型的论文,得到研究趋势"],
20+
'高德地图': ['北京今天天气怎么样', '基于今天的天气,帮我规划一条从北京到杭州的路线'],
21+
'time': ['帮我查一下北京时间', '现在是北京时间 2025-04-01 12:00:00,对应的美西时间是多少?'],
22+
'fetch':
23+
['从中国新闻网获取最新的新闻', '获取 https://www.example.com 的内容,并提取为Markdown格式'],
24+
}
25+
26+
# for internal
27+
default_mcp_servers = [{
28+
'name': mcp_name,
29+
'enabled': True,
30+
'internal': True
31+
} for mcp_name in default_mcp_prompts.keys()]
32+
33+
bot_avatars = {
34+
'Qwen':
35+
os.path.join(os.path.dirname(__file__), './assets/qwen.png'),
36+
'QwQ':
37+
os.path.join(os.path.dirname(__file__), './assets/qwen.png'),
38+
'LLM-Research':
39+
os.path.join(os.path.dirname(__file__), './assets/meta.webp'),
40+
'deepseek-ai':
41+
os.path.join(os.path.dirname(__file__), './assets/deepseek.png'),
42+
}
43+
44+
mcp_prompt_model = 'Qwen/Qwen2.5-72B-Instruct'
45+
46+
model_options = [
47+
{
48+
'label': 'Qwen3-235B-A22B',
49+
'value': 'Qwen/Qwen3-235B-A22B',
50+
'model_params': {
51+
'extra_body': {
52+
'enable_thinking': False,
53+
}
54+
},
55+
'tag': {
56+
'label': '正常模式',
57+
'color': '#54C1FA'
58+
}
59+
},
60+
{
61+
'label': 'Qwen3-235B-A22B',
62+
'value': 'Qwen/Qwen3-235B-A22B:thinking',
63+
'thought': True,
64+
'model_params': {
65+
'extra_body': {
66+
'enable_thinking': True,
67+
}
68+
},
69+
'tag': {
70+
'label': '深度思考',
71+
'color': '#36CFD1'
72+
}
73+
},
74+
{
75+
'label': 'Qwen3-32B',
76+
'value': 'Qwen/Qwen3-32B',
77+
'model_params': {
78+
'extra_body': {
79+
'enable_thinking': False,
80+
}
81+
},
82+
'tag': {
83+
'label': '正常模式',
84+
'color': '#54C1FA'
85+
}
86+
},
87+
{
88+
'label': 'Qwen3-32B',
89+
'value': 'Qwen/Qwen3-32B:thinking',
90+
'thought': True,
91+
'model_params': {
92+
'extra_body': {
93+
'enable_thinking': True,
94+
}
95+
},
96+
'tag': {
97+
'label': '深度思考',
98+
'color': '#36CFD1'
99+
}
100+
},
101+
{
102+
'label': 'Qwen2.5-72B-Instruct',
103+
'value': 'Qwen/Qwen2.5-72B-Instruct'
104+
},
105+
{
106+
'label': 'DeepSeek-V3-0324',
107+
'value': 'deepseek-ai/DeepSeek-V3-0324',
108+
},
109+
{
110+
'label': 'Llama-4-Maverick-17B-128E-Instruct',
111+
'value': 'LLM-Research/Llama-4-Maverick-17B-128E-Instruct',
112+
},
113+
{
114+
'label': 'QwQ-32B',
115+
'value': 'Qwen/QwQ-32B',
116+
'thought': True,
117+
'tag': {
118+
'label': '推理模型',
119+
'color': '#624AFF'
120+
}
121+
},
122+
]
123+
124+
model_options_map = {model['value']: model for model in model_options}
125+
126+
primary_color = '#816DF8'
127+
128+
default_locale = 'zh_CN'
129+
130+
default_theme = {'token': {'colorPrimary': primary_color}}
131+
132+
133+
def user_config(disabled_actions=None):
134+
return ChatbotUserConfig(
135+
actions=[
136+
'copy', 'edit',
137+
ChatbotActionConfig(
138+
action='delete',
139+
popconfirm=dict(
140+
title='删除消息',
141+
description='确认删除该消息?',
142+
okButtonProps=dict(danger=True)))
143+
],
144+
disabled_actions=disabled_actions)
145+
146+
147+
def bot_config(disabled_actions=None):
148+
return ChatbotBotConfig(
149+
actions=[
150+
'copy', 'edit',
151+
ChatbotActionConfig(
152+
action='retry',
153+
popconfirm=dict(
154+
title='重新生成消息',
155+
description='重新生成消息会删除所有后续消息。',
156+
okButtonProps=dict(danger=True))),
157+
ChatbotActionConfig(
158+
action='delete',
159+
popconfirm=dict(
160+
title='删除消息',
161+
description='确认删除该消息?',
162+
okButtonProps=dict(danger=True)))
163+
],
164+
disabled_actions=disabled_actions)
165+
166+
167+
def welcome_config(prompts: dict, loading=False):
168+
return ChatbotWelcomeConfig(
169+
icon='./assets/mcp.png',
170+
title='ModelScope MCP 实验场',
171+
styles=dict(icon=dict(borderRadius='50%', overflow='hidden')),
172+
description='调用 MCP 工具以拓展模型能力',
173+
prompts=dict(
174+
title='用例生成中...' if loading else None,
175+
wrap=True,
176+
styles=dict(item=dict(flex='1 0 200px')),
177+
items=[{
178+
'label': mcp_name,
179+
'children': [{
180+
'description': prompt
181+
} for prompt in prompts]
182+
} for mcp_name, prompts in prompts.items()]))

apps/mcp-playground/env.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import json
3+
4+
is_cn_env = os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio'
5+
6+
api_key = os.getenv('MODELSCOPE_API_KEY')
7+
8+
internal_mcp_config = json.loads(
9+
os.getenv("INTERNAL_MCP_CONFIG", '{"mcpServers": {}}'))
10+
11+
# oss
12+
endpoint = os.getenv("OSS_ENDPOINT")
13+
14+
region = os.getenv("OSS_REGION")
15+
16+
bucket_name = os.getenv("OSS_BUCKET_NAME")

0 commit comments

Comments
 (0)