修改robot目录窗口逻辑
This commit is contained in:
parent
035b8338cc
commit
41c6e010d1
@ -709,7 +709,7 @@ async def chat_completions(request: ChatRequest, authorization: Optional[str] =
|
|||||||
Chat completions API similar to OpenAI, supports both streaming and non-streaming
|
Chat completions API similar to OpenAI, supports both streaming and non-streaming
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request: ChatRequest containing messages, model, dataset_ids (optional list), required bot_id, system_prompt, mcp_settings, and files
|
request: ChatRequest containing messages, model, optional dataset_ids list, required bot_id, system_prompt, mcp_settings, and files
|
||||||
authorization: Authorization header containing API key (Bearer <API_KEY>)
|
authorization: Authorization header containing API key (Bearer <API_KEY>)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -717,19 +717,24 @@ async def chat_completions(request: ChatRequest, authorization: Optional[str] =
|
|||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- dataset_ids: 可选参数,当提供时必须是项目ID列表(单个项目也使用数组格式)
|
- dataset_ids: 可选参数,当提供时必须是项目ID列表(单个项目也使用数组格式)
|
||||||
- bot_id: 必需参数,机器人ID,用于创建项目目录
|
- bot_id: 必需参数,机器人ID
|
||||||
- 只有当提供 dataset_ids 时才会创建机器人项目目录:projects/robot/{bot_id}/
|
- 只有当 robot_type == "catalog_agent" 且 dataset_ids 为非空数组时才会创建机器人项目目录:projects/robot/{bot_id}/
|
||||||
|
- robot_type 为其他值(包括默认的 "agent")时不创建任何目录
|
||||||
|
- dataset_ids 为空数组 []、None 或未提供时不创建任何目录
|
||||||
- 支持多知识库合并,自动处理文件夹重名冲突
|
- 支持多知识库合并,自动处理文件夹重名冲突
|
||||||
|
|
||||||
Required Parameters:
|
Required Parameters:
|
||||||
- bot_id: str - 目标机器人项目ID
|
- bot_id: str - 目标机器人ID
|
||||||
|
- messages: List[Message] - 对话消息列表
|
||||||
Optional Parameters:
|
Optional Parameters:
|
||||||
- dataset_ids: List[str] - 源知识库项目ID列表(单个项目也使用数组格式)
|
- dataset_ids: List[str] - 源知识库项目ID列表(单个项目也使用数组格式)
|
||||||
|
- robot_type: str - 机器人类型,默认为 "agent"
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
{"bot_id": "my-bot-001"}
|
{"bot_id": "my-bot-001", "messages": [{"role": "user", "content": "Hello"}]}
|
||||||
{"dataset_ids": ["project-123"], "bot_id": "my-bot-001"}
|
{"dataset_ids": ["project-123"], "bot_id": "my-bot-001", "messages": [{"role": "user", "content": "Hello"}]}
|
||||||
{"dataset_ids": ["project-123", "project-456"], "bot_id": "my-bot-002"}
|
{"dataset_ids": ["project-123", "project-456"], "bot_id": "my-bot-002", "messages": [{"role": "user", "content": "Hello"}]}
|
||||||
|
{"dataset_ids": ["project-123"], "bot_id": "my-catalog-bot", "robot_type": "catalog_agent", "messages": [{"role": "user", "content": "Hello"}]}
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# v1接口:从Authorization header中提取API key作为模型API密钥
|
# v1接口:从Authorization header中提取API key作为模型API密钥
|
||||||
@ -740,8 +745,8 @@ async def chat_completions(request: ChatRequest, authorization: Optional[str] =
|
|||||||
if not bot_id:
|
if not bot_id:
|
||||||
raise HTTPException(status_code=400, detail="bot_id is required")
|
raise HTTPException(status_code=400, detail="bot_id is required")
|
||||||
|
|
||||||
# 创建项目目录(如果有dataset_ids)
|
# 创建项目目录(如果有dataset_ids且不是agent类型)
|
||||||
project_dir = create_project_directory(request.dataset_ids, bot_id)
|
project_dir = create_project_directory(request.dataset_ids, bot_id, request.robot_type)
|
||||||
|
|
||||||
# 收集额外参数作为 generate_cfg
|
# 收集额外参数作为 generate_cfg
|
||||||
exclude_fields = {'messages', 'model', 'model_server', 'dataset_ids', 'language', 'tool_response', 'system_prompt', 'mcp_settings' ,'stream', 'robot_type', 'bot_id'}
|
exclude_fields = {'messages', 'model', 'model_server', 'dataset_ids', 'language', 'tool_response', 'system_prompt', 'mcp_settings' ,'stream', 'robot_type', 'bot_id'}
|
||||||
@ -923,9 +928,10 @@ async def create_agent_and_generate_response(
|
|||||||
raise HTTPException(status_code=500, detail="No response from agent")
|
raise HTTPException(status_code=500, detail="No response from agent")
|
||||||
|
|
||||||
|
|
||||||
def create_project_directory(dataset_ids: List[str], bot_id: str) -> Optional[str]:
|
def create_project_directory(dataset_ids: Optional[List[str]], bot_id: str, robot_type: str = "agent") -> Optional[str]:
|
||||||
"""创建项目目录的公共逻辑"""
|
"""创建项目目录的公共逻辑"""
|
||||||
if not dataset_ids:
|
# 只有当 robot_type == "catalog_agent" 且 dataset_ids 不为空时才创建目录
|
||||||
|
if robot_type != "catalog_agent" or not dataset_ids or len(dataset_ids) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1014,7 +1020,11 @@ async def chat_completions_v2(request: ChatRequestV2, authorization: Optional[st
|
|||||||
api_key = bot_config.get("api_key")
|
api_key = bot_config.get("api_key")
|
||||||
|
|
||||||
# 创建项目目录(从后端配置获取dataset_ids)
|
# 创建项目目录(从后端配置获取dataset_ids)
|
||||||
project_dir = create_project_directory(bot_config.get("dataset_ids", []), bot_id)
|
project_dir = create_project_directory(
|
||||||
|
bot_config.get("dataset_ids", []),
|
||||||
|
bot_id,
|
||||||
|
bot_config.get("robot_type", "agent")
|
||||||
|
)
|
||||||
|
|
||||||
# 处理消息
|
# 处理消息
|
||||||
messages = process_messages(request.messages, request.language)
|
messages = process_messages(request.messages, request.language)
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class ChatRequest(BaseModel):
|
|||||||
messages: List[Message]
|
messages: List[Message]
|
||||||
model: str = "qwen3-next"
|
model: str = "qwen3-next"
|
||||||
model_server: str = ""
|
model_server: str = ""
|
||||||
dataset_ids: List[str]
|
dataset_ids: Optional[List[str]] = None
|
||||||
bot_id: str
|
bot_id: str
|
||||||
stream: Optional[bool] = False
|
stream: Optional[bool] = False
|
||||||
language: Optional[str] = "ja"
|
language: Optional[str] = "ja"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user