From 9a931389ea2987795c1f08b152152fc3919e24fe Mon Sep 17 00:00:00 2001 From: Timebomb2018 <18868801967@163.com> Date: Tue, 7 Apr 2026 17:15:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(app):=201.=20Import=20issue=20handling?= =?UTF-8?q?=EF=BC=9B=202.=20embedding=20model=20checkout;=203.=20omni=20mo?= =?UTF-8?q?del=20removes=20thinking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/core/agent/langchain_agent.py | 9 ++++++++- api/app/core/models/base.py | 12 ++++++++---- api/app/core/models/embedding.py | 7 +++++-- api/app/core/models/scripts/dashscope_models.yaml | 1 - api/app/schemas/app_schema.py | 6 +++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/api/app/core/agent/langchain_agent.py b/api/app/core/agent/langchain_agent.py index abb1af14..ca7172e8 100644 --- a/api/app/core/agent/langchain_agent.py +++ b/api/app/core/agent/langchain_agent.py @@ -14,6 +14,7 @@ from typing import Any, AsyncGenerator, Dict, List, Optional, Sequence from langchain.agents import create_agent from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage from langchain_core.tools import BaseTool +from langgraph.errors import GraphRecursionError from app.core.logging_config import get_business_logger from app.core.models import RedBearLLM, RedBearModelConfig @@ -377,7 +378,7 @@ class LangChainAgent: {"messages": messages}, config={"recursion_limit": self.max_iterations} ) - except RecursionError as e: + except (RecursionError, GraphRecursionError) as e: logger.warning( f"Agent 达到最大迭代次数限制 ({self.max_iterations}),可能存在工具调用循环", extra={"error": str(e)} @@ -612,6 +613,12 @@ class LangChainAgent: yield stream_total_tokens break + except GraphRecursionError: + logger.warning( + f"Agent 达到最大迭代次数限制 ({self.max_iterations}),模型可能不支持正确的工具调用停止判断" + ) + if not full_content: + yield "抱歉,我在处理您的请求时遇到了问题(已达最大处理步骤限制)。请尝试简化问题或更换模型后重试。" except Exception as e: logger.error(f"Agent astream_events 失败: {str(e)}", exc_info=True) raise diff --git a/api/app/core/models/base.py b/api/app/core/models/base.py index c7d8cfed..f5df7ed8 100644 --- a/api/app/core/models/base.py +++ b/api/app/core/models/base.py @@ -79,8 +79,10 @@ class RedBearModelFactory: model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {}) if is_streaming: model_kwargs["enable_thinking"] = config.deep_thinking - if config.deep_thinking and config.thinking_budget_tokens: - model_kwargs["thinking_budget"] = config.thinking_budget_tokens + if config.deep_thinking: + model_kwargs["incremental_output"] = True + if config.thinking_budget_tokens: + model_kwargs["thinking_budget"] = config.thinking_budget_tokens else: model_kwargs["enable_thinking"] = False params["model_kwargs"] = model_kwargs @@ -140,8 +142,10 @@ class RedBearModelFactory: model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {}) if is_streaming: model_kwargs["enable_thinking"] = config.deep_thinking - if config.deep_thinking and config.thinking_budget_tokens: - model_kwargs["thinking_budget"] = config.thinking_budget_tokens + if config.deep_thinking: + model_kwargs["incremental_output"] = True + if config.thinking_budget_tokens: + model_kwargs["thinking_budget"] = config.thinking_budget_tokens else: model_kwargs["enable_thinking"] = False params["model_kwargs"] = model_kwargs diff --git a/api/app/core/models/embedding.py b/api/app/core/models/embedding.py index 87c79d09..fb75696a 100644 --- a/api/app/core/models/embedding.py +++ b/api/app/core/models/embedding.py @@ -1,5 +1,5 @@ -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Union from langchain_core.embeddings import Embeddings from app.core.models.base import RedBearModelConfig, get_provider_embedding_class, RedBearModelFactory @@ -22,7 +22,8 @@ class RedBearEmbeddings(Embeddings): self._model = self._create_model(config) self._client = None - def _create_model(self, config: RedBearModelConfig) -> Embeddings: + @staticmethod + def _create_model(config: RedBearModelConfig) -> Embeddings: """根据配置创建 LangChain 模型""" embedding_class = get_provider_embedding_class(config.provider) provider = config.provider.lower() @@ -36,6 +37,8 @@ class RedBearEmbeddings(Embeddings): "api_key": config.api_key, "timeout": httpx.Timeout(timeout=config.timeout, connect=60.0), "max_retries": config.max_retries, + "check_embedding_ctx_length": False, + "encoding_format": "float" } elif provider == ModelProvider.DASHSCOPE: params = { diff --git a/api/app/core/models/scripts/dashscope_models.yaml b/api/app/core/models/scripts/dashscope_models.yaml index d1b604e0..d9e6a00f 100644 --- a/api/app/core/models/scripts/dashscope_models.yaml +++ b/api/app/core/models/scripts/dashscope_models.yaml @@ -803,7 +803,6 @@ models: - vision - video - audio - - thinking is_omni: true tags: - 大语言模型 diff --git a/api/app/schemas/app_schema.py b/api/app/schemas/app_schema.py index 8d6df73e..85cff671 100644 --- a/api/app/schemas/app_schema.py +++ b/api/app/schemas/app_schema.py @@ -4,6 +4,10 @@ from typing import Optional, Any, List, Dict, Union from enum import Enum, StrEnum from pydantic import BaseModel, Field, ConfigDict, field_serializer, field_validator + +from app.schemas.workflow_schema import WorkflowConfigCreate + + # ---------- Multimodal File Support ---------- class FileType(StrEnum): @@ -313,7 +317,7 @@ class AppCreate(BaseModel): # only for type=multi_agent multi_agent_config: Optional[Dict[str, Any]] = None - workflow_config: Optional[Dict[str, Any]] = None + workflow_config: Optional[WorkflowConfigCreate] = None class AppUpdate(BaseModel):