mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-12-07 16:56:29 +08:00
Compare commits
1 Commits
v2.15.6
...
update-max
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebe617b733 |
4
.github/workflows/deploy_preview.yml
vendored
4
.github/workflows/deploy_preview.yml
vendored
@@ -3,7 +3,9 @@ name: VercelPreviewDeployment
|
|||||||
on:
|
on:
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types:
|
types:
|
||||||
- review_requested
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
|
||||||
env:
|
env:
|
||||||
VERCEL_TEAM: ${{ secrets.VERCEL_TEAM }}
|
VERCEL_TEAM: ${{ secrets.VERCEL_TEAM }}
|
||||||
|
|||||||
39
.github/workflows/test.yml
vendored
39
.github/workflows/test.yml
vendored
@@ -1,39 +0,0 @@
|
|||||||
name: Run Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
tags:
|
|
||||||
- "!*"
|
|
||||||
pull_request:
|
|
||||||
types:
|
|
||||||
- review_requested
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
cache: "yarn"
|
|
||||||
|
|
||||||
- name: Cache node_modules
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: node_modules
|
|
||||||
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-node_modules-
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: yarn install
|
|
||||||
|
|
||||||
- name: Run Jest tests
|
|
||||||
run: yarn test:ci
|
|
||||||
@@ -10,7 +10,6 @@ import { handle as alibabaHandler } from "../../alibaba";
|
|||||||
import { handle as moonshotHandler } from "../../moonshot";
|
import { handle as moonshotHandler } from "../../moonshot";
|
||||||
import { handle as stabilityHandler } from "../../stability";
|
import { handle as stabilityHandler } from "../../stability";
|
||||||
import { handle as iflytekHandler } from "../../iflytek";
|
import { handle as iflytekHandler } from "../../iflytek";
|
||||||
import { handle as xaiHandler } from "../../xai";
|
|
||||||
import { handle as proxyHandler } from "../../proxy";
|
import { handle as proxyHandler } from "../../proxy";
|
||||||
|
|
||||||
async function handle(
|
async function handle(
|
||||||
@@ -39,8 +38,6 @@ async function handle(
|
|||||||
return stabilityHandler(req, { params });
|
return stabilityHandler(req, { params });
|
||||||
case ApiPath.Iflytek:
|
case ApiPath.Iflytek:
|
||||||
return iflytekHandler(req, { params });
|
return iflytekHandler(req, { params });
|
||||||
case ApiPath.XAI:
|
|
||||||
return xaiHandler(req, { params });
|
|
||||||
case ApiPath.OpenAI:
|
case ApiPath.OpenAI:
|
||||||
return openaiHandler(req, { params });
|
return openaiHandler(req, { params });
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -92,9 +92,6 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
|
|||||||
systemApiKey =
|
systemApiKey =
|
||||||
serverConfig.iflytekApiKey + ":" + serverConfig.iflytekApiSecret;
|
serverConfig.iflytekApiKey + ":" + serverConfig.iflytekApiSecret;
|
||||||
break;
|
break;
|
||||||
case ModelProvider.XAI:
|
|
||||||
systemApiKey = serverConfig.xaiApiKey;
|
|
||||||
break;
|
|
||||||
case ModelProvider.GPT:
|
case ModelProvider.GPT:
|
||||||
default:
|
default:
|
||||||
if (req.nextUrl.pathname.includes("azure/deployments")) {
|
if (req.nextUrl.pathname.includes("azure/deployments")) {
|
||||||
|
|||||||
128
app/api/xai.ts
128
app/api/xai.ts
@@ -1,128 +0,0 @@
|
|||||||
import { getServerSideConfig } from "@/app/config/server";
|
|
||||||
import {
|
|
||||||
XAI_BASE_URL,
|
|
||||||
ApiPath,
|
|
||||||
ModelProvider,
|
|
||||||
ServiceProvider,
|
|
||||||
} from "@/app/constant";
|
|
||||||
import { prettyObject } from "@/app/utils/format";
|
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
|
||||||
import { auth } from "@/app/api/auth";
|
|
||||||
import { isModelAvailableInServer } from "@/app/utils/model";
|
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
|
||||||
|
|
||||||
export async function handle(
|
|
||||||
req: NextRequest,
|
|
||||||
{ params }: { params: { path: string[] } },
|
|
||||||
) {
|
|
||||||
console.log("[XAI Route] params ", params);
|
|
||||||
|
|
||||||
if (req.method === "OPTIONS") {
|
|
||||||
return NextResponse.json({ body: "OK" }, { status: 200 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const authResult = auth(req, ModelProvider.XAI);
|
|
||||||
if (authResult.error) {
|
|
||||||
return NextResponse.json(authResult, {
|
|
||||||
status: 401,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await request(req);
|
|
||||||
return response;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("[XAI] ", e);
|
|
||||||
return NextResponse.json(prettyObject(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function request(req: NextRequest) {
|
|
||||||
const controller = new AbortController();
|
|
||||||
|
|
||||||
// alibaba use base url or just remove the path
|
|
||||||
let path = `${req.nextUrl.pathname}`.replaceAll(ApiPath.XAI, "");
|
|
||||||
|
|
||||||
let baseUrl = serverConfig.xaiUrl || XAI_BASE_URL;
|
|
||||||
|
|
||||||
if (!baseUrl.startsWith("http")) {
|
|
||||||
baseUrl = `https://${baseUrl}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseUrl.endsWith("/")) {
|
|
||||||
baseUrl = baseUrl.slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("[Proxy] ", path);
|
|
||||||
console.log("[Base Url]", baseUrl);
|
|
||||||
|
|
||||||
const timeoutId = setTimeout(
|
|
||||||
() => {
|
|
||||||
controller.abort();
|
|
||||||
},
|
|
||||||
10 * 60 * 1000,
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchUrl = `${baseUrl}${path}`;
|
|
||||||
const fetchOptions: RequestInit = {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: req.headers.get("Authorization") ?? "",
|
|
||||||
},
|
|
||||||
method: req.method,
|
|
||||||
body: req.body,
|
|
||||||
redirect: "manual",
|
|
||||||
// @ts-ignore
|
|
||||||
duplex: "half",
|
|
||||||
signal: controller.signal,
|
|
||||||
};
|
|
||||||
|
|
||||||
// #1815 try to refuse some request to some models
|
|
||||||
if (serverConfig.customModels && req.body) {
|
|
||||||
try {
|
|
||||||
const clonedBody = await req.text();
|
|
||||||
fetchOptions.body = clonedBody;
|
|
||||||
|
|
||||||
const jsonBody = JSON.parse(clonedBody) as { model?: string };
|
|
||||||
|
|
||||||
// not undefined and is false
|
|
||||||
if (
|
|
||||||
isModelAvailableInServer(
|
|
||||||
serverConfig.customModels,
|
|
||||||
jsonBody?.model as string,
|
|
||||||
ServiceProvider.XAI as string,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
error: true,
|
|
||||||
message: `you are not allowed to use ${jsonBody?.model} model`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 403,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`[XAI] filter`, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const res = await fetch(fetchUrl, fetchOptions);
|
|
||||||
|
|
||||||
// to prevent browser prompt for credentials
|
|
||||||
const newHeaders = new Headers(res.headers);
|
|
||||||
newHeaders.delete("www-authenticate");
|
|
||||||
// to disable nginx buffering
|
|
||||||
newHeaders.set("X-Accel-Buffering", "no");
|
|
||||||
|
|
||||||
return new Response(res.body, {
|
|
||||||
status: res.status,
|
|
||||||
statusText: res.statusText,
|
|
||||||
headers: newHeaders,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@ import { QwenApi } from "./platforms/alibaba";
|
|||||||
import { HunyuanApi } from "./platforms/tencent";
|
import { HunyuanApi } from "./platforms/tencent";
|
||||||
import { MoonshotApi } from "./platforms/moonshot";
|
import { MoonshotApi } from "./platforms/moonshot";
|
||||||
import { SparkApi } from "./platforms/iflytek";
|
import { SparkApi } from "./platforms/iflytek";
|
||||||
import { XAIApi } from "./platforms/xai";
|
|
||||||
|
|
||||||
export const ROLES = ["system", "user", "assistant"] as const;
|
export const ROLES = ["system", "user", "assistant"] as const;
|
||||||
export type MessageRole = (typeof ROLES)[number];
|
export type MessageRole = (typeof ROLES)[number];
|
||||||
@@ -153,9 +152,6 @@ export class ClientApi {
|
|||||||
case ModelProvider.Iflytek:
|
case ModelProvider.Iflytek:
|
||||||
this.llm = new SparkApi();
|
this.llm = new SparkApi();
|
||||||
break;
|
break;
|
||||||
case ModelProvider.XAI:
|
|
||||||
this.llm = new XAIApi();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
this.llm = new ChatGPTApi();
|
this.llm = new ChatGPTApi();
|
||||||
}
|
}
|
||||||
@@ -243,7 +239,6 @@ export function getHeaders(ignoreHeaders: boolean = false) {
|
|||||||
const isAlibaba = modelConfig.providerName === ServiceProvider.Alibaba;
|
const isAlibaba = modelConfig.providerName === ServiceProvider.Alibaba;
|
||||||
const isMoonshot = modelConfig.providerName === ServiceProvider.Moonshot;
|
const isMoonshot = modelConfig.providerName === ServiceProvider.Moonshot;
|
||||||
const isIflytek = modelConfig.providerName === ServiceProvider.Iflytek;
|
const isIflytek = modelConfig.providerName === ServiceProvider.Iflytek;
|
||||||
const isXAI = modelConfig.providerName === ServiceProvider.XAI;
|
|
||||||
const isEnabledAccessControl = accessStore.enabledAccessControl();
|
const isEnabledAccessControl = accessStore.enabledAccessControl();
|
||||||
const apiKey = isGoogle
|
const apiKey = isGoogle
|
||||||
? accessStore.googleApiKey
|
? accessStore.googleApiKey
|
||||||
@@ -257,8 +252,6 @@ export function getHeaders(ignoreHeaders: boolean = false) {
|
|||||||
? accessStore.alibabaApiKey
|
? accessStore.alibabaApiKey
|
||||||
: isMoonshot
|
: isMoonshot
|
||||||
? accessStore.moonshotApiKey
|
? accessStore.moonshotApiKey
|
||||||
: isXAI
|
|
||||||
? accessStore.xaiApiKey
|
|
||||||
: isIflytek
|
: isIflytek
|
||||||
? accessStore.iflytekApiKey && accessStore.iflytekApiSecret
|
? accessStore.iflytekApiKey && accessStore.iflytekApiSecret
|
||||||
? accessStore.iflytekApiKey + ":" + accessStore.iflytekApiSecret
|
? accessStore.iflytekApiKey + ":" + accessStore.iflytekApiSecret
|
||||||
@@ -273,7 +266,6 @@ export function getHeaders(ignoreHeaders: boolean = false) {
|
|||||||
isAlibaba,
|
isAlibaba,
|
||||||
isMoonshot,
|
isMoonshot,
|
||||||
isIflytek,
|
isIflytek,
|
||||||
isXAI,
|
|
||||||
apiKey,
|
apiKey,
|
||||||
isEnabledAccessControl,
|
isEnabledAccessControl,
|
||||||
};
|
};
|
||||||
@@ -336,8 +328,6 @@ export function getClientApi(provider: ServiceProvider): ClientApi {
|
|||||||
return new ClientApi(ModelProvider.Moonshot);
|
return new ClientApi(ModelProvider.Moonshot);
|
||||||
case ServiceProvider.Iflytek:
|
case ServiceProvider.Iflytek:
|
||||||
return new ClientApi(ModelProvider.Iflytek);
|
return new ClientApi(ModelProvider.Iflytek);
|
||||||
case ServiceProvider.XAI:
|
|
||||||
return new ClientApi(ModelProvider.XAI);
|
|
||||||
default:
|
default:
|
||||||
return new ClientApi(ModelProvider.GPT);
|
return new ClientApi(ModelProvider.GPT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { getMessageTextContent, isVisionModel } from "@/app/utils";
|
|||||||
import { preProcessImageContent, stream } from "@/app/utils/chat";
|
import { preProcessImageContent, stream } from "@/app/utils/chat";
|
||||||
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
|
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
|
||||||
import { RequestPayload } from "./openai";
|
import { RequestPayload } from "./openai";
|
||||||
import { fetch } from "@/app/utils/stream";
|
|
||||||
|
|
||||||
export type MultiBlockContent = {
|
export type MultiBlockContent = {
|
||||||
type: "image" | "text";
|
type: "image" | "text";
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
import { getClientConfig } from "@/app/config/client";
|
import { getClientConfig } from "@/app/config/client";
|
||||||
import { getMessageTextContent } from "@/app/utils";
|
import { getMessageTextContent } from "@/app/utils";
|
||||||
import { RequestPayload } from "./openai";
|
import { RequestPayload } from "./openai";
|
||||||
import { fetch } from "@/app/utils/stream";
|
|
||||||
|
|
||||||
export class MoonshotApi implements LLMApi {
|
export class MoonshotApi implements LLMApi {
|
||||||
private disableListModels = true;
|
private disableListModels = true;
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import {
|
|||||||
isVisionModel,
|
isVisionModel,
|
||||||
isDalle3 as _isDalle3,
|
isDalle3 as _isDalle3,
|
||||||
} from "@/app/utils";
|
} from "@/app/utils";
|
||||||
import { fetch } from "@/app/utils/stream";
|
|
||||||
|
|
||||||
export interface OpenAIListModelResponse {
|
export interface OpenAIListModelResponse {
|
||||||
object: string;
|
object: string;
|
||||||
@@ -64,7 +63,7 @@ export interface RequestPayload {
|
|||||||
presence_penalty: number;
|
presence_penalty: number;
|
||||||
frequency_penalty: number;
|
frequency_penalty: number;
|
||||||
top_p: number;
|
top_p: number;
|
||||||
max_tokens?: number;
|
max_completions_tokens?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DalleRequestPayload {
|
export interface DalleRequestPayload {
|
||||||
@@ -229,13 +228,16 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
presence_penalty: !isO1 ? modelConfig.presence_penalty : 0,
|
presence_penalty: !isO1 ? modelConfig.presence_penalty : 0,
|
||||||
frequency_penalty: !isO1 ? modelConfig.frequency_penalty : 0,
|
frequency_penalty: !isO1 ? modelConfig.frequency_penalty : 0,
|
||||||
top_p: !isO1 ? modelConfig.top_p : 1,
|
top_p: !isO1 ? modelConfig.top_p : 1,
|
||||||
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
|
// max_completions_tokens: Math.max(modelConfig.max_completions_tokens, 1024),
|
||||||
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
|
// Please do not ask me why not send max_completions_tokens, no reason, this param is just shit, I dont want to explain anymore.
|
||||||
};
|
};
|
||||||
|
|
||||||
// add max_tokens to vision model
|
// add max_completions_tokens to vision model
|
||||||
if (visionModel) {
|
if (visionModel) {
|
||||||
requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
|
requestPayload["max_completions_tokens"] = Math.max(
|
||||||
|
modelConfig.max_completions_tokens,
|
||||||
|
4000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +355,7 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
// make a fetch request
|
// make a fetch request
|
||||||
const requestTimeoutId = setTimeout(
|
const requestTimeoutId = setTimeout(
|
||||||
() => controller.abort(),
|
() => controller.abort(),
|
||||||
isDalle3 || isO1 ? REQUEST_TIMEOUT_MS * 4 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow.
|
isDalle3 || isO1 ? REQUEST_TIMEOUT_MS * 2 : REQUEST_TIMEOUT_MS, // dalle3 using b64_json is slow.
|
||||||
);
|
);
|
||||||
|
|
||||||
const res = await fetch(chatPath, chatPayload);
|
const res = await fetch(chatPath, chatPayload);
|
||||||
|
|||||||
@@ -1,193 +0,0 @@
|
|||||||
"use client";
|
|
||||||
// azure and openai, using same models. so using same LLMApi.
|
|
||||||
import { ApiPath, XAI_BASE_URL, XAI, REQUEST_TIMEOUT_MS } from "@/app/constant";
|
|
||||||
import {
|
|
||||||
useAccessStore,
|
|
||||||
useAppConfig,
|
|
||||||
useChatStore,
|
|
||||||
ChatMessageTool,
|
|
||||||
usePluginStore,
|
|
||||||
} from "@/app/store";
|
|
||||||
import { stream } from "@/app/utils/chat";
|
|
||||||
import {
|
|
||||||
ChatOptions,
|
|
||||||
getHeaders,
|
|
||||||
LLMApi,
|
|
||||||
LLMModel,
|
|
||||||
SpeechOptions,
|
|
||||||
} from "../api";
|
|
||||||
import { getClientConfig } from "@/app/config/client";
|
|
||||||
import { getMessageTextContent } from "@/app/utils";
|
|
||||||
import { RequestPayload } from "./openai";
|
|
||||||
import { fetch } from "@/app/utils/stream";
|
|
||||||
|
|
||||||
export class XAIApi implements LLMApi {
|
|
||||||
private disableListModels = true;
|
|
||||||
|
|
||||||
path(path: string): string {
|
|
||||||
const accessStore = useAccessStore.getState();
|
|
||||||
|
|
||||||
let baseUrl = "";
|
|
||||||
|
|
||||||
if (accessStore.useCustomConfig) {
|
|
||||||
baseUrl = accessStore.xaiUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseUrl.length === 0) {
|
|
||||||
const isApp = !!getClientConfig()?.isApp;
|
|
||||||
const apiPath = ApiPath.XAI;
|
|
||||||
baseUrl = isApp ? XAI_BASE_URL : apiPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (baseUrl.endsWith("/")) {
|
|
||||||
baseUrl = baseUrl.slice(0, baseUrl.length - 1);
|
|
||||||
}
|
|
||||||
if (!baseUrl.startsWith("http") && !baseUrl.startsWith(ApiPath.XAI)) {
|
|
||||||
baseUrl = "https://" + baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("[Proxy Endpoint] ", baseUrl, path);
|
|
||||||
|
|
||||||
return [baseUrl, path].join("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
extractMessage(res: any) {
|
|
||||||
return res.choices?.at(0)?.message?.content ?? "";
|
|
||||||
}
|
|
||||||
|
|
||||||
speech(options: SpeechOptions): Promise<ArrayBuffer> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
async chat(options: ChatOptions) {
|
|
||||||
const messages: ChatOptions["messages"] = [];
|
|
||||||
for (const v of options.messages) {
|
|
||||||
const content = getMessageTextContent(v);
|
|
||||||
messages.push({ role: v.role, content });
|
|
||||||
}
|
|
||||||
|
|
||||||
const modelConfig = {
|
|
||||||
...useAppConfig.getState().modelConfig,
|
|
||||||
...useChatStore.getState().currentSession().mask.modelConfig,
|
|
||||||
...{
|
|
||||||
model: options.config.model,
|
|
||||||
providerName: options.config.providerName,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const requestPayload: RequestPayload = {
|
|
||||||
messages,
|
|
||||||
stream: options.config.stream,
|
|
||||||
model: modelConfig.model,
|
|
||||||
temperature: modelConfig.temperature,
|
|
||||||
presence_penalty: modelConfig.presence_penalty,
|
|
||||||
frequency_penalty: modelConfig.frequency_penalty,
|
|
||||||
top_p: modelConfig.top_p,
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log("[Request] xai payload: ", requestPayload);
|
|
||||||
|
|
||||||
const shouldStream = !!options.config.stream;
|
|
||||||
const controller = new AbortController();
|
|
||||||
options.onController?.(controller);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const chatPath = this.path(XAI.ChatPath);
|
|
||||||
const chatPayload = {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(requestPayload),
|
|
||||||
signal: controller.signal,
|
|
||||||
headers: getHeaders(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// make a fetch request
|
|
||||||
const requestTimeoutId = setTimeout(
|
|
||||||
() => controller.abort(),
|
|
||||||
REQUEST_TIMEOUT_MS,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (shouldStream) {
|
|
||||||
const [tools, funcs] = usePluginStore
|
|
||||||
.getState()
|
|
||||||
.getAsTools(
|
|
||||||
useChatStore.getState().currentSession().mask?.plugin || [],
|
|
||||||
);
|
|
||||||
return stream(
|
|
||||||
chatPath,
|
|
||||||
requestPayload,
|
|
||||||
getHeaders(),
|
|
||||||
tools as any,
|
|
||||||
funcs,
|
|
||||||
controller,
|
|
||||||
// parseSSE
|
|
||||||
(text: string, runTools: ChatMessageTool[]) => {
|
|
||||||
// console.log("parseSSE", text, runTools);
|
|
||||||
const json = JSON.parse(text);
|
|
||||||
const choices = json.choices as Array<{
|
|
||||||
delta: {
|
|
||||||
content: string;
|
|
||||||
tool_calls: ChatMessageTool[];
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
const tool_calls = choices[0]?.delta?.tool_calls;
|
|
||||||
if (tool_calls?.length > 0) {
|
|
||||||
const index = tool_calls[0]?.index;
|
|
||||||
const id = tool_calls[0]?.id;
|
|
||||||
const args = tool_calls[0]?.function?.arguments;
|
|
||||||
if (id) {
|
|
||||||
runTools.push({
|
|
||||||
id,
|
|
||||||
type: tool_calls[0]?.type,
|
|
||||||
function: {
|
|
||||||
name: tool_calls[0]?.function?.name as string,
|
|
||||||
arguments: args,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
|
||||||
runTools[index]["function"]["arguments"] += args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return choices[0]?.delta?.content;
|
|
||||||
},
|
|
||||||
// processToolMessage, include tool_calls message and tool call results
|
|
||||||
(
|
|
||||||
requestPayload: RequestPayload,
|
|
||||||
toolCallMessage: any,
|
|
||||||
toolCallResult: any[],
|
|
||||||
) => {
|
|
||||||
// @ts-ignore
|
|
||||||
requestPayload?.messages?.splice(
|
|
||||||
// @ts-ignore
|
|
||||||
requestPayload?.messages?.length,
|
|
||||||
0,
|
|
||||||
toolCallMessage,
|
|
||||||
...toolCallResult,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const res = await fetch(chatPath, chatPayload);
|
|
||||||
clearTimeout(requestTimeoutId);
|
|
||||||
|
|
||||||
const resJson = await res.json();
|
|
||||||
const message = this.extractMessage(resJson);
|
|
||||||
options.onFinish(message);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log("[Request] failed to make a chat request", e);
|
|
||||||
options.onError?.(e as Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async usage() {
|
|
||||||
return {
|
|
||||||
used: 0,
|
|
||||||
total: 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async models(): Promise<LLMModel[]> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -115,14 +115,11 @@ import { getClientConfig } from "../config/client";
|
|||||||
import { useAllModels } from "../utils/hooks";
|
import { useAllModels } from "../utils/hooks";
|
||||||
import { MultimodalContent } from "../client/api";
|
import { MultimodalContent } from "../client/api";
|
||||||
|
|
||||||
|
const localStorage = safeLocalStorage();
|
||||||
import { ClientApi } from "../client/api";
|
import { ClientApi } from "../client/api";
|
||||||
import { createTTSPlayer } from "../utils/audio";
|
import { createTTSPlayer } from "../utils/audio";
|
||||||
import { MsEdgeTTS, OUTPUT_FORMAT } from "../utils/ms_edge_tts";
|
import { MsEdgeTTS, OUTPUT_FORMAT } from "../utils/ms_edge_tts";
|
||||||
|
|
||||||
import { isEmpty } from "lodash-es";
|
|
||||||
|
|
||||||
const localStorage = safeLocalStorage();
|
|
||||||
|
|
||||||
const ttsPlayer = createTTSPlayer();
|
const ttsPlayer = createTTSPlayer();
|
||||||
|
|
||||||
const Markdown = dynamic(async () => (await import("./markdown")).Markdown, {
|
const Markdown = dynamic(async () => (await import("./markdown")).Markdown, {
|
||||||
@@ -1018,7 +1015,7 @@ function _Chat() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const doSubmit = (userInput: string) => {
|
const doSubmit = (userInput: string) => {
|
||||||
if (userInput.trim() === "" && isEmpty(attachImages)) return;
|
if (userInput.trim() === "") return;
|
||||||
const matchCommand = chatCommands.match(userInput);
|
const matchCommand = chatCommands.match(userInput);
|
||||||
if (matchCommand.matched) {
|
if (matchCommand.matched) {
|
||||||
setUserInput("");
|
setUserInput("");
|
||||||
|
|||||||
@@ -140,9 +140,6 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
&-narrow {
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-logo {
|
.sidebar-logo {
|
||||||
|
|||||||
@@ -169,12 +169,6 @@ export function PreCode(props: { children: any }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CustomCode(props: { children: any; className?: string }) {
|
function CustomCode(props: { children: any; className?: string }) {
|
||||||
const chatStore = useChatStore();
|
|
||||||
const session = chatStore.currentSession();
|
|
||||||
const config = useAppConfig();
|
|
||||||
const enableCodeFold =
|
|
||||||
session.mask?.enableCodeFold !== false && config.enableCodeFold;
|
|
||||||
|
|
||||||
const ref = useRef<HTMLPreElement>(null);
|
const ref = useRef<HTMLPreElement>(null);
|
||||||
const [collapsed, setCollapsed] = useState(true);
|
const [collapsed, setCollapsed] = useState(true);
|
||||||
const [showToggle, setShowToggle] = useState(false);
|
const [showToggle, setShowToggle] = useState(false);
|
||||||
@@ -190,30 +184,25 @@ function CustomCode(props: { children: any; className?: string }) {
|
|||||||
const toggleCollapsed = () => {
|
const toggleCollapsed = () => {
|
||||||
setCollapsed((collapsed) => !collapsed);
|
setCollapsed((collapsed) => !collapsed);
|
||||||
};
|
};
|
||||||
const renderShowMoreButton = () => {
|
|
||||||
if (showToggle && enableCodeFold && collapsed) {
|
|
||||||
return (
|
|
||||||
<div className={`show-hide-button ${collapsed ? "collapsed" : "expanded"}`}>
|
|
||||||
<button onClick={toggleCollapsed}>{Locale.NewChat.More}</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<code
|
<code
|
||||||
className={props?.className}
|
className={props?.className}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
style={{
|
style={{
|
||||||
maxHeight: enableCodeFold && collapsed ? "400px" : "none",
|
maxHeight: collapsed ? "400px" : "none",
|
||||||
overflowY: "hidden",
|
overflowY: "hidden",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</code>
|
</code>
|
||||||
|
{showToggle && collapsed && (
|
||||||
{renderShowMoreButton()}
|
<div
|
||||||
|
className={`show-hide-button ${collapsed ? "collapsed" : "expanded"}`}
|
||||||
|
>
|
||||||
|
<button onClick={toggleCollapsed}>{Locale.NewChat.More}</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,23 +183,6 @@ export function MaskConfig(props: {
|
|||||||
></input>
|
></input>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
)}
|
)}
|
||||||
{globalConfig.enableCodeFold && (
|
|
||||||
<ListItem
|
|
||||||
title={Locale.Mask.Config.CodeFold.Title}
|
|
||||||
subTitle={Locale.Mask.Config.CodeFold.SubTitle}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
aria-label={Locale.Mask.Config.CodeFold.Title}
|
|
||||||
type="checkbox"
|
|
||||||
checked={props.mask.enableCodeFold !== false}
|
|
||||||
onChange={(e) => {
|
|
||||||
props.updateMask((mask) => {
|
|
||||||
mask.enableCodeFold = e.currentTarget.checked;
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
></input>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!props.shouldSyncFromGlobal ? (
|
{!props.shouldSyncFromGlobal ? (
|
||||||
<ListItem
|
<ListItem
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import Locale, {
|
|||||||
changeLang,
|
changeLang,
|
||||||
getLang,
|
getLang,
|
||||||
} from "../locales";
|
} from "../locales";
|
||||||
import { copyToClipboard, clientUpdate, semverCompare } from "../utils";
|
import { copyToClipboard } from "../utils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
Anthropic,
|
Anthropic,
|
||||||
@@ -59,7 +59,6 @@ import {
|
|||||||
ByteDance,
|
ByteDance,
|
||||||
Alibaba,
|
Alibaba,
|
||||||
Moonshot,
|
Moonshot,
|
||||||
XAI,
|
|
||||||
Google,
|
Google,
|
||||||
GoogleSafetySettingsThreshold,
|
GoogleSafetySettingsThreshold,
|
||||||
OPENAI_BASE_URL,
|
OPENAI_BASE_URL,
|
||||||
@@ -586,7 +585,7 @@ export function Settings() {
|
|||||||
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
||||||
const currentVersion = updateStore.formatVersion(updateStore.version);
|
const currentVersion = updateStore.formatVersion(updateStore.version);
|
||||||
const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
|
const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
|
||||||
const hasNewVersion = semverCompare(currentVersion, remoteId) === -1;
|
const hasNewVersion = currentVersion !== remoteId;
|
||||||
const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
|
const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
|
||||||
|
|
||||||
function checkUpdate(force = false) {
|
function checkUpdate(force = false) {
|
||||||
@@ -1195,45 +1194,6 @@ export function Settings() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const XAIConfigComponent = accessStore.provider === ServiceProvider.XAI && (
|
|
||||||
<>
|
|
||||||
<ListItem
|
|
||||||
title={Locale.Settings.Access.XAI.Endpoint.Title}
|
|
||||||
subTitle={
|
|
||||||
Locale.Settings.Access.XAI.Endpoint.SubTitle + XAI.ExampleEndpoint
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
aria-label={Locale.Settings.Access.XAI.Endpoint.Title}
|
|
||||||
type="text"
|
|
||||||
value={accessStore.xaiUrl}
|
|
||||||
placeholder={XAI.ExampleEndpoint}
|
|
||||||
onChange={(e) =>
|
|
||||||
accessStore.update(
|
|
||||||
(access) => (access.xaiUrl = e.currentTarget.value),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
></input>
|
|
||||||
</ListItem>
|
|
||||||
<ListItem
|
|
||||||
title={Locale.Settings.Access.XAI.ApiKey.Title}
|
|
||||||
subTitle={Locale.Settings.Access.XAI.ApiKey.SubTitle}
|
|
||||||
>
|
|
||||||
<PasswordInput
|
|
||||||
aria-label={Locale.Settings.Access.XAI.ApiKey.Title}
|
|
||||||
value={accessStore.xaiApiKey}
|
|
||||||
type="text"
|
|
||||||
placeholder={Locale.Settings.Access.XAI.ApiKey.Placeholder}
|
|
||||||
onChange={(e) => {
|
|
||||||
accessStore.update(
|
|
||||||
(access) => (access.xaiApiKey = e.currentTarget.value),
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ListItem>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const stabilityConfigComponent = accessStore.provider ===
|
const stabilityConfigComponent = accessStore.provider ===
|
||||||
ServiceProvider.Stability && (
|
ServiceProvider.Stability && (
|
||||||
<>
|
<>
|
||||||
@@ -1397,17 +1357,9 @@ export function Settings() {
|
|||||||
{checkingUpdate ? (
|
{checkingUpdate ? (
|
||||||
<LoadingIcon />
|
<LoadingIcon />
|
||||||
) : hasNewVersion ? (
|
) : hasNewVersion ? (
|
||||||
clientConfig?.isApp ? (
|
<Link href={updateUrl} target="_blank" className="link">
|
||||||
<IconButton
|
{Locale.Settings.Update.GoToUpdate}
|
||||||
icon={<ResetIcon></ResetIcon>}
|
</Link>
|
||||||
text={Locale.Settings.Update.GoToUpdate}
|
|
||||||
onClick={() => clientUpdate()}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Link href={updateUrl} target="_blank" className="link">
|
|
||||||
{Locale.Settings.Update.GoToUpdate}
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
) : (
|
) : (
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<ResetIcon></ResetIcon>}
|
icon={<ResetIcon></ResetIcon>}
|
||||||
@@ -1557,22 +1509,6 @@ export function Settings() {
|
|||||||
}
|
}
|
||||||
></input>
|
></input>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<ListItem
|
|
||||||
title={Locale.Mask.Config.CodeFold.Title}
|
|
||||||
subTitle={Locale.Mask.Config.CodeFold.SubTitle}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
aria-label={Locale.Mask.Config.CodeFold.Title}
|
|
||||||
type="checkbox"
|
|
||||||
checked={config.enableCodeFold}
|
|
||||||
data-testid="enable-code-fold-checkbox"
|
|
||||||
onChange={(e) =>
|
|
||||||
updateConfig(
|
|
||||||
(config) => (config.enableCodeFold = e.currentTarget.checked),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
></input>
|
|
||||||
</ListItem>
|
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
<SyncItems />
|
<SyncItems />
|
||||||
@@ -1692,7 +1628,6 @@ export function Settings() {
|
|||||||
{moonshotConfigComponent}
|
{moonshotConfigComponent}
|
||||||
{stabilityConfigComponent}
|
{stabilityConfigComponent}
|
||||||
{lflytekConfigComponent}
|
{lflytekConfigComponent}
|
||||||
{XAIConfigComponent}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -165,17 +165,11 @@ export function SideBarHeader(props: {
|
|||||||
subTitle?: string | React.ReactNode;
|
subTitle?: string | React.ReactNode;
|
||||||
logo?: React.ReactNode;
|
logo?: React.ReactNode;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
shouldNarrow?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
const { title, subTitle, logo, children, shouldNarrow } = props;
|
const { title, subTitle, logo, children } = props;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div
|
<div className={styles["sidebar-header"]} data-tauri-drag-region>
|
||||||
className={`${styles["sidebar-header"]} ${
|
|
||||||
shouldNarrow ? styles["sidebar-header-narrow"] : ""
|
|
||||||
}`}
|
|
||||||
data-tauri-drag-region
|
|
||||||
>
|
|
||||||
<div className={styles["sidebar-title-container"]}>
|
<div className={styles["sidebar-title-container"]}>
|
||||||
<div className={styles["sidebar-title"]} data-tauri-drag-region>
|
<div className={styles["sidebar-title"]} data-tauri-drag-region>
|
||||||
{title}
|
{title}
|
||||||
@@ -233,7 +227,6 @@ export function SideBar(props: { className?: string }) {
|
|||||||
title="NextChat"
|
title="NextChat"
|
||||||
subTitle="Build your own AI assistant."
|
subTitle="Build your own AI assistant."
|
||||||
logo={<ChatGptIcon />}
|
logo={<ChatGptIcon />}
|
||||||
shouldNarrow={shouldNarrow}
|
|
||||||
>
|
>
|
||||||
<div className={styles["sidebar-header-bar"]}>
|
<div className={styles["sidebar-header-bar"]}>
|
||||||
<IconButton
|
<IconButton
|
||||||
|
|||||||
@@ -71,10 +71,6 @@ declare global {
|
|||||||
IFLYTEK_API_KEY?: string;
|
IFLYTEK_API_KEY?: string;
|
||||||
IFLYTEK_API_SECRET?: string;
|
IFLYTEK_API_SECRET?: string;
|
||||||
|
|
||||||
// xai only
|
|
||||||
XAI_URL?: string;
|
|
||||||
XAI_API_KEY?: string;
|
|
||||||
|
|
||||||
// custom template for preprocessing user input
|
// custom template for preprocessing user input
|
||||||
DEFAULT_INPUT_TEMPLATE?: string;
|
DEFAULT_INPUT_TEMPLATE?: string;
|
||||||
}
|
}
|
||||||
@@ -150,7 +146,6 @@ export const getServerSideConfig = () => {
|
|||||||
const isAlibaba = !!process.env.ALIBABA_API_KEY;
|
const isAlibaba = !!process.env.ALIBABA_API_KEY;
|
||||||
const isMoonshot = !!process.env.MOONSHOT_API_KEY;
|
const isMoonshot = !!process.env.MOONSHOT_API_KEY;
|
||||||
const isIflytek = !!process.env.IFLYTEK_API_KEY;
|
const isIflytek = !!process.env.IFLYTEK_API_KEY;
|
||||||
const isXAI = !!process.env.XAI_API_KEY;
|
|
||||||
// const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? "";
|
// const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? "";
|
||||||
// const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
|
// const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
|
||||||
// const randomIndex = Math.floor(Math.random() * apiKeys.length);
|
// const randomIndex = Math.floor(Math.random() * apiKeys.length);
|
||||||
@@ -213,10 +208,6 @@ export const getServerSideConfig = () => {
|
|||||||
iflytekApiKey: process.env.IFLYTEK_API_KEY,
|
iflytekApiKey: process.env.IFLYTEK_API_KEY,
|
||||||
iflytekApiSecret: process.env.IFLYTEK_API_SECRET,
|
iflytekApiSecret: process.env.IFLYTEK_API_SECRET,
|
||||||
|
|
||||||
isXAI,
|
|
||||||
xaiUrl: process.env.XAI_URL,
|
|
||||||
xaiApiKey: getApiKey(process.env.XAI_API_KEY),
|
|
||||||
|
|
||||||
cloudflareAccountId: process.env.CLOUDFLARE_ACCOUNT_ID,
|
cloudflareAccountId: process.env.CLOUDFLARE_ACCOUNT_ID,
|
||||||
cloudflareKVNamespaceId: process.env.CLOUDFLARE_KV_NAMESPACE_ID,
|
cloudflareKVNamespaceId: process.env.CLOUDFLARE_KV_NAMESPACE_ID,
|
||||||
cloudflareKVApiKey: getApiKey(process.env.CLOUDFLARE_KV_API_KEY),
|
cloudflareKVApiKey: getApiKey(process.env.CLOUDFLARE_KV_API_KEY),
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ export const TENCENT_BASE_URL = "https://hunyuan.tencentcloudapi.com";
|
|||||||
export const MOONSHOT_BASE_URL = "https://api.moonshot.cn";
|
export const MOONSHOT_BASE_URL = "https://api.moonshot.cn";
|
||||||
export const IFLYTEK_BASE_URL = "https://spark-api-open.xf-yun.com";
|
export const IFLYTEK_BASE_URL = "https://spark-api-open.xf-yun.com";
|
||||||
|
|
||||||
export const XAI_BASE_URL = "https://api.x.ai";
|
|
||||||
|
|
||||||
export const CACHE_URL_PREFIX = "/api/cache";
|
export const CACHE_URL_PREFIX = "/api/cache";
|
||||||
export const UPLOAD_URL = `${CACHE_URL_PREFIX}/upload`;
|
export const UPLOAD_URL = `${CACHE_URL_PREFIX}/upload`;
|
||||||
|
|
||||||
@@ -61,7 +59,6 @@ export enum ApiPath {
|
|||||||
Iflytek = "/api/iflytek",
|
Iflytek = "/api/iflytek",
|
||||||
Stability = "/api/stability",
|
Stability = "/api/stability",
|
||||||
Artifacts = "/api/artifacts",
|
Artifacts = "/api/artifacts",
|
||||||
XAI = "/api/xai",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SlotID {
|
export enum SlotID {
|
||||||
@@ -114,7 +111,6 @@ export enum ServiceProvider {
|
|||||||
Moonshot = "Moonshot",
|
Moonshot = "Moonshot",
|
||||||
Stability = "Stability",
|
Stability = "Stability",
|
||||||
Iflytek = "Iflytek",
|
Iflytek = "Iflytek",
|
||||||
XAI = "XAI",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings
|
// Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings
|
||||||
@@ -137,7 +133,6 @@ export enum ModelProvider {
|
|||||||
Hunyuan = "Hunyuan",
|
Hunyuan = "Hunyuan",
|
||||||
Moonshot = "Moonshot",
|
Moonshot = "Moonshot",
|
||||||
Iflytek = "Iflytek",
|
Iflytek = "Iflytek",
|
||||||
XAI = "XAI",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Stability = {
|
export const Stability = {
|
||||||
@@ -220,11 +215,6 @@ export const Iflytek = {
|
|||||||
ChatPath: "v1/chat/completions",
|
ChatPath: "v1/chat/completions",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const XAI = {
|
|
||||||
ExampleEndpoint: XAI_BASE_URL,
|
|
||||||
ChatPath: "v1/chat/completions",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
|
||||||
// export const DEFAULT_SYSTEM_TEMPLATE = `
|
// export const DEFAULT_SYSTEM_TEMPLATE = `
|
||||||
// You are ChatGPT, a large language model trained by {{ServiceProvider}}.
|
// You are ChatGPT, a large language model trained by {{ServiceProvider}}.
|
||||||
@@ -374,8 +364,6 @@ const iflytekModels = [
|
|||||||
"4.0Ultra",
|
"4.0Ultra",
|
||||||
];
|
];
|
||||||
|
|
||||||
const xAIModes = ["grok-beta"];
|
|
||||||
|
|
||||||
let seq = 1000; // 内置的模型序号生成器从1000开始
|
let seq = 1000; // 内置的模型序号生成器从1000开始
|
||||||
export const DEFAULT_MODELS = [
|
export const DEFAULT_MODELS = [
|
||||||
...openaiModels.map((name) => ({
|
...openaiModels.map((name) => ({
|
||||||
@@ -488,17 +476,6 @@ export const DEFAULT_MODELS = [
|
|||||||
sorted: 10,
|
sorted: 10,
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
...xAIModes.map((name) => ({
|
|
||||||
name,
|
|
||||||
available: true,
|
|
||||||
sorted: seq++,
|
|
||||||
provider: {
|
|
||||||
id: "xai",
|
|
||||||
providerName: "XAI",
|
|
||||||
providerType: "xai",
|
|
||||||
sorted: 11,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const CHAT_PAGE_SIZE = 15;
|
export const CHAT_PAGE_SIZE = 15;
|
||||||
|
|||||||
7
app/global.d.ts
vendored
7
app/global.d.ts
vendored
@@ -26,13 +26,6 @@ declare interface Window {
|
|||||||
isPermissionGranted(): Promise<boolean>;
|
isPermissionGranted(): Promise<boolean>;
|
||||||
sendNotification(options: string | Options): void;
|
sendNotification(options: string | Options): void;
|
||||||
};
|
};
|
||||||
updater: {
|
|
||||||
checkUpdate(): Promise<UpdateResult>;
|
|
||||||
installUpdate(): Promise<void>;
|
|
||||||
onUpdaterEvent(
|
|
||||||
handler: (status: UpdateStatusResult) => void,
|
|
||||||
): Promise<UnlistenFn>;
|
|
||||||
};
|
|
||||||
http: {
|
http: {
|
||||||
fetch<T>(
|
fetch<T>(
|
||||||
url: string,
|
url: string,
|
||||||
|
|||||||
@@ -205,8 +205,6 @@ const cn = {
|
|||||||
IsChecking: "正在检查更新...",
|
IsChecking: "正在检查更新...",
|
||||||
FoundUpdate: (x: string) => `发现新版本:${x}`,
|
FoundUpdate: (x: string) => `发现新版本:${x}`,
|
||||||
GoToUpdate: "前往更新",
|
GoToUpdate: "前往更新",
|
||||||
Success: "更新成功!",
|
|
||||||
Failed: "更新失败",
|
|
||||||
},
|
},
|
||||||
SendKey: "发送键",
|
SendKey: "发送键",
|
||||||
Theme: "主题",
|
Theme: "主题",
|
||||||
@@ -462,17 +460,6 @@ const cn = {
|
|||||||
SubTitle: "样例:",
|
SubTitle: "样例:",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XAI: {
|
|
||||||
ApiKey: {
|
|
||||||
Title: "接口密钥",
|
|
||||||
SubTitle: "使用自定义XAI API Key",
|
|
||||||
Placeholder: "XAI API Key",
|
|
||||||
},
|
|
||||||
Endpoint: {
|
|
||||||
Title: "接口地址",
|
|
||||||
SubTitle: "样例:",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Stability: {
|
Stability: {
|
||||||
ApiKey: {
|
ApiKey: {
|
||||||
Title: "接口密钥",
|
Title: "接口密钥",
|
||||||
@@ -508,8 +495,8 @@ const cn = {
|
|||||||
|
|
||||||
Model: "模型 (model)",
|
Model: "模型 (model)",
|
||||||
CompressModel: {
|
CompressModel: {
|
||||||
Title: "对话摘要模型",
|
Title: "压缩模型",
|
||||||
SubTitle: "用于压缩历史记录、生成对话标题的模型",
|
SubTitle: "用于压缩历史记录的模型",
|
||||||
},
|
},
|
||||||
Temperature: {
|
Temperature: {
|
||||||
Title: "随机性 (temperature)",
|
Title: "随机性 (temperature)",
|
||||||
@@ -678,10 +665,6 @@ const cn = {
|
|||||||
Title: "启用Artifacts",
|
Title: "启用Artifacts",
|
||||||
SubTitle: "启用之后可以直接渲染HTML页面",
|
SubTitle: "启用之后可以直接渲染HTML页面",
|
||||||
},
|
},
|
||||||
CodeFold: {
|
|
||||||
Title: "启用代码折叠",
|
|
||||||
SubTitle: "启用之后可以自动折叠/展开过长的代码块",
|
|
||||||
},
|
|
||||||
Share: {
|
Share: {
|
||||||
Title: "分享此面具",
|
Title: "分享此面具",
|
||||||
SubTitle: "生成此面具的直达链接",
|
SubTitle: "生成此面具的直达链接",
|
||||||
|
|||||||
@@ -207,8 +207,6 @@ const en: LocaleType = {
|
|||||||
IsChecking: "Checking update...",
|
IsChecking: "Checking update...",
|
||||||
FoundUpdate: (x: string) => `Found new version: ${x}`,
|
FoundUpdate: (x: string) => `Found new version: ${x}`,
|
||||||
GoToUpdate: "Update",
|
GoToUpdate: "Update",
|
||||||
Success: "Update Successful.",
|
|
||||||
Failed: "Update Failed.",
|
|
||||||
},
|
},
|
||||||
SendKey: "Send Key",
|
SendKey: "Send Key",
|
||||||
Theme: "Theme",
|
Theme: "Theme",
|
||||||
@@ -446,17 +444,6 @@ const en: LocaleType = {
|
|||||||
SubTitle: "Example: ",
|
SubTitle: "Example: ",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XAI: {
|
|
||||||
ApiKey: {
|
|
||||||
Title: "XAI API Key",
|
|
||||||
SubTitle: "Use a custom XAI API Key",
|
|
||||||
Placeholder: "XAI API Key",
|
|
||||||
},
|
|
||||||
Endpoint: {
|
|
||||||
Title: "Endpoint Address",
|
|
||||||
SubTitle: "Example: ",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Stability: {
|
Stability: {
|
||||||
ApiKey: {
|
ApiKey: {
|
||||||
Title: "Stability API Key",
|
Title: "Stability API Key",
|
||||||
@@ -513,8 +500,8 @@ const en: LocaleType = {
|
|||||||
|
|
||||||
Model: "Model",
|
Model: "Model",
|
||||||
CompressModel: {
|
CompressModel: {
|
||||||
Title: "Summary Model",
|
Title: "Compression Model",
|
||||||
SubTitle: "Model used to compress history and generate title",
|
SubTitle: "Model used to compress history",
|
||||||
},
|
},
|
||||||
Temperature: {
|
Temperature: {
|
||||||
Title: "Temperature",
|
Title: "Temperature",
|
||||||
@@ -688,11 +675,6 @@ const en: LocaleType = {
|
|||||||
Title: "Enable Artifacts",
|
Title: "Enable Artifacts",
|
||||||
SubTitle: "Can render HTML page when enable artifacts.",
|
SubTitle: "Can render HTML page when enable artifacts.",
|
||||||
},
|
},
|
||||||
CodeFold: {
|
|
||||||
Title: "Enable CodeFold",
|
|
||||||
SubTitle:
|
|
||||||
"Automatically collapse/expand overly long code blocks when CodeFold is enabled",
|
|
||||||
},
|
|
||||||
Share: {
|
Share: {
|
||||||
Title: "Share This Mask",
|
Title: "Share This Mask",
|
||||||
SubTitle: "Generate a link to this mask",
|
SubTitle: "Generate a link to this mask",
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
MOONSHOT_BASE_URL,
|
MOONSHOT_BASE_URL,
|
||||||
STABILITY_BASE_URL,
|
STABILITY_BASE_URL,
|
||||||
IFLYTEK_BASE_URL,
|
IFLYTEK_BASE_URL,
|
||||||
XAI_BASE_URL,
|
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
import { getHeaders } from "../client/api";
|
import { getHeaders } from "../client/api";
|
||||||
import { getClientConfig } from "../config/client";
|
import { getClientConfig } from "../config/client";
|
||||||
@@ -45,8 +44,6 @@ const DEFAULT_STABILITY_URL = isApp ? STABILITY_BASE_URL : ApiPath.Stability;
|
|||||||
|
|
||||||
const DEFAULT_IFLYTEK_URL = isApp ? IFLYTEK_BASE_URL : ApiPath.Iflytek;
|
const DEFAULT_IFLYTEK_URL = isApp ? IFLYTEK_BASE_URL : ApiPath.Iflytek;
|
||||||
|
|
||||||
const DEFAULT_XAI_URL = isApp ? XAI_BASE_URL : ApiPath.XAI;
|
|
||||||
|
|
||||||
const DEFAULT_ACCESS_STATE = {
|
const DEFAULT_ACCESS_STATE = {
|
||||||
accessCode: "",
|
accessCode: "",
|
||||||
useCustomConfig: false,
|
useCustomConfig: false,
|
||||||
@@ -104,10 +101,6 @@ const DEFAULT_ACCESS_STATE = {
|
|||||||
iflytekApiKey: "",
|
iflytekApiKey: "",
|
||||||
iflytekApiSecret: "",
|
iflytekApiSecret: "",
|
||||||
|
|
||||||
// xai
|
|
||||||
xaiUrl: DEFAULT_XAI_URL,
|
|
||||||
xaiApiKey: "",
|
|
||||||
|
|
||||||
// server config
|
// server config
|
||||||
needCode: true,
|
needCode: true,
|
||||||
hideUserApiKey: false,
|
hideUserApiKey: false,
|
||||||
@@ -176,10 +169,6 @@ export const useAccessStore = createPersistStore(
|
|||||||
return ensure(get(), ["iflytekApiKey"]);
|
return ensure(get(), ["iflytekApiKey"]);
|
||||||
},
|
},
|
||||||
|
|
||||||
isValidXAI() {
|
|
||||||
return ensure(get(), ["xaiApiKey"]);
|
|
||||||
},
|
|
||||||
|
|
||||||
isAuthorized() {
|
isAuthorized() {
|
||||||
this.fetch();
|
this.fetch();
|
||||||
|
|
||||||
@@ -195,7 +184,6 @@ export const useAccessStore = createPersistStore(
|
|||||||
this.isValidTencent() ||
|
this.isValidTencent() ||
|
||||||
this.isValidMoonshot() ||
|
this.isValidMoonshot() ||
|
||||||
this.isValidIflytek() ||
|
this.isValidIflytek() ||
|
||||||
this.isValidXAI() ||
|
|
||||||
!this.enabledAccessControl() ||
|
!this.enabledAccessControl() ||
|
||||||
(this.enabledAccessControl() && ensure(get(), ["accessCode"]))
|
(this.enabledAccessControl() && ensure(get(), ["accessCode"]))
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -372,16 +372,22 @@ export const useChatStore = createPersistStore(
|
|||||||
|
|
||||||
if (attachImages && attachImages.length > 0) {
|
if (attachImages && attachImages.length > 0) {
|
||||||
mContent = [
|
mContent = [
|
||||||
...(userContent
|
{
|
||||||
? [{ type: "text" as const, text: userContent }]
|
type: "text",
|
||||||
: []),
|
text: userContent,
|
||||||
...attachImages.map((url) => ({
|
},
|
||||||
type: "image_url" as const,
|
|
||||||
image_url: { url },
|
|
||||||
})),
|
|
||||||
];
|
];
|
||||||
|
mContent = mContent.concat(
|
||||||
|
attachImages.map((url) => {
|
||||||
|
return {
|
||||||
|
type: "image_url",
|
||||||
|
image_url: {
|
||||||
|
url: url,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let userMessage: ChatMessage = createMessage({
|
let userMessage: ChatMessage = createMessage({
|
||||||
role: "user",
|
role: "user",
|
||||||
content: mContent,
|
content: mContent,
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ export const DEFAULT_CONFIG = {
|
|||||||
|
|
||||||
enableArtifacts: true, // show artifacts config
|
enableArtifacts: true, // show artifacts config
|
||||||
|
|
||||||
enableCodeFold: true, // code fold config
|
|
||||||
|
|
||||||
disablePromptHint: false,
|
disablePromptHint: false,
|
||||||
|
|
||||||
dontShowMaskSplashScreen: false, // dont show splash screen when create chat
|
dontShowMaskSplashScreen: false, // dont show splash screen when create chat
|
||||||
@@ -67,7 +65,7 @@ export const DEFAULT_CONFIG = {
|
|||||||
providerName: "OpenAI" as ServiceProvider,
|
providerName: "OpenAI" as ServiceProvider,
|
||||||
temperature: 0.5,
|
temperature: 0.5,
|
||||||
top_p: 1,
|
top_p: 1,
|
||||||
max_tokens: 4000,
|
max_completions_tokens: 4000,
|
||||||
presence_penalty: 0,
|
presence_penalty: 0,
|
||||||
frequency_penalty: 0,
|
frequency_penalty: 0,
|
||||||
sendMemory: true,
|
sendMemory: true,
|
||||||
@@ -129,7 +127,7 @@ export const ModalConfigValidator = {
|
|||||||
model(x: string) {
|
model(x: string) {
|
||||||
return x as ModelType;
|
return x as ModelType;
|
||||||
},
|
},
|
||||||
max_tokens(x: number) {
|
max_completions_tokens(x: number) {
|
||||||
return limitNumber(x, 0, 512000, 1024);
|
return limitNumber(x, 0, 512000, 1024);
|
||||||
},
|
},
|
||||||
presence_penalty(x: number) {
|
presence_penalty(x: number) {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export type Mask = {
|
|||||||
builtin: boolean;
|
builtin: boolean;
|
||||||
plugin?: string[];
|
plugin?: string[];
|
||||||
enableArtifacts?: boolean;
|
enableArtifacts?: boolean;
|
||||||
enableCodeFold?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_MASK_STATE = {
|
export const DEFAULT_MASK_STATE = {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
} from "../constant";
|
} from "../constant";
|
||||||
import { getClientConfig } from "../config/client";
|
import { getClientConfig } from "../config/client";
|
||||||
import { createPersistStore } from "../utils/store";
|
import { createPersistStore } from "../utils/store";
|
||||||
import { clientUpdate } from "../utils";
|
|
||||||
import ChatGptIcon from "../icons/chatgpt.png";
|
import ChatGptIcon from "../icons/chatgpt.png";
|
||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
import { ClientApi } from "../client/api";
|
import { ClientApi } from "../client/api";
|
||||||
@@ -120,7 +119,6 @@ export const useUpdateStore = createPersistStore(
|
|||||||
icon: `${ChatGptIcon.src}`,
|
icon: `${ChatGptIcon.src}`,
|
||||||
sound: "Default",
|
sound: "Default",
|
||||||
});
|
});
|
||||||
clientUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
34
app/utils.ts
34
app/utils.ts
@@ -386,37 +386,3 @@ export function getOperationId(operation: {
|
|||||||
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}`
|
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clientUpdate() {
|
|
||||||
// this a wild for updating client app
|
|
||||||
return window.__TAURI__?.updater
|
|
||||||
.checkUpdate()
|
|
||||||
.then((updateResult) => {
|
|
||||||
if (updateResult.shouldUpdate) {
|
|
||||||
window.__TAURI__?.updater
|
|
||||||
.installUpdate()
|
|
||||||
.then((result) => {
|
|
||||||
showToast(Locale.Settings.Update.Success);
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.error("[Install Update Error]", e);
|
|
||||||
showToast(Locale.Settings.Update.Failed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.error("[Check Update Error]", e);
|
|
||||||
showToast(Locale.Settings.Update.Failed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb
|
|
||||||
export function semverCompare(a: string, b: string) {
|
|
||||||
if (a.startsWith(b + "-")) return -1;
|
|
||||||
if (b.startsWith(a + "-")) return 1;
|
|
||||||
return a.localeCompare(b, undefined, {
|
|
||||||
numeric: true,
|
|
||||||
sensitivity: "case",
|
|
||||||
caseFirst: "upper",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
"mask": "npx tsx app/masks/build.ts",
|
"mask": "npx tsx app/masks/build.ts",
|
||||||
"mask:watch": "npx watch \"yarn mask\" app/masks",
|
"mask:watch": "npx watch \"yarn mask\" app/masks",
|
||||||
"dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"",
|
"dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"",
|
||||||
"build": "yarn mask && cross-env BUILD_MODE=standalone next build",
|
"build": "yarn test:ci && yarn mask && cross-env BUILD_MODE=standalone next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"export": "yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
|
"export": "yarn test:ci && yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
|
||||||
"export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
|
"export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
|
||||||
"app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"",
|
"app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"",
|
||||||
"app:build": "yarn mask && yarn tauri build",
|
"app:build": "yarn test:ci && yarn mask && yarn tauri build",
|
||||||
"prompts": "node ./scripts/fetch-prompts.mjs",
|
"prompts": "node ./scripts/fetch-prompts.mjs",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev",
|
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev",
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
"@tauri-apps/cli": "1.5.11",
|
"@tauri-apps/cli": "1.5.11",
|
||||||
"@testing-library/jest-dom": "^6.4.8",
|
"@testing-library/jest-dom": "^6.4.8",
|
||||||
"@testing-library/react": "^16.0.0",
|
"@testing-library/react": "^16.0.0",
|
||||||
"@types/jest": "^29.5.13",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/js-yaml": "4.0.9",
|
"@types/js-yaml": "4.0.9",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.11.30",
|
"@types/node": "^20.11.30",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "NextChat",
|
"productName": "NextChat",
|
||||||
"version": "2.15.6"
|
"version": "2.15.4"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
"endpoints": [
|
"endpoints": [
|
||||||
"https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json"
|
"https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json"
|
||||||
],
|
],
|
||||||
"dialog": true,
|
"dialog": false,
|
||||||
"windows": {
|
"windows": {
|
||||||
"installMode": "passive"
|
"installMode": "passive"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2263,10 +2263,10 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/istanbul-lib-report" "*"
|
"@types/istanbul-lib-report" "*"
|
||||||
|
|
||||||
"@types/jest@^29.5.13":
|
"@types/jest@^29.5.12":
|
||||||
version "29.5.13"
|
version "29.5.12"
|
||||||
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.13.tgz#8bc571659f401e6a719a7bf0dbcb8b78c71a8adc"
|
resolved "https://registry.npmmirror.com/@types/jest/-/jest-29.5.12.tgz#7f7dc6eb4cf246d2474ed78744b05d06ce025544"
|
||||||
integrity sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==
|
integrity sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==
|
||||||
dependencies:
|
dependencies:
|
||||||
expect "^29.0.0"
|
expect "^29.0.0"
|
||||||
pretty-format "^29.0.0"
|
pretty-format "^29.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user