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
4 changes: 4 additions & 0 deletions packages/core/src/ai/llm-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/ai/test-endpoint.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -242,6 +242,10 @@ async function listOllamaModels(endpoint: AIEndpoint): Promise<string[]> {
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",
Expand Down Expand Up @@ -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) {
Expand Down