Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dayu/contracts/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class OpenAICompatibleModelConfig(BaseModelConfig, total=False):
supports_stream_usage: bool
extra_payloads: dict[str, ModelConfigJsonValue]
max_retries: int
verify_ssl: bool


class CliModelConfig(BaseModelConfig, total=False):
Expand Down Expand Up @@ -155,6 +156,7 @@ class OpenAICompatibleRunnerParams(TypedDict, total=False):
supports_stream: bool
supports_tool_calling: bool
supports_stream_usage: bool
verify_ssl: bool


class CliRunnerParams(TypedDict, total=False):
Expand Down
8 changes: 7 additions & 1 deletion dayu/engine/async_openai_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def __init__(
supports_stream_usage: bool = False,
running_config: Optional[AsyncOpenAIRunnerRunningConfig] = None,
cancellation_token: CancellationToken | None = None,
verify_ssl: bool = True,
):
"""
初始化 OpenAI 兼容 Runner。
Expand Down Expand Up @@ -583,6 +584,7 @@ def __init__(
self.supports_tool_calling = supports_tool_calling
self.supports_stream_usage = supports_stream_usage
self.cancellation_token = cancellation_token
self._verify_ssl = verify_ssl
self._session: Optional[Any] = None
self._tool_executor: Optional[ToolExecutor] = None

Expand Down Expand Up @@ -626,7 +628,11 @@ def _ensure_session(self) -> "ClientSession":
if session is not None and not bool(getattr(session, "closed", False)):
return session
aiohttp_module = _require_aiohttp_module()
new_session = aiohttp_module.ClientSession()
if self._verify_ssl:
new_session = aiohttp_module.ClientSession()
else:
connector = aiohttp_module.TCPConnector(verify_ssl=False)
new_session = aiohttp_module.ClientSession(connector=connector)
self._session = new_session
return new_session

Expand Down
1 change: 1 addition & 0 deletions dayu/engine/runner_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def create_runner(
supports_stream_usage=bool(runner_params.get("supports_stream_usage", False)),
running_config=_build_openai_runner_running_config(agent_create_args),
cancellation_token=cancellation_token,
verify_ssl=bool(runner_params.get("verify_ssl", True)),
)
raise ValueError(f"不支持的 runner_type: {runner_type}")

Expand Down
1 change: 1 addition & 0 deletions dayu/host/agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _build_runner_params(
"supports_stream": bool(openai_model_config.get("supports_stream", True)),
"supports_tool_calling": bool(openai_model_config.get("supports_tool_calling", True)),
"supports_stream_usage": bool(openai_model_config.get("supports_stream_usage", False)),
"verify_ssl": bool(openai_model_config.get("verify_ssl", True)),
}
return openai_runner_params
raise ValueError(f"不支持的 runner_type: {runner_type}")
Expand Down
38 changes: 17 additions & 21 deletions dayu/startup/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,21 @@ def load_llm_models(self) -> dict[str, ModelConfig]:
FileNotFoundError: 配置文件不存在
json.JSONDecodeError: JSON 格式错误
"""
if self._llm_models_cache is None:
loaded_models = _require_structured_config_object(
self._resolver.read_json("llm_models.json", required=True),
filename="llm_models.json",
)
normalized_models: dict[str, ModelConfig] = {}
for raw_model_name, raw_model_config in loaded_models.items():
model_name = str(raw_model_name or "").strip()
if not model_name:
raise TypeError("llm_models.json 的 key 必须是非空字符串")
if model_name.startswith("_"):
continue
if not isinstance(raw_model_config, dict):
raise TypeError(f"llm_models.json.{model_name} 必须是对象")
normalized_models[model_name] = cast(ModelConfig, raw_model_config)
self._llm_models_cache = normalized_models
llm_models = self._llm_models_cache
if llm_models is None:
raise RuntimeError("llm_models.json 缓存为空")
return cast(dict[str, ModelConfig], deepcopy(llm_models))
loaded_models = _require_structured_config_object(
self._resolver.read_json("llm_models.json", required=True),
filename="llm_models.json",
)
normalized_models: dict[str, ModelConfig] = {}
for raw_model_name, raw_model_config in loaded_models.items():
model_name = str(raw_model_name or "").strip()
if not model_name:
raise TypeError("llm_models.json 的 key 必须是非空字符串")
if model_name.startswith("_"):
continue
if not isinstance(raw_model_config, dict):
raise TypeError(f"llm_models.json.{model_name} 必须是对象")
normalized_models[model_name] = cast(ModelConfig, raw_model_config)
return cast(dict[str, ModelConfig], deepcopy(normalized_models))

def load_llm_model(self, model_name: str) -> ModelConfig:
"""加载指定 LLM 模型的配置(包含环境变量替换)
Expand Down Expand Up @@ -323,9 +318,10 @@ def load_llm_model(self, model_name: str) -> ModelConfig:
Log.error(error_msg, module=MODULE)
raise KeyError(error_msg)

raw_config = models[model_name]
model_config = cast(
ModelConfig,
_replace_model_config_env_vars(cast(ModelConfigJsonValue, models[model_name])),
_replace_model_config_env_vars(cast(ModelConfigJsonValue, raw_config)),
)
ensure_runner_type_enabled(model_config.get("runner_type"))
return cast(ModelConfig, model_config)
Expand Down