Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bme-mcp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何家明
bme-mcp
Commits
31a35b96
Commit
31a35b96
authored
Apr 30, 2025
by
何家明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化模型
parent
57779c7f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
29 deletions
+50
-29
api.py
api.py
+2
-1
config.yaml
config.yaml
+11
-5
config_read.py
config_read.py
+4
-0
mcp_client.py
mcp_client.py
+7
-8
mcp_server.py
mcp_server.py
+26
-15
No files found.
api.py
View file @
31a35b96
...
...
@@ -2,6 +2,7 @@ import uvicorn
from
fastapi
import
FastAPI
from
QueryParam
import
QueryParam
from
config_read
import
config
from
mcp_client
import
user_query
app
=
FastAPI
(
name
=
[
"BME MCP服务"
])
...
...
@@ -16,4 +17,4 @@ async def query(query_param: QueryParam):
if
__name__
==
"__main__"
:
uvicorn
.
run
(
app
,
host
=
"0.0.0.0"
,
port
=
8000
)
uvicorn
.
run
(
app
,
host
=
"0.0.0.0"
,
port
=
config
[
"port"
]
)
config.yaml
View file @
31a35b96
active
:
deepseek_v3_bme
port
:
8000
active
:
bme-qwen2.5-32b
model
:
# deepseek-r1公司模型
deepseek_r1_bme
:
# 公司:deepseek-r1-671b
bme-deepseek-r1-671b
:
api_key
:
Tc7sY47hiU5d1LNGbJjGBfqfY13IE3khIc0uBvpJ11U
base_url
:
http://10.10.10.14:30000/v1
model_name
:
deepseek-r1
# 公司:qwen2.5-32b
bme-qwen2.5-32b
:
api_key
:
Tc7sY47hiU5d1LNGbJjGBfqfY13IE3khIc0uBvpJ11U
base_url
:
http://10.10.10.12:30070/v1
model_name
:
deepseek-r1
#
deepseek-v3公司模型
deepseek_v3_bme
:
#
公司:deepseek-v3-0324-671b
bme-deepseek-v3-0324-671b
:
api_key
:
Tc7sY47hiU5d1LNGbJjGBfqfY13IE3khIc0uBvpJ11U
base_url
:
http://10.10.10.12:30100/v1
model_name
:
deepseek-v3
...
...
config_read.py
0 → 100644
View file @
31a35b96
import
yaml
with
open
(
"config.yaml"
,
"r"
,
encoding
=
"utf-8"
)
as
yml_file
:
config
=
yaml
.
safe_load
(
yml_file
)
mcp_client.py
View file @
31a35b96
import
json
from
contextlib
import
AsyncExitStack
from
datetime
import
datetime
from
typing
import
Optional
from
loguru
import
logger
from
mcp
import
ClientSession
,
StdioServerParameters
from
mcp.client.stdio
import
stdio_client
...
...
@@ -9,15 +11,10 @@ from openai.types.chat import ChatCompletionToolParam, ChatCompletionAssistantMe
ChatCompletionMessageToolCallParam
,
ChatCompletionToolMessageParam
from
openai.types.chat.chat_completion_message_tool_call_param
import
Function
from
openai.types.shared_params
import
FunctionDefinition
import
json
import
yaml
from
pydantic
import
AnyUrl
from
QueryParam
import
QueryParam
with
open
(
"config.yaml"
,
"r"
,
encoding
=
"utf-8"
)
as
yml_file
:
config
=
yaml
.
safe_load
(
yml_file
)
from
config_read
import
config
if
config
[
"log"
][
"base_path"
]:
logger
.
add
(
config
[
"log"
][
"base_path"
]
+
"/mcp_client/log_{time:
%
Y-
%
m-
%
d}.log"
,
rotation
=
"1 day"
,
encoding
=
"utf-8"
,
...
...
@@ -138,7 +135,8 @@ class McpClient:
ai_response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
self
.
model_name
,
messages
=
messages
,
tools
=
self
.
available_tools
tools
=
self
.
available_tools
,
tool_choice
=
"auto"
)
logger
.
info
(
f
"--> ai response: {ai_response}"
)
...
...
@@ -181,7 +179,8 @@ class McpClient:
ai_response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
self
.
model_name
,
messages
=
messages
,
tools
=
self
.
available_tools
tools
=
self
.
available_tools
,
tool_choice
=
"auto"
)
logger
.
info
(
f
"----> ai response: {ai_response}"
)
...
...
mcp_server.py
View file @
31a35b96
import
requests
import
yaml
from
mcp.server.fastmcp
import
FastMCP
mcp
=
FastMCP
(
"BME-MCP"
)
from
config_read
import
config
with
open
(
"config.yaml"
,
"r"
,
encoding
=
"utf-8"
)
as
yml_file
:
config
=
yaml
.
safe_load
(
yml_file
)
mcp
=
FastMCP
(
"BME-MCP"
)
base_url
=
config
[
"remote"
][
"base_url"
]
...
...
@@ -62,9 +60,12 @@ def get_air_pm_10_month_focus(customer_id: int) -> []:
@
mcp
.
tool
()
def
get_air_pm_rank
(
customer_id
:
int
,
order
:
int
=
1
,
statistic_type
:
int
=
1
)
->
[]:
def
get_air_pm_rank
(
customer_id
:
int
,
order
:
int
,
statistic_type
:
int
)
->
[]:
"""
根据客户id获取空气质量微站排行(包含PM2.5和PM10标准)
根据客户id获取空气质量微站排行(包含PM2.5和PM10标准),其中
order如果没有指定,默认值是1;
statistic_type如果没有指定,默认值是1;
:param customer_id: 客户id
:param order: 排序规则:按统计区间的类型进行排序,升序排序传1,降序排序传2,默认为1
:param statistic_type: 统计区间:按小时统计传1,按日统计传2,要按月统计传3,默认为1
...
...
@@ -97,9 +98,13 @@ def get_air_pm_rank(customer_id: int, order: int=1, statistic_type: int=1) -> []
@
mcp
.
tool
()
def
get_tsp_rank
(
customer_id
:
int
,
order
:
int
=
1
,
statistic_type
:
int
=
1
,
size
:
int
=
10
)
->
[]:
def
get_tsp_rank
(
customer_id
:
int
,
order
:
int
,
statistic_type
:
int
,
size
:
int
)
->
[]:
"""
根据客户id获取TSP监测排行
根据客户id获取TSP监测排行,其中
order如果没有指定,默认值是1;
statistic_type如果没有指定,默认值是1;
size如果没有指定,默认值是10;
:param customer_id: 客户id
:param order: 排序规则:按统计区间的类型进行排序,升序排序传1,降序排序传2,默认为1
:param statistic_type: 统计区间:按小时统计传1,按日统计传2,要按月统计传3,默认为1
...
...
@@ -157,15 +162,21 @@ def get_governance_process_statistics(customer_id: int) -> {}:
@
mcp
.
tool
()
def
get_governance_process_records
(
customer_id
:
int
,
instruct_type
:
str
,
device_name
:
str
,
start_time
:
str
,
end_time
:
str
,
size
:
int
)
->
[]:
def
get_governance_process_records
(
customer_id
:
int
,
instruct_type
:
str
,
device_name
:
str
,
start_time
:
str
,
end_time
:
str
,
size
:
int
)
->
[]:
"""
根据客户id查询治理过程全记录列表
根据客户id查询治理过程全记录,其中:
instruct_type如果没有指定,默认值是空字符串;
device_name如果没有指定,默认值是空字符串;
start_time如果没有指定,默认值是当前时间的七天前,如:2025-04-23 16:18:00;
end_time如果没有指定,默认值是当前时间,如:2025-04-30 16:18:00;
size如果没有指定,默认值是10;
:param customer_id: 客户id
:param instruct_type: 触发机制:
智能联动为0,手动开启为1,全部为空
:param instruct_type: 触发机制:
当传入智能联动时,转换为0;当传入手动开启时,转换为1;其他值都转换为空字符串
:param device_name: 设备名称
:param start_time: 开始时间,格式为yyyy-MM-dd HH:mm:ss
,如:2025-04-27 17:30:00,默认为七天前的时间
:param end_time: 结束时间,格式为yyyy-MM-dd HH:mm:ss
,如:2025-04-27 17:30:00,默认为当前时间
:param start_time: 开始时间,格式为yyyy-MM-dd HH:mm:ss
:param end_time: 结束时间,格式为yyyy-MM-dd HH:mm:ss
:param size: 查询数量,默认10
:return: 返回结构中的字段名解释:
total:总数(由于该接口是分页查询,所以这里返回总数)
...
...
@@ -223,7 +234,7 @@ def get_default_system_prompt() -> str:
return
(
"你可以结合一系列的工具(tool)来回答用户的问题。
\n
"
"以下是你应该始终遵循的规则:
\n
"
"1.始终传入类型正确的参数,如果从
输入中没有解析到参数,则取工具对应参数描述的默认值,如果也没有默认值,则结束流程并告知用户信息不全
。
\n
"
"1.始终传入类型正确的参数,如果从
用户输入中没有解析到参数,直接使用描述中提到的参数默认值,不需要询问用户
。
\n
"
"2.只在需要时调用工具,如果你不需要额外信息,不要调用搜索代理,尽量自己解决任务。
\n
"
"3.如果不需要调用工具,直接回答问题即可。
\n
"
"4.永远不要用完全相同的参数重新进行之前的工具调用。
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment