Skip to content

Commit a4d4837

Browse files
author
久氢
committed
feat(langchain): add support for reasoning content with new reasoning providers and integrate ChatDeepSeek model
Change-Id: I60b0bdc5837f88c554957d322273e8dbd63dc677 Signed-off-by: 久氢 <mapenghui.mph@alibaba-inc.com>
1 parent a26d8b6 commit a4d4837

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

agentrun/integration/langchain/model_adapter.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
)
1212
from agentrun.integration.utils.adapter import ModelAdapter
1313

14+
# 支持 reasoning_content 的供应商列表
15+
_REASONING_PROVIDERS = frozenset({
16+
"tongyi",
17+
"custom",
18+
"deepseek",
19+
"zhipuai",
20+
"moonshot",
21+
"minimax",
22+
})
23+
1424

1525
class LangChainModelAdapter(ModelAdapter):
1626
"""LangChain 模型适配器 / LangChain Model Adapter
@@ -23,15 +33,36 @@ def __init__(self):
2333

2434
def wrap_model(self, common_model: Any) -> Any:
2535
"""包装 CommonModel 为 LangChain BaseChatModel / LangChain Model Adapter"""
36+
info = common_model.get_model_info() # 确保模型可用
37+
provider = (info.provider or "").lower()
38+
39+
if provider in _REASONING_PROVIDERS:
40+
return self._create_reasoning_model(info)
41+
return self._create_openai_model(info)
42+
43+
def _create_reasoning_model(self, info: Any) -> Any:
44+
"""创建支持 reasoning_content 的模型(使用 ChatDeepSeek)"""
45+
from langchain_deepseek import ChatDeepSeek
46+
47+
return ChatDeepSeek(
48+
model=info.model,
49+
api_key=info.api_key,
50+
api_base=info.base_url,
51+
default_headers=info.headers,
52+
stream_usage=True,
53+
streaming=True,
54+
)
55+
56+
def _create_openai_model(self, info: Any) -> Any:
57+
"""创建标准 OpenAI 兼容模型"""
2658
from langchain_openai import ChatOpenAI
2759

28-
info = common_model.get_model_info() # 确保模型可用
2960
return ChatOpenAI(
3061
name=info.model,
3162
api_key=info.api_key,
3263
model=info.model,
3364
base_url=info.base_url,
3465
default_headers=info.headers,
3566
stream_usage=True,
36-
streaming=True, # 启用流式输出以支持 token by token
67+
streaming=True,
3768
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ server = [
3838
langchain = [
3939
"langchain>=1.0.0; python_version >= '3.10'",
4040
"langchain-openai>=1.0.0; python_version >= '3.10'",
41+
"langchain-deepseek>=1.0.1; python_version >= '3.10'",
4142
]
4243

4344
google-adk = [

0 commit comments

Comments
 (0)