Skip to content
Merged
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
7 changes: 5 additions & 2 deletions src-tauri/src/command/llm_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::command::base::CommandResult;
use crate::config::{LlmChainLink, LlmProviderPreset, PRIMARY_LLM_ENTRY_ID};
use crate::credential::{self, CredentialStatus, EffectiveCredentialSource, ResolvedCredential};
use crate::error::AppError;
use crate::llm::service::{http_client_for, normalize_provider_base_url, provider_requires_key, LlmService};
use crate::llm::service::{
http_client_for, normalize_provider_base_url, provider_requires_key, rig_http_client_for,
LlmService,
};
use crate::llm::types::ConnectionReport;
use rig::client::ModelListingClient;
use rig::model::{Model, ModelList, ModelListingError};
Expand Down Expand Up @@ -264,7 +267,7 @@ async fn fetch_model_list_with_credential(
"noop"
});
let base_url = normalize_provider_base_url(&provider, base_url);
let http_client = http_client_for(insecure)?;
let http_client = rig_http_client_for(insecure)?;

let models = match provider {
LlmProviderPreset::Anthropic => {
Expand Down
20 changes: 19 additions & 1 deletion src-tauri/src/llm/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl LlmService {
});

// 自签证书场景下跳过 TLS 校验的开关:默认关闭,仅对 insecure=true 的服务生效
let http_client = http_client_for(link.insecure)?;
let http_client = rig_http_client_for(link.insecure)?;

let backend = match provider {
LlmProviderPreset::Anthropic => LlmBackend::Anthropic(
Expand Down Expand Up @@ -853,6 +853,24 @@ pub(crate) fn http_client_for(insecure: bool) -> Result<reqwest::Client, AppErro
})
}

/// 供 rig 0.40 `ClientBuilder::http_client` 使用的客户端构造。
///
/// rig-core 0.40 依赖 reqwest 0.13,而本项目直接依赖 reqwest 0.12——两个版本
/// 的 `Client` 是不同的类型;`HttpClientExt` 只为 rig 内部的 reqwest 0.13
/// `Client` 实现,因此不能把本项目的 0.12 client 传给 `.http_client()`(E0599)。
/// 这里直接用 rig 重新导出的 `ReqwestClient`(即 reqwest 0.13 的 `Client`)
/// 构造,`insecure` 开关的 TLS 行为保持不变。
pub(crate) fn rig_http_client_for(
insecure: bool,
) -> Result<rig::http_client::ReqwestClient, AppError> {
rig::http_client::ReqwestClient::builder()
.tls_danger_accept_invalid_certs(insecure)
.build()
.map_err(|error| {
AppError::configuration("无法创建 HTTP 客户端").with_detail(error.to_string())
})
}

pub(crate) fn normalize_provider_base_url(provider: &LlmProviderPreset, base_url: &str) -> String {
let base_url = base_url.trim().trim_end_matches('/');
if matches!(provider, LlmProviderPreset::Ollama) {
Expand Down
Loading