mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-21 13:24:44 +08:00
feat: Add llms to support the latest Open Source SOTA models (#497)
* fix: update README and configuration guide for new model support and reasoning capabilities * fix: format code for consistency in agent and node files * fix: update test cases for environment variable handling in llm configuration * fix: refactor message chunk conversion functions for improved clarity and maintainability * refactor: remove enable_thinking parameter from LLM configuration functions * chore: update agent-LLM mapping for consistency * chore: update LLM configuration handling for improved clarity * test: add unit tests for Dashscope message chunk conversion and LLM configuration * test: add unit tests for message chunk conversion in Dashscope * test: add unit tests for message chunk conversion in Dashscope * chore: remove unused imports from test_dashscope.py --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from typing import get_args
|
||||
|
||||
from src.config import load_yaml_config
|
||||
from src.config.agents import LLMType
|
||||
from src.llms.providers.dashscope import ChatDashscope
|
||||
|
||||
# Cache for LLM instances
|
||||
_llm_cache: dict[LLMType, BaseChatModel] = {}
|
||||
@@ -29,6 +30,7 @@ def _get_llm_type_config_keys() -> dict[str, str]:
|
||||
"reasoning": "REASONING_MODEL",
|
||||
"basic": "BASIC_MODEL",
|
||||
"vision": "VISION_MODEL",
|
||||
"code": "CODE_MODEL",
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +74,6 @@ def _create_llm_use_conf(llm_type: LLMType, conf: Dict[str, Any]) -> BaseChatMod
|
||||
if "max_retries" not in merged_conf:
|
||||
merged_conf["max_retries"] = 3
|
||||
|
||||
if llm_type == "reasoning":
|
||||
merged_conf["api_base"] = merged_conf.pop("base_url", None)
|
||||
|
||||
# Handle SSL verification settings
|
||||
verify_ssl = merged_conf.pop("verify_ssl", True)
|
||||
|
||||
@@ -87,15 +86,23 @@ def _create_llm_use_conf(llm_type: LLMType, conf: Dict[str, Any]) -> BaseChatMod
|
||||
|
||||
if "azure_endpoint" in merged_conf or os.getenv("AZURE_OPENAI_ENDPOINT"):
|
||||
return AzureChatOpenAI(**merged_conf)
|
||||
|
||||
# Check if base_url is dashscope endpoint
|
||||
if "base_url" in merged_conf and "dashscope." in merged_conf["base_url"]:
|
||||
if llm_type == "reasoning":
|
||||
merged_conf["extra_body"] = {"enable_thinking": True}
|
||||
else:
|
||||
merged_conf["extra_body"] = {"enable_thinking": False}
|
||||
return ChatDashscope(**merged_conf)
|
||||
|
||||
if llm_type == "reasoning":
|
||||
merged_conf["api_base"] = merged_conf.pop("base_url", None)
|
||||
return ChatDeepSeek(**merged_conf)
|
||||
else:
|
||||
return ChatOpenAI(**merged_conf)
|
||||
|
||||
|
||||
def get_llm_by_type(
|
||||
llm_type: LLMType,
|
||||
) -> BaseChatModel:
|
||||
def get_llm_by_type(llm_type: LLMType) -> BaseChatModel:
|
||||
"""
|
||||
Get LLM instance by type. Returns cached instance if available.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user