diff --git a/packages/core/src/ai/llm-provider.ts b/packages/core/src/ai/llm-provider.ts index f1b0e5b8..01cbbf9f 100644 --- a/packages/core/src/ai/llm-provider.ts +++ b/packages/core/src/ai/llm-provider.ts @@ -230,6 +230,10 @@ export async function createChatModelFromEndpoint( const temperature = options.temperature ?? 0.7; const maxTokens = options.maxTokens ?? 4096; const streaming = options.streaming ?? true; + // 3,AI提问,如果是 Ollama 且桌面端(Tauri 环境),替换 _streamingFetch 为原生 fetch + if (endpoint.provider === "ollama" && typeof window !== "undefined" && "__TAURI_INTERNALS__" in window) { + setStreamingFetch(globalThis.fetch); + } const endpointFetch = getEndpointFetch(endpoint, model); switch (endpoint.provider) { diff --git a/packages/core/src/ai/test-endpoint.ts b/packages/core/src/ai/test-endpoint.ts index 96ceddbb..ecca29c2 100644 --- a/packages/core/src/ai/test-endpoint.ts +++ b/packages/core/src/ai/test-endpoint.ts @@ -1,7 +1,7 @@ import type { AIEndpoint } from "../types"; import { getDefaultBaseUrl, providerRequiresApiKey } from "../utils"; import { logAIEndpointDebug, summarizeDebugText } from "./request-debug"; -import { getEndpointFetch } from "./llm-provider"; +import { getEndpointFetch, setStreamingFetch } from "./llm-provider"; import { buildOpenAICompatibleUrl, buildProviderModelsUrl, @@ -242,6 +242,10 @@ async function listOllamaModels(endpoint: AIEndpoint): Promise { endpoint.apiKey, endpoint.useExactRequestUrl, ); + // 1, 未获取模型列表,如果是 Ollama 且桌面端(Tauri 环境),替换 _streamingFetch 为原生 fetch + if (endpoint.provider === "ollama" && typeof window !== "undefined" && "__TAURI_INTERNALS__" in window) { + setStreamingFetch(globalThis.fetch); + } const data = await fetchJson(requestUrl, undefined, { endpoint, action: "list-models", @@ -458,6 +462,10 @@ export async function testAIEndpoint( case "ollama": // Pre-check: verify the Ollama server is reachable before running the full test try { + // 2, 已获取模型列表,如果是 Ollama 且桌面端(Tauri 环境),替换 _streamingFetch 为原生 fetch + if (endpoint.provider === "ollama" && typeof window !== "undefined" && "__TAURI_INTERNALS__" in window) { + setStreamingFetch(globalThis.fetch); + } const tagsUrl = buildProviderModelsUrl("ollama", endpoint.baseUrl, endpoint.apiKey, endpoint.useExactRequestUrl); await fetchJson(tagsUrl, undefined, { endpoint, action: "ollama-ping" }); } catch (pingErr) {