Merge pull request #799 from SuanmoSuanyangTechnology/fix/Timebomb_0210
fix(app):
This commit is contained in:
@@ -14,6 +14,7 @@ from typing import Any, AsyncGenerator, Dict, List, Optional, Sequence
|
|||||||
from langchain.agents import create_agent
|
from langchain.agents import create_agent
|
||||||
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage
|
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage
|
||||||
from langchain_core.tools import BaseTool
|
from langchain_core.tools import BaseTool
|
||||||
|
from langgraph.errors import GraphRecursionError
|
||||||
|
|
||||||
from app.core.logging_config import get_business_logger
|
from app.core.logging_config import get_business_logger
|
||||||
from app.core.models import RedBearLLM, RedBearModelConfig
|
from app.core.models import RedBearLLM, RedBearModelConfig
|
||||||
@@ -377,7 +378,7 @@ class LangChainAgent:
|
|||||||
{"messages": messages},
|
{"messages": messages},
|
||||||
config={"recursion_limit": self.max_iterations}
|
config={"recursion_limit": self.max_iterations}
|
||||||
)
|
)
|
||||||
except RecursionError as e:
|
except (RecursionError, GraphRecursionError) as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Agent 达到最大迭代次数限制 ({self.max_iterations}),可能存在工具调用循环",
|
f"Agent 达到最大迭代次数限制 ({self.max_iterations}),可能存在工具调用循环",
|
||||||
extra={"error": str(e)}
|
extra={"error": str(e)}
|
||||||
@@ -612,6 +613,12 @@ class LangChainAgent:
|
|||||||
yield stream_total_tokens
|
yield stream_total_tokens
|
||||||
break
|
break
|
||||||
|
|
||||||
|
except GraphRecursionError:
|
||||||
|
logger.warning(
|
||||||
|
f"Agent 达到最大迭代次数限制 ({self.max_iterations}),模型可能不支持正确的工具调用停止判断"
|
||||||
|
)
|
||||||
|
if not full_content:
|
||||||
|
yield "抱歉,我在处理您的请求时遇到了问题(已达最大处理步骤限制)。请尝试简化问题或更换模型后重试。"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Agent astream_events 失败: {str(e)}", exc_info=True)
|
logger.error(f"Agent astream_events 失败: {str(e)}", exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -79,8 +79,10 @@ class RedBearModelFactory:
|
|||||||
model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {})
|
model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {})
|
||||||
if is_streaming:
|
if is_streaming:
|
||||||
model_kwargs["enable_thinking"] = config.deep_thinking
|
model_kwargs["enable_thinking"] = config.deep_thinking
|
||||||
if config.deep_thinking and config.thinking_budget_tokens:
|
if config.deep_thinking:
|
||||||
model_kwargs["thinking_budget"] = config.thinking_budget_tokens
|
model_kwargs["incremental_output"] = True
|
||||||
|
if config.thinking_budget_tokens:
|
||||||
|
model_kwargs["thinking_budget"] = config.thinking_budget_tokens
|
||||||
else:
|
else:
|
||||||
model_kwargs["enable_thinking"] = False
|
model_kwargs["enable_thinking"] = False
|
||||||
params["model_kwargs"] = model_kwargs
|
params["model_kwargs"] = model_kwargs
|
||||||
@@ -140,8 +142,10 @@ class RedBearModelFactory:
|
|||||||
model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {})
|
model_kwargs: Dict[str, Any] = config.extra_params.get("model_kwargs", {})
|
||||||
if is_streaming:
|
if is_streaming:
|
||||||
model_kwargs["enable_thinking"] = config.deep_thinking
|
model_kwargs["enable_thinking"] = config.deep_thinking
|
||||||
if config.deep_thinking and config.thinking_budget_tokens:
|
if config.deep_thinking:
|
||||||
model_kwargs["thinking_budget"] = config.thinking_budget_tokens
|
model_kwargs["incremental_output"] = True
|
||||||
|
if config.thinking_budget_tokens:
|
||||||
|
model_kwargs["thinking_budget"] = config.thinking_budget_tokens
|
||||||
else:
|
else:
|
||||||
model_kwargs["enable_thinking"] = False
|
model_kwargs["enable_thinking"] = False
|
||||||
params["model_kwargs"] = model_kwargs
|
params["model_kwargs"] = model_kwargs
|
||||||
|
|||||||
@@ -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 langchain_core.embeddings import Embeddings
|
||||||
|
|
||||||
from app.core.models.base import RedBearModelConfig, get_provider_embedding_class, RedBearModelFactory
|
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._model = self._create_model(config)
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
def _create_model(self, config: RedBearModelConfig) -> Embeddings:
|
@staticmethod
|
||||||
|
def _create_model(config: RedBearModelConfig) -> Embeddings:
|
||||||
"""根据配置创建 LangChain 模型"""
|
"""根据配置创建 LangChain 模型"""
|
||||||
embedding_class = get_provider_embedding_class(config.provider)
|
embedding_class = get_provider_embedding_class(config.provider)
|
||||||
provider = config.provider.lower()
|
provider = config.provider.lower()
|
||||||
@@ -36,6 +37,8 @@ class RedBearEmbeddings(Embeddings):
|
|||||||
"api_key": config.api_key,
|
"api_key": config.api_key,
|
||||||
"timeout": httpx.Timeout(timeout=config.timeout, connect=60.0),
|
"timeout": httpx.Timeout(timeout=config.timeout, connect=60.0),
|
||||||
"max_retries": config.max_retries,
|
"max_retries": config.max_retries,
|
||||||
|
"check_embedding_ctx_length": False,
|
||||||
|
"encoding_format": "float"
|
||||||
}
|
}
|
||||||
elif provider == ModelProvider.DASHSCOPE:
|
elif provider == ModelProvider.DASHSCOPE:
|
||||||
params = {
|
params = {
|
||||||
|
|||||||
@@ -803,7 +803,6 @@ models:
|
|||||||
- vision
|
- vision
|
||||||
- video
|
- video
|
||||||
- audio
|
- audio
|
||||||
- thinking
|
|
||||||
is_omni: true
|
is_omni: true
|
||||||
tags:
|
tags:
|
||||||
- 大语言模型
|
- 大语言模型
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ from typing import Optional, Any, List, Dict, Union
|
|||||||
from enum import Enum, StrEnum
|
from enum import Enum, StrEnum
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, ConfigDict, field_serializer, field_validator
|
from pydantic import BaseModel, Field, ConfigDict, field_serializer, field_validator
|
||||||
|
|
||||||
|
from app.schemas.workflow_schema import WorkflowConfigCreate
|
||||||
|
|
||||||
|
|
||||||
# ---------- Multimodal File Support ----------
|
# ---------- Multimodal File Support ----------
|
||||||
|
|
||||||
class FileType(StrEnum):
|
class FileType(StrEnum):
|
||||||
@@ -313,7 +317,7 @@ class AppCreate(BaseModel):
|
|||||||
# only for type=multi_agent
|
# only for type=multi_agent
|
||||||
multi_agent_config: Optional[Dict[str, Any]] = None
|
multi_agent_config: Optional[Dict[str, Any]] = None
|
||||||
|
|
||||||
workflow_config: Optional[Dict[str, Any]] = None
|
workflow_config: Optional[WorkflowConfigCreate] = None
|
||||||
|
|
||||||
|
|
||||||
class AppUpdate(BaseModel):
|
class AppUpdate(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user