Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat tauir #5527

Closed
Closed
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: 2 additions & 2 deletions .github/workflows/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
node-version: 18
- name: get version
run: echo "PACKAGE_VERSION=$(node -p "require('./src-tauri/tauri.conf.json').package.version")" >> $GITHUB_ENV
run: echo "PACKAGE_VERSION=$(node -p "require('./src-tauri/tauri.conf.json').version")" >> $GITHUB_ENV
- name: create release
id: create-release
uses: actions/github-script@v6
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
if: matrix.config.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
sudo apt-get install -y libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1 libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
run: yarn install # change this to npm or pnpm depending on which one you use
- uses: tauri-apps/tauri-action@v0
Expand Down
3 changes: 2 additions & 1 deletion app/client/platforms/alibaba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { getMessageTextContent, fetch } from "@/app/utils";

export interface OpenAIListModelResponse {
object: string;
Expand Down Expand Up @@ -178,6 +178,7 @@ export class QwenApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
8 changes: 1 addition & 7 deletions app/client/platforms/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
usePluginStore,
ChatMessageTool,
} from "@/app/store";
import { getClientConfig } from "@/app/config/client";
import { DEFAULT_API_HOST } from "@/app/constant";
import { getMessageTextContent, isVisionModel } from "@/app/utils";
import { preProcessImageContent, stream } from "@/app/utils/chat";
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
Expand Down Expand Up @@ -386,11 +384,7 @@ export class ClaudeApi implements LLMApi {

// if endpoint is empty, use default endpoint
if (baseUrl.trim().length === 0) {
const isApp = !!getClientConfig()?.isApp;

baseUrl = isApp
? DEFAULT_API_HOST + "/api/proxy/anthropic"
: ApiPath.Anthropic;
baseUrl = ApiPath.Anthropic;
}

if (!baseUrl.startsWith("http") && !baseUrl.startsWith("/api")) {
Expand Down
3 changes: 2 additions & 1 deletion app/client/platforms/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { getMessageTextContent, fetch } from "@/app/utils";

export interface OpenAIListModelResponse {
object: string;
Expand Down Expand Up @@ -197,6 +197,7 @@ export class ErnieApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
3 changes: 2 additions & 1 deletion app/client/platforms/bytedance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { getMessageTextContent, fetch } from "@/app/utils";

export interface OpenAIListModelResponse {
object: string;
Expand Down Expand Up @@ -165,6 +165,7 @@ export class DoubaoApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
7 changes: 3 additions & 4 deletions app/client/platforms/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
SpeechOptions,
} from "../api";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
import { getClientConfig } from "@/app/config/client";
import { DEFAULT_API_HOST } from "@/app/constant";
import Locale from "../../locales";
import {
EventStreamContentType,
Expand All @@ -20,6 +18,7 @@ import {
getMessageTextContent,
getMessageImages,
isVisionModel,
fetch,
} from "@/app/utils";
import { preProcessImageContent } from "@/app/utils/chat";

Expand All @@ -32,9 +31,8 @@ export class GeminiProApi implements LLMApi {
baseUrl = accessStore.googleUrl;
}

const isApp = !!getClientConfig()?.isApp;
if (baseUrl.length === 0) {
baseUrl = isApp ? DEFAULT_API_HOST + `/api/proxy/google` : ApiPath.Google;
baseUrl = ApiPath.Google;
}
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.slice(0, baseUrl.length - 1);
Expand Down Expand Up @@ -217,6 +215,7 @@ export class GeminiProApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
15 changes: 4 additions & 11 deletions app/client/platforms/iflytek.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"use client";
import {
ApiPath,
DEFAULT_API_HOST,
Iflytek,
REQUEST_TIMEOUT_MS,
} from "@/app/constant";
import { ApiPath, Iflytek, REQUEST_TIMEOUT_MS } from "@/app/constant";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";

import {
Expand All @@ -20,8 +15,7 @@ import {
fetchEventSource,
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { getMessageTextContent, fetch } from "@/app/utils";

import { RequestPayload } from "./openai";

Expand All @@ -38,9 +32,7 @@ export class SparkApi implements LLMApi {
}

if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
const apiPath = ApiPath.Iflytek;
baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
baseUrl = ApiPath.Iflytek;
}

if (baseUrl.endsWith("/")) {
Expand Down Expand Up @@ -149,6 +141,7 @@ export class SparkApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
11 changes: 2 additions & 9 deletions app/client/platforms/moonshot.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"use client";
// azure and openai, using same models. so using same LLMApi.
import {
ApiPath,
DEFAULT_API_HOST,
Moonshot,
REQUEST_TIMEOUT_MS,
} from "@/app/constant";
import { ApiPath, Moonshot, REQUEST_TIMEOUT_MS } from "@/app/constant";
import {
useAccessStore,
useAppConfig,
Expand All @@ -21,7 +16,6 @@ import {
LLMModel,
SpeechOptions,
} from "../api";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent } from "@/app/utils";
import { RequestPayload } from "./openai";

Expand All @@ -38,9 +32,8 @@ export class MoonshotApi implements LLMApi {
}

if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
const apiPath = ApiPath.Moonshot;
baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
baseUrl = apiPath;
}

if (baseUrl.endsWith("/")) {
Expand Down
6 changes: 1 addition & 5 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// azure and openai, using same models. so using same LLMApi.
import {
ApiPath,
DEFAULT_API_HOST,
DEFAULT_MODELS,
OpenaiPath,
Azure,
Expand Down Expand Up @@ -36,7 +35,6 @@ import {
SpeechOptions,
} from "../api";
import Locale from "../../locales";
import { getClientConfig } from "@/app/config/client";
import {
getMessageTextContent,
isVisionModel,
Expand Down Expand Up @@ -96,9 +94,7 @@ export class ChatGPTApi implements LLMApi {
}

if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
const apiPath = isAzure ? ApiPath.Azure : ApiPath.OpenAI;
baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
baseUrl = isAzure ? ApiPath.Azure : ApiPath.OpenAI;
}

if (baseUrl.endsWith("/")) {
Expand Down
11 changes: 4 additions & 7 deletions app/client/platforms/tencent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { ApiPath, DEFAULT_API_HOST, REQUEST_TIMEOUT_MS } from "@/app/constant";
import { ApiPath, REQUEST_TIMEOUT_MS } from "@/app/constant";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";

import {
Expand All @@ -16,8 +16,7 @@ import {
fetchEventSource,
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { getMessageTextContent, isVisionModel } from "@/app/utils";
import { getMessageTextContent, isVisionModel, fetch } from "@/app/utils";
import mapKeys from "lodash-es/mapKeys";
import mapValues from "lodash-es/mapValues";
import isArray from "lodash-es/isArray";
Expand Down Expand Up @@ -69,10 +68,7 @@ export class HunyuanApi implements LLMApi {
}

if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
baseUrl = isApp
? DEFAULT_API_HOST + "/api/proxy/tencent"
: ApiPath.Tencent;
baseUrl = ApiPath.Tencent;
}

if (baseUrl.endsWith("/")) {
Expand Down Expand Up @@ -179,6 +175,7 @@ export class HunyuanApi implements LLMApi {
controller.signal.onabort = finish;

fetchEventSource(chatPath, {
fetch: fetch as any,
...chatPayload,
async onopen(res) {
clearTimeout(requestTimeoutId);
Expand Down
1 change: 0 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const RUNTIME_CONFIG_DOM = "danger-runtime-config";

export const STABILITY_BASE_URL = "https://api.stability.ai";

export const DEFAULT_API_HOST = "https://api.nextchat.dev";
export const OPENAI_BASE_URL = "https://api.openai.com";
export const ANTHROPIC_BASE_URL = "https://api.anthropic.com";

Expand Down
61 changes: 10 additions & 51 deletions app/store/access.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ApiPath,
DEFAULT_API_HOST,
GoogleSafetySettingsThreshold,
ServiceProvider,
StoreKey,
Expand All @@ -15,54 +14,14 @@ let fetchState = 0; // 0 not fetch, 1 fetching, 2 done

const isApp = getClientConfig()?.buildMode === "export";

const DEFAULT_OPENAI_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/openai"
: ApiPath.OpenAI;

const DEFAULT_GOOGLE_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/google"
: ApiPath.Google;

const DEFAULT_ANTHROPIC_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/anthropic"
: ApiPath.Anthropic;

const DEFAULT_BAIDU_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/baidu"
: ApiPath.Baidu;

const DEFAULT_BYTEDANCE_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/bytedance"
: ApiPath.ByteDance;

const DEFAULT_ALIBABA_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/alibaba"
: ApiPath.Alibaba;

const DEFAULT_TENCENT_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/tencent"
: ApiPath.Tencent;

const DEFAULT_MOONSHOT_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/moonshot"
: ApiPath.Moonshot;

const DEFAULT_STABILITY_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/stability"
: ApiPath.Stability;

const DEFAULT_IFLYTEK_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/iflytek"
: ApiPath.Iflytek;

const DEFAULT_ACCESS_STATE = {
accessCode: "",
useCustomConfig: false,

provider: ServiceProvider.OpenAI,

// openai
openaiUrl: DEFAULT_OPENAI_URL,
openaiUrl: ApiPath.OpenAI as string,
openaiApiKey: "",

// azure
Expand All @@ -71,44 +30,44 @@ const DEFAULT_ACCESS_STATE = {
azureApiVersion: "2023-08-01-preview",

// google ai studio
googleUrl: DEFAULT_GOOGLE_URL,
googleUrl: ApiPath.Google as string,
googleApiKey: "",
googleApiVersion: "v1",
googleSafetySettings: GoogleSafetySettingsThreshold.BLOCK_ONLY_HIGH,

// anthropic
anthropicUrl: DEFAULT_ANTHROPIC_URL,
anthropicUrl: ApiPath.Anthropic as string,
anthropicApiKey: "",
anthropicApiVersion: "2023-06-01",

// baidu
baiduUrl: DEFAULT_BAIDU_URL,
baiduUrl: ApiPath.Baidu as string,
baiduApiKey: "",
baiduSecretKey: "",

// bytedance
bytedanceUrl: DEFAULT_BYTEDANCE_URL,
bytedanceUrl: ApiPath.ByteDance as string,
bytedanceApiKey: "",

// alibaba
alibabaUrl: DEFAULT_ALIBABA_URL,
alibabaUrl: ApiPath.Alibaba as string,
alibabaApiKey: "",

// moonshot
moonshotUrl: DEFAULT_MOONSHOT_URL,
moonshotUrl: ApiPath.Moonshot as string,
moonshotApiKey: "",

//stability
stabilityUrl: DEFAULT_STABILITY_URL,
stabilityUrl: ApiPath.Stability as string,
stabilityApiKey: "",

// tencent
tencentUrl: DEFAULT_TENCENT_URL,
tencentUrl: ApiPath.Tencent as string,
tencentSecretKey: "",
tencentSecretId: "",

// iflytek
iflytekUrl: DEFAULT_IFLYTEK_URL,
iflytekUrl: ApiPath.Iflytek as string,
iflytekApiKey: "",
iflytekApiSecret: "",

Expand Down
Loading
Loading