Merge pull request #1034 from SuanmoSuanyangTechnology/release/v0.3.2
Release/v0.3.2
This commit is contained in:
@@ -296,7 +296,7 @@ async def chat(
|
||||
}
|
||||
)
|
||||
|
||||
# 多 Agent 非流式返回
|
||||
# workflow 非流式返回
|
||||
result = await app_chat_service.workflow_chat(
|
||||
|
||||
message=payload.message,
|
||||
|
||||
@@ -221,7 +221,7 @@ def update_workspace_members(
|
||||
|
||||
@router.delete("/members/{member_id}", response_model=ApiResponse)
|
||||
@cur_workspace_access_guard()
|
||||
def delete_workspace_member(
|
||||
async def delete_workspace_member(
|
||||
member_id: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
@@ -230,7 +230,7 @@ def delete_workspace_member(
|
||||
workspace_id = current_user.current_workspace_id
|
||||
api_logger.info(f"用户 {current_user.username} 请求删除工作空间 {workspace_id} 的成员 {member_id}")
|
||||
|
||||
workspace_service.delete_workspace_member(
|
||||
await workspace_service.delete_workspace_member(
|
||||
db=db,
|
||||
workspace_id=workspace_id,
|
||||
member_id=member_id,
|
||||
|
||||
@@ -241,6 +241,8 @@ class Settings:
|
||||
SMTP_PORT: int = int(os.getenv("SMTP_PORT", "587"))
|
||||
SMTP_USER: str = os.getenv("SMTP_USER", "")
|
||||
SMTP_PASSWORD: str = os.getenv("SMTP_PASSWORD", "")
|
||||
|
||||
SANDBOX_URL: str = os.getenv("SANDBOX_URL", "")
|
||||
|
||||
REFLECTION_INTERVAL_SECONDS: float = float(os.getenv("REFLECTION_INTERVAL_SECONDS", "300"))
|
||||
HEALTH_CHECK_SECONDS: float = float(os.getenv("HEALTH_CHECK_SECONDS", "600"))
|
||||
|
||||
@@ -216,7 +216,7 @@ class RedBearModelFactory:
|
||||
# 深度思考模式:Claude 3.7 Sonnet 等支持思考的模型
|
||||
# 通过 additional_model_request_fields 传递 thinking 块,关闭时不传(Bedrock 无 disabled 选项)
|
||||
if config.deep_thinking:
|
||||
budget = config.thinking_budget_tokens or 10000
|
||||
budget = config.thinking_budget_tokens or 1024
|
||||
params["additional_model_request_fields"] = {
|
||||
"thinking": {"type": "enabled", "budget_tokens": budget}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ from app.core.workflow.engine.variable_pool import VariablePool
|
||||
from app.core.workflow.nodes import BaseNode
|
||||
from app.core.workflow.nodes.code.config import CodeNodeConfig
|
||||
from app.core.workflow.variable.base_variable import VariableType, DEFAULT_VALUE
|
||||
from app.core.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -131,7 +132,7 @@ class CodeNode(BaseNode):
|
||||
|
||||
async with httpx.AsyncClient(timeout=60) as client:
|
||||
response = await client.post(
|
||||
"http://sandbox:8194/v1/sandbox/run",
|
||||
f"{settings.SANDBOX_URL}:8194/v1/sandbox/run",
|
||||
headers={
|
||||
"x-api-key": 'redbear-sandbox'
|
||||
},
|
||||
|
||||
@@ -182,7 +182,7 @@ class DocExtractorNode(BaseNode):
|
||||
mime_type=f"image/{ext}",
|
||||
is_file=True,
|
||||
).model_dump())
|
||||
text = text + f"\n{placeholder}: {url}"
|
||||
text = text + f"\n{placeholder}: <img src=\"{url}\" data-url=\"{url}\">"
|
||||
except Exception as e:
|
||||
logger.error(f"Node {self.node_id}: failed to save image {placeholder}: {e}")
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ class ModelParameters(BaseModel):
|
||||
n: int = Field(default=1, ge=1, le=10, description="生成的回复数量")
|
||||
stop: Optional[List[str]] = Field(default=None, description="停止序列")
|
||||
deep_thinking: bool = Field(default=False, description="是否启用深度思考模式(需模型支持,如 DeepSeek-R1、QwQ 等)")
|
||||
thinking_budget_tokens: Optional[int] = Field(default=None, ge=1024, le=131072, description="深度思考 token 预算(仅部分模型支持)")
|
||||
thinking_budget_tokens: Optional[int] = Field(default=None, ge=1, le=131072, description="深度思考 token 预算(仅部分模型支持)")
|
||||
json_output: bool = Field(default=False, description="是否强制 JSON 格式输出(需模型支持 json_output 能力)")
|
||||
|
||||
|
||||
|
||||
@@ -161,7 +161,10 @@ class AppChatService:
|
||||
f.type == FileType.DOCUMENT for f in files
|
||||
):
|
||||
system_prompt += (
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: http://...,请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: <img src=\"url\"...>,"
|
||||
"请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"重要:图片 URL 中包含 UUID(如 /storage/permanent/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),"
|
||||
"必须将 src 属性的值原封不动复制到 Markdown 的括号中,不得增删任何字符。"
|
||||
)
|
||||
|
||||
# 创建 LangChain Agent
|
||||
@@ -448,7 +451,10 @@ class AppChatService:
|
||||
):
|
||||
from langchain.agents import create_agent
|
||||
system_prompt += (
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: http://...,请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: <img src=\"url\"...>,"
|
||||
"请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"重要:图片 URL 中包含 UUID(如 /storage/permanent/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),"
|
||||
"必须将 src 属性的值原封不动复制到 Markdown 的括号中,不得增删任何字符。"
|
||||
)
|
||||
|
||||
# 创建 LangChain Agent
|
||||
|
||||
@@ -650,7 +650,10 @@ class AgentRunService:
|
||||
)
|
||||
if has_doc_with_images:
|
||||
system_prompt += (
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: http://...,请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: <img src=\"url\"...>,"
|
||||
"请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"重要:图片 URL 中包含 UUID(如 /storage/permanent/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),"
|
||||
"必须将 src 属性的值原封不动复制到 Markdown 的括号中,不得增删任何字符。"
|
||||
)
|
||||
|
||||
agent = LangChainAgent(
|
||||
@@ -924,7 +927,10 @@ class AgentRunService:
|
||||
)
|
||||
if has_doc_with_images:
|
||||
system_prompt += (
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: http://...,请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"\n\n文档文字中包含图片位置标记如 [图片 第2页 第1张]: <img src=\"url\"...>,"
|
||||
"请在回答中用 Markdown 格式  展示对应图片。"
|
||||
"重要:图片 URL 中包含 UUID(如 /storage/permanent/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx),"
|
||||
"必须将 src 属性的值原封不动复制到 Markdown 的括号中,不得增删任何字符。"
|
||||
)
|
||||
|
||||
# 创建 LangChain Agent
|
||||
|
||||
@@ -400,7 +400,7 @@ class MultimodalService:
|
||||
# 在文本内容中追加图片位置标记
|
||||
if result and result[-1].get("type") in ("text", "document"):
|
||||
key = "text" if "text" in result[-1] else list(result[-1].keys())[-1]
|
||||
result[-1][key] = result[-1].get(key, "") + f"\n[图片 {placeholder}]: {img_url}"
|
||||
result[-1][key] = result[-1].get(key, "") + f"\n[图片 {placeholder}]: <img src=\"{img_url}\" data-url=\"{img_url}\">"
|
||||
# 将图片以视觉格式追加到消息内容中
|
||||
img_file = FileInput(
|
||||
type=FileType.IMAGE,
|
||||
|
||||
@@ -554,13 +554,16 @@ class WorkflowService:
|
||||
}
|
||||
}
|
||||
case "workflow_end":
|
||||
data = {
|
||||
"elapsed_time": payload.get("elapsed_time"),
|
||||
"message_length": len(payload.get("output", "")),
|
||||
"error": payload.get("error", "")
|
||||
}
|
||||
if "citations" in payload and payload["citations"]:
|
||||
data["citations"] = payload["citations"]
|
||||
return {
|
||||
"event": "end",
|
||||
"data": {
|
||||
"elapsed_time": payload.get("elapsed_time"),
|
||||
"message_length": len(payload.get("output", "")),
|
||||
"error": payload.get("error", "")
|
||||
}
|
||||
"data": data
|
||||
}
|
||||
case "node_start" | "node_end" | "node_error" | "cycle_item":
|
||||
return None
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.models.workspace_model import (
|
||||
)
|
||||
from app.repositories import workspace_repository
|
||||
from app.repositories.workspace_invite_repository import WorkspaceInviteRepository
|
||||
from app.services.session_service import SessionService
|
||||
from app.schemas.workspace_schema import (
|
||||
InviteAcceptRequest,
|
||||
InviteValidateResponse,
|
||||
@@ -58,7 +59,7 @@ def switch_workspace(
|
||||
raise BusinessException(f"切换工作空间失败: {str(e)}", BizCode.INTERNAL_ERROR)
|
||||
|
||||
|
||||
def delete_workspace_member(
|
||||
async def delete_workspace_member(
|
||||
db: Session,
|
||||
workspace_id: uuid.UUID,
|
||||
member_id: uuid.UUID,
|
||||
@@ -76,10 +77,29 @@ def delete_workspace_member(
|
||||
BizCode.WORKSPACE_NOT_FOUND)
|
||||
|
||||
try:
|
||||
deleted_user = workspace_member.user
|
||||
workspace_member.is_active = False
|
||||
workspace_member.user.current_workspace_id = None
|
||||
deleted_user.current_workspace_id = None
|
||||
|
||||
# 若被删除成员不是超级管理员且没有其他可用工作空间,则禁用该用户
|
||||
if not deleted_user.is_superuser:
|
||||
remaining = (
|
||||
db.query(WorkspaceMember)
|
||||
.filter(
|
||||
WorkspaceMember.user_id == deleted_user.id,
|
||||
WorkspaceMember.workspace_id != workspace_id,
|
||||
WorkspaceMember.is_active.is_(True),
|
||||
)
|
||||
.count()
|
||||
)
|
||||
if remaining == 0:
|
||||
deleted_user.is_active = False
|
||||
|
||||
db.commit()
|
||||
business_logger.info(f"用户 {user.username} 成功删除工作空间 {workspace_id} 的成员 {member_id}")
|
||||
|
||||
# 使被删除成员的所有 token 立即失效
|
||||
await SessionService.invalidate_all_user_tokens(str(workspace_member.user_id))
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
business_logger.error(f"删除工作空间成员失败 - 工作空间: {workspace_id}, 成员: {member_id}, 错误: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user