Skip to content

Commit dce8613

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/cancel_sub_model
# Conflicts: # backend/services/prompt_service.py # frontend/app/[locale]/setup/models/components/modelConfig.tsx # test/backend/services/test_prompt_service.py
2 parents 3262ac5 + 42a8f77 commit dce8613

File tree

57 files changed

+4490
-934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4490
-934
lines changed

backend/consts/const.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,7 @@
238238
"PROCESS_FAILED": "PROCESS_FAILED",
239239
"FORWARD_FAILED": "FORWARD_FAILED",
240240
}
241+
242+
# Deep Thinking Constants
243+
THINK_START_PATTERN = "<think>"
244+
THINK_END_PATTERN = "</think>"

backend/database/tool_db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def add_tool_field(tool_info):
164164
# add tool params
165165
tool_params = tool.params
166166
for ele in tool_params:
167-
ele["default"] = tool_info["params"][ele["name"]]
167+
param_name = ele["name"]
168+
ele["default"] = tool_info["params"].get(param_name)
168169

169170
tool_dict = as_dict(tool)
170171
tool_dict["params"] = tool_params

backend/database/user_tenant_db.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from typing import Any, Dict, Optional
55

6+
from consts.const import DEFAULT_TENANT_ID
67
from database.client import as_dict, get_db_session
78
from database.db_models import UserTenant
89

@@ -28,6 +29,27 @@ def get_user_tenant_by_user_id(user_id: str) -> Optional[Dict[str, Any]]:
2829
return None
2930

3031

32+
def get_all_tenant_ids() -> list[str]:
33+
"""
34+
Get all unique tenant IDs from the database
35+
36+
Returns:
37+
list[str]: List of unique tenant IDs
38+
"""
39+
with get_db_session() as session:
40+
result = session.query(UserTenant.tenant_id).filter(
41+
UserTenant.delete_flag == "N"
42+
).distinct().all()
43+
44+
tenant_ids = [row[0] for row in result]
45+
46+
# Add default tenant_id if not already in the list
47+
if DEFAULT_TENANT_ID not in tenant_ids:
48+
tenant_ids.append(DEFAULT_TENANT_ID)
49+
50+
return tenant_ids
51+
52+
3153
def insert_user_tenant(user_id: str, tenant_id: str):
3254
"""
3355
Insert user tenant relationship

backend/main_service.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
import uvicorn
22
import logging
33
import warnings
4+
import asyncio
45
warnings.filterwarnings("ignore", category=UserWarning)
56

67
from dotenv import load_dotenv
78
load_dotenv()
89

910
from apps.base_app import app
1011
from utils.logging_utils import configure_logging, configure_elasticsearch_logging
12+
from services.tool_configuration_service import initialize_tools_on_startup
1113

1214

1315
configure_logging(logging.INFO)
1416
configure_elasticsearch_logging()
1517
logger = logging.getLogger("main_service")
1618

19+
20+
async def startup_initialization():
21+
"""
22+
Perform initialization tasks during server startup
23+
"""
24+
logger.info("Starting server initialization...")
25+
26+
try:
27+
# Initialize tools on startup - service layer handles detailed logging
28+
await initialize_tools_on_startup()
29+
logger.info("Server initialization completed successfully!")
30+
31+
except Exception as e:
32+
logger.error(f"Server initialization failed: {str(e)}")
33+
# Don't raise the exception to allow server to start even if initialization fails
34+
logger.warning("Server will continue to start despite initialization issues")
35+
36+
1737
if __name__ == "__main__":
18-
# Scan agents and update to database
38+
asyncio.run(startup_initialization())
1939
uvicorn.run(app, host="0.0.0.0", port=5010, log_level="info")

backend/prompts/managed_system_prompt_template.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ system_prompt: |-
6161
- 用简单的Python编写代码
6262
- 遵循python代码规范和python语法
6363
- 根据格式规范正确调用工具
64+
- 考虑到代码执行与展示用户代码的区别,使用'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'表达运行代码,使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码
65+
- 注意运行的代码不会被用户看到,所以如果用户需要看到代码,你需要使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码。
6466
6567
3. 观察结果:
6668
- 查看代码执行结果
@@ -99,7 +101,7 @@ system_prompt: |-
99101
{{ constraint }}
100102
101103
### python代码规范
102-
1. 如果认为是需要执行的代码,代码内容以'代码:\n```py\n'开头,并以'```<end_code>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```code:语言类型\n'开头,并以'```<end_code>'标识符结尾,其中语言类型例如python、java、javascript等;
104+
1. 如果认为是需要执行的代码,代码内容以'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'标识符结尾,其中语言类型例如python、java、javascript等;
103105
2. 只使用已定义的变量,变量将在多次调用之间持续保持;
104106
3. 使用“print()”函数让下一次的模型调用看到对应变量信息;
105107
4. 正确使用工具的入参,使用关键字参数,不要用字典形式;

backend/prompts/managed_system_prompt_template_en.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ system_prompt: |-
6161
- Write code in simple Python
6262
- Follow Python coding standards and Python syntax
6363
- Call tools correctly according to format specifications
64+
- To distinguish between code execution and displaying user code, use 'Code: \n```<RUN>\n' to start executing code and '```<END_CODE>' to indicate its completion. Use 'Code: \n```<DISPLAY:language_type>\n' to start displaying code and '```<END_CODE>' to indicate its completion.
65+
- Note that executed code is not visible to users. If users need to see the code, use 'Code: \n```<DISPLAY:language_type>\n' as the start and '```<END_CODE>' to denote displayed code.
6466
6567
3. Observe Results:
6668
- View code execution results
@@ -99,7 +101,7 @@ system_prompt: |-
99101
{{ constraint }}
100102
101103
### Python Code Specifications
102-
1. If it is considered to be code that needs to be executed, the code content begins with 'code: \n```py\n' and ends with '```<end_code>'. If the code does not need to be executed for display only, the code content begins with 'code:\n```code:language_type\n', and ends with '```<end_code>', where language_type can be python, java, javascript, etc;
104+
1. If it is considered to be code that needs to be executed, the code content begins with 'code: \n```<RUN>\n' and ends with '```<END_CODE>'. If the code does not need to be executed for display only, the code content begins with 'code:\n```<DISPLAY:language_type>\n', and ends with '```<END_CODE>', where language_type can be python, java, javascript, etc;
103105
2. Only use defined variables, variables will persist between multiple calls;
104106
3. Use "print()" function to let the next model call see corresponding variable information;
105107
4. Use tool input parameters correctly, use keyword arguments, not dictionary format;

backend/prompts/manager_system_prompt_template.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ system_prompt: |-
6262
- 用简单的Python编写代码
6363
- 遵循python代码规范和python语法
6464
- 正确调用工具或助手解决问题
65+
- 考虑到代码执行与展示用户代码的区别,使用'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'表达运行代码,使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码
66+
- 注意运行的代码不会被用户看到,所以如果用户需要看到代码,你需要使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码。
6567
6668
3. 观察结果:
6769
- 查看代码执行结果
@@ -127,7 +129,7 @@ system_prompt: |-
127129
{{ constraint }}
128130
129131
### python代码规范
130-
1. 如果认为是需要执行的代码,代码内容以'代码:\n```py\n'开头,并以'```<end_code>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```code:语言类型\n'开头,并以'```<end_code>'标识符结尾,其中语言类型例如python、java、javascript等;
132+
1. 如果认为是需要执行的代码,代码内容以'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'标识符结尾,其中语言类型例如python、java、javascript等;
131133
2. 只使用已定义的变量,变量将在多次调用之间持续保持;
132134
3. 使用“print()”函数让下一次的模型调用看到对应变量信息;
133135
4. 正确使用工具/助手的入参,使用关键字参数,不要用字典形式;

backend/prompts/manager_system_prompt_template_en.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ system_prompt: |-
6262
- Write code in simple Python
6363
- Follow Python coding standards and Python syntax
6464
- Correctly call tools or agents to solve problems
65+
- To distinguish between code execution and displaying user code, use 'Code: \n```<RUN>\n' to start executing code and '```<END_CODE>' to indicate its completion. Use 'Code: \n```<DISPLAY:language_type>\n' to start displaying code and '```<END_CODE>' to indicate its completion.
66+
- Note that executed code is not visible to users. If users need to see the code, use 'Code: \n```<DISPLAY:language_type>\n' as the start and '```<END_CODE>' to denote displayed code.
6567
6668
3. Observe Results:
6769
- View code execution results
@@ -127,7 +129,7 @@ system_prompt: |-
127129
{{ constraint }}
128130
129131
### Python Code Specifications
130-
1. If it is considered to be code that needs to be executed, the code content begins with 'code: \n```py\n' and ends with '```<end_code>'. If the code does not need to be executed for display only, the code content begins with 'code: \n```code:language_type\n', and ends with '```<end_code>', where language_type can be python, java, javascript, etc;
132+
1. If it is considered to be code that needs to be executed, the code content begins with 'code: \n```<RUN>\n' and ends with '```<END_CODE>'. If the code does not need to be executed for display only, the code content begins with 'code: \n```<DISPLAY:language_type>\n', and ends with '```<END_CODE>', where language_type can be python, java, javascript, etc;
131133
2. Only use defined variables, variables will persist between multiple calls;
132134
3. Use "print()" function to let the next model call see corresponding variable information;
133135
4. Use tool/agent input parameters correctly, use keyword arguments, not dictionary format;

backend/prompts/utils/prompt_generate.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
5252
- 用简单的Python编写代码
5353
- 遵循python代码规范和python语法
5454
- 根据格式规范正确调用工具/助手
55+
- 考虑到代码执行与展示用户代码的区别,使用'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'表达运行代码,使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码
56+
- 注意运行的代码不会被用户看到,所以如果用户需要看到代码,你需要使用'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'表达展示代码。
5557
5658
3. 观察结果:
5759
- 查看代码执行结果
5860
5961
在思考结束后,当Agent认为可以回答用户问题,那么可以不生成代码,直接生成最终回答给到用户并停止循环。
6062
6163
### python代码规范
62-
1. 如果认为是需要执行的代码,代码内容以'代码:\n```py\n'开头,并以'```<end_code>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```code:语言类型\n'开头,并以'```<end_code>'标识符结尾,其中语言类型例如python、java、javascript等;
64+
1. 如果认为是需要执行的代码,代码内容以'代码:\n```<RUN>\n'开头,并以'```<END_CODE>'标识符结尾。如果是不需要执行仅用于展示的代码,代码内容以'代码:\n```<DISPLAY:语言类型>\n'开头,并以'```<END_CODE>'标识符结尾,其中语言类型例如python、java、javascript等;
6365
2. 只使用已定义的变量,变量将在多次调用之间持续保持;
6466
3. 使用“print()”函数让下一次的模型调用看到对应变量信息;
6567
4. 正确使用工具/助手的入参,使用关键字参数,不要用字典形式;
@@ -76,18 +78,18 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
7678
7779
思考:我先使用knowledge_base_search工具查找本地知识库是否有相关信息。
7880
代码:
79-
```py
81+
```<RUN>
8082
knowledge_info = knowledge_base_search(query="东方明珠 介绍", index_names=["本地知识库1", "本地知识库2"])
8183
print(knowledge_info)
82-
```<end_code>
84+
```<END_CODE>
8385
观察结果:未找到查询"东方明珠 介绍"的结果。检索结果难以支撑回答。
8486
8587
思考:从本地知识库中没有找到相关信息,我需要使用web_search工具查询网络信息。
8688
代码:
87-
```py
89+
```<RUN>
8890
web_info = web_search(query="东方明珠 介绍")
8991
print(web_info)
90-
```<end_code>
92+
```<END_CODE>
9193
观察结果:东方明珠广播电视塔位于中国上海市浦东新区陆家嘴...
9294
9395
思考:我已经获得了有关信息,现在我将生成最终回答。
@@ -99,10 +101,10 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
99101
100102
思考:我需要调用旅程规划助手来规划出行。
101103
代码:
102-
```py
104+
```<RUN>
103105
itinerary_result = travel_planning_assistant(task="帮我规划明天从上海出发去北京的行程")
104106
print(itinerary_result)
105-
```<end_code>
107+
```<END_CODE>
106108
观察结果:明天从上海出发去北京的行程规划,包括交通、住宿、景点等。
107109
108110
思考:我已经获得了出行规划,现在我将生成最终回答。
@@ -114,18 +116,18 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
114116
115117
思考:我需要先获取天气数据,然后让分析助手帮我分析。
116118
代码:
117-
```py
119+
```<RUN>
118120
weather_data = weather_api(city="北京")
119121
print(weather_data)
120-
```<end_code>
122+
```<END_CODE>
121123
观察结果:{"temperature": 25, "humidity": 60%, "condition": "晴天"}
122124
123125
思考:现在我有天气数据了,让分析助手帮我分析这些数据。
124126
代码:
125-
```py
127+
```<RUN>
126128
analysis_result = data_analysis_assistant(task="分析今天的天气数据:温度25度,湿度60%,晴天")
127129
print(analysis_result)
128-
```<end_code>
130+
```<END_CODE>
129131
观察结果:今天天气适宜,温度适中,湿度正常,适合户外活动。
130132
131133
思考:我已经获得了天气数据和分析结果,现在我将生成最终回答。
@@ -147,9 +149,9 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
147149
148150
任务5:"帮我用Python写一个快速排序的代码"
149151
150-
思考:我需要直接写一个python代码,此代码仅用于展示,因此我以'代码:\n```code:python\n'开头。
152+
思考:我需要直接写一个python代码,此代码仅用于展示,因此我以'代码:\n```<DISPLAY:python>\n'开头。
151153
代码:
152-
```code:python
154+
```<DISPLAY:python>
153155
def quick_sort(arr):
154156
if len(arr) <= 1:
155157
return arr
@@ -158,12 +160,12 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
158160
middle = [x for x in arr if x == pivot]
159161
right = [x for x in arr if x > pivot]
160162
return quick_sort(left) + middle + quick_sort(right)
161-
```<end_code>
163+
```<END_CODE>
162164
观察结果:快速排序的python代码。
163165
164166
思考:我已经获得了快速排序的python代码,现在我将生成最终回答。
165167
快速排序的python代码如下:
166-
```code:python
168+
```<DISPLAY:python>
167169
def quick_sort(arr):
168170
if len(arr) <= 1:
169171
return arr
@@ -172,7 +174,7 @@ FEW_SHOTS_SYSTEM_PROMPT: |-
172174
middle = [x for x in arr if x == pivot]
173175
right = [x for x in arr if x > pivot]
174176
return quick_sort(left) + middle + quick_sort(right)
175-
```<end_code>
177+
```<END_CODE>
176178
177179
---
178180

0 commit comments

Comments
 (0)