Skip to content

Commit bebcee4

Browse files
committed
Merge remote-tracking branch 'up/website' into website
# Conflicts: # app/store/chat.ts
2 parents 2da502d + 7d3b5f1 commit bebcee4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2223
-318
lines changed

.env.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ ANTHROPIC_API_VERSION=
6666
ANTHROPIC_URL=
6767

6868
### (optional)
69-
WHITE_WEBDEV_ENDPOINTS=
69+
WHITE_WEBDAV_ENDPOINTS=

.eslintrc.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"extends": "next/core-web-vitals",
3-
"plugins": ["prettier"]
3+
"plugins": ["prettier", "unused-imports"],
4+
"rules": {
5+
"unused-imports/no-unused-imports": "warn"
6+
}
47
}

.github/workflows/deploy_preview.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: npm install --global vercel@latest
5050

5151
- name: Cache dependencies
52-
uses: actions/cache@v2
52+
uses: actions/cache@v4
5353
id: cache-npm
5454
with:
5555
path: ~/.npm

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ For ByteDance: use `modelName@bytedance=deploymentName` to customize model name
340340

341341
Change default model
342342

343-
### `WHITE_WEBDEV_ENDPOINTS` (optional)
343+
### `WHITE_WEBDAV_ENDPOINTS` (optional)
344344

345345
You can use this option if you want to increase the number of webdav service addresses you are allowed to access, as required by the format:
346346
- Each address must be a complete endpoint

README_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ ByteDance Api Url.
202202

203203
如果你想禁用从链接解析预制设置,将此环境变量设置为 1 即可。
204204

205-
### `WHITE_WEBDEV_ENDPOINTS` (可选)
205+
### `WHITE_WEBDAV_ENDPOINTS` (可选)
206206

207207
如果你想增加允许访问的webdav服务地址,可以使用该选项,格式要求:
208208
- 每一个地址必须是一个完整的 endpoint

README_JA.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ ByteDance API の URL。
193193

194194
リンクからのプリセット設定解析を無効にしたい場合は、この環境変数を 1 に設定します。
195195

196-
### `WHITE_WEBDEV_ENDPOINTS` (オプション)
196+
### `WHITE_WEBDAV_ENDPOINTS` (オプション)
197197

198198
アクセス許可を与える WebDAV サービスのアドレスを追加したい場合、このオプションを使用します。フォーマット要件:
199199
- 各アドレスは完全なエンドポイントでなければなりません。

app/api/[provider]/[...path]/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiPath } from "@/app/constant";
2-
import { NextRequest, NextResponse } from "next/server";
2+
import { NextRequest } from "next/server";
33
import { handle as openaiHandler } from "../../openai";
44
import { handle as azureHandler } from "../../azure";
55
import { handle as googleHandler } from "../../google";

app/api/alibaba.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getServerSideConfig } from "@/app/config/server";
22
import {
3-
Alibaba,
43
ALIBABA_BASE_URL,
54
ApiPath,
65
ModelProvider,
@@ -10,7 +9,6 @@ import { prettyObject } from "@/app/utils/format";
109
import { NextRequest, NextResponse } from "next/server";
1110
import { auth } from "@/app/api/auth";
1211
import { isModelAvailableInServer } from "@/app/utils/model";
13-
import type { RequestPayload } from "@/app/client/platforms/openai";
1412

1513
const serverConfig = getServerSideConfig();
1614

app/api/anthropic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
ANTHROPIC_BASE_URL,
44
Anthropic,
55
ApiPath,
6-
DEFAULT_MODELS,
76
ServiceProvider,
87
ModelProvider,
98
} from "@/app/constant";
@@ -98,6 +97,7 @@ async function request(req: NextRequest) {
9897
headers: {
9998
"Content-Type": "application/json",
10099
"Cache-Control": "no-store",
100+
"anthropic-dangerous-direct-browser-access": "true",
101101
[authHeaderName]: authValue,
102102
"anthropic-version":
103103
req.headers.get("anthropic-version") ||

app/api/azure.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getServerSideConfig } from "@/app/config/server";
21
import { ModelProvider } from "@/app/constant";
32
import { prettyObject } from "@/app/utils/format";
43
import { NextRequest, NextResponse } from "next/server";

app/api/baidu.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BAIDU_BASE_URL,
44
ApiPath,
55
ModelProvider,
6-
BAIDU_OATUH_URL,
76
ServiceProvider,
87
} from "@/app/constant";
98
import { prettyObject } from "@/app/utils/format";

app/api/common.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { NextRequest, NextResponse } from "next/server";
22
import { getServerSideConfig } from "../config/server";
3-
import {
4-
DEFAULT_MODELS,
5-
OPENAI_BASE_URL,
6-
GEMINI_BASE_URL,
7-
ServiceProvider,
8-
} from "../constant";
3+
import { OPENAI_BASE_URL, ServiceProvider } from "../constant";
94
import { isModelAvailableInServer } from "../utils/model";
105
import { cloudflareAIGatewayUrl } from "../utils/cloudflare";
116

app/api/google.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { NextRequest, NextResponse } from "next/server";
22
import { auth } from "./auth";
33
import { getServerSideConfig } from "@/app/config/server";
4-
import {
5-
ApiPath,
6-
GEMINI_BASE_URL,
7-
Google,
8-
ModelProvider,
9-
} from "@/app/constant";
4+
import { ApiPath, GEMINI_BASE_URL, ModelProvider } from "@/app/constant";
105
import { prettyObject } from "@/app/utils/format";
116

127
const serverConfig = getServerSideConfig();

app/api/iflytek.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getServerSideConfig } from "@/app/config/server";
22
import {
3-
Iflytek,
43
IFLYTEK_BASE_URL,
54
ApiPath,
65
ModelProvider,
@@ -10,7 +9,6 @@ import { prettyObject } from "@/app/utils/format";
109
import { NextRequest, NextResponse } from "next/server";
1110
import { auth } from "@/app/api/auth";
1211
import { isModelAvailableInServer } from "@/app/utils/model";
13-
import type { RequestPayload } from "@/app/client/platforms/openai";
1412
// iflytek
1513

1614
const serverConfig = getServerSideConfig();

app/api/moonshot.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getServerSideConfig } from "@/app/config/server";
22
import {
3-
Moonshot,
43
MOONSHOT_BASE_URL,
54
ApiPath,
65
ModelProvider,
@@ -10,7 +9,6 @@ import { prettyObject } from "@/app/utils/format";
109
import { NextRequest, NextResponse } from "next/server";
1110
import { auth } from "@/app/api/auth";
1211
import { isModelAvailableInServer } from "@/app/utils/model";
13-
import type { RequestPayload } from "@/app/client/platforms/openai";
1412

1513
const serverConfig = getServerSideConfig();
1614

app/api/tencent/route.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { getServerSideConfig } from "@/app/config/server";
2-
import {
3-
TENCENT_BASE_URL,
4-
ApiPath,
5-
ModelProvider,
6-
ServiceProvider,
7-
Tencent,
8-
} from "@/app/constant";
2+
import { TENCENT_BASE_URL, ModelProvider } from "@/app/constant";
93
import { prettyObject } from "@/app/utils/format";
104
import { NextRequest, NextResponse } from "next/server";
115
import { auth } from "@/app/api/auth";
12-
import { isModelAvailableInServer } from "@/app/utils/model";
136
import { getHeader } from "@/app/utils/tencent";
147

158
const serverConfig = getServerSideConfig();

app/api/webdav/[...path]/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = getServerSideConfig();
66

77
const mergedAllowedWebDavEndpoints = [
88
...internalAllowedWebDavEndpoints,
9-
...config.allowedWebDevEndpoints,
9+
...config.allowedWebDavEndpoints,
1010
].filter((domain) => Boolean(domain.trim()));
1111

1212
const normalizeUrl = (url: string) => {

app/client/api.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getClientConfig } from "../config/client";
22
import {
33
ACCESS_CODE_PREFIX,
4-
Azure,
54
ModelProvider,
65
ServiceProvider,
76
} from "../constant";
@@ -26,6 +25,7 @@ export const ROLES = ["system", "user", "assistant"] as const;
2625
export type MessageRole = (typeof ROLES)[number];
2726

2827
export const Models = ["gpt-3.5-turbo", "gpt-4"] as const;
28+
export const TTSModels = ["tts-1", "tts-1-hd"] as const;
2929
export type ChatModel = ModelType;
3030

3131
export interface MultimodalContent {
@@ -54,6 +54,15 @@ export interface LLMConfig {
5454
style?: DalleRequestPayload["style"];
5555
}
5656

57+
export interface SpeechOptions {
58+
model: string;
59+
input: string;
60+
voice: string;
61+
response_format?: string;
62+
speed?: number;
63+
onController?: (controller: AbortController) => void;
64+
}
65+
5766
export interface ChatOptions {
5867
messages: RequestMessage[];
5968
config: LLMConfig;
@@ -88,6 +97,7 @@ export interface LLMModelProvider {
8897

8998
export abstract class LLMApi {
9099
abstract chat(options: ChatOptions): Promise<void>;
100+
abstract speech(options: SpeechOptions): Promise<ArrayBuffer>;
91101
abstract usage(): Promise<LLMUsage>;
92102
abstract models(): Promise<LLMModel[]>;
93103
}
@@ -206,13 +216,16 @@ export function validString(x: string): boolean {
206216
return x?.length > 0;
207217
}
208218

209-
export function getHeaders() {
219+
export function getHeaders(ignoreHeaders: boolean = false) {
210220
const accessStore = useAccessStore.getState();
211221
const chatStore = useChatStore.getState();
212-
const headers: Record<string, string> = {
213-
"Content-Type": "application/json",
214-
Accept: "application/json",
215-
};
222+
let headers: Record<string, string> = {};
223+
if (!ignoreHeaders) {
224+
headers = {
225+
"Content-Type": "application/json",
226+
Accept: "application/json",
227+
};
228+
}
216229

217230
const clientConfig = getClientConfig();
218231

app/client/platforms/alibaba.ts

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getHeaders,
1313
LLMApi,
1414
LLMModel,
15+
SpeechOptions,
1516
MultimodalContent,
1617
} from "../api";
1718
import Locale from "../../locales";
@@ -83,6 +84,10 @@ export class QwenApi implements LLMApi {
8384
return res?.output?.choices?.at(0)?.message?.content ?? "";
8485
}
8586

87+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
88+
throw new Error("Method not implemented.");
89+
}
90+
8691
async chat(options: ChatOptions) {
8792
const messages = options.messages.map((v) => ({
8893
role: v.role,

app/client/platforms/anthropic.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ACCESS_CODE_PREFIX, Anthropic, ApiPath } from "@/app/constant";
2-
import { ChatOptions, getHeaders, LLMApi, MultimodalContent } from "../api";
1+
import { Anthropic, ApiPath } from "@/app/constant";
2+
import { ChatOptions, getHeaders, LLMApi, SpeechOptions } from "../api";
33
import {
44
useAccessStore,
55
useAppConfig,
@@ -9,13 +9,6 @@ import {
99
} from "@/app/store";
1010
import { getClientConfig } from "@/app/config/client";
1111
import { DEFAULT_API_HOST } from "@/app/constant";
12-
import {
13-
EventStreamContentType,
14-
fetchEventSource,
15-
} from "@fortaine/fetch-event-source";
16-
17-
import Locale from "../../locales";
18-
import { prettyObject } from "@/app/utils/format";
1912
import { getMessageTextContent, isVisionModel } from "@/app/utils";
2013
import { preProcessImageContent, stream } from "@/app/utils/chat";
2114
import { cloudflareAIGatewayUrl } from "@/app/utils/cloudflare";
@@ -80,6 +73,10 @@ const ClaudeMapper = {
8073
const keys = ["claude-2, claude-instant-1"];
8174

8275
export class ClaudeApi implements LLMApi {
76+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
77+
throw new Error("Method not implemented.");
78+
}
79+
8380
extractMessage(res: any) {
8481
console.log("[Response] claude response: ", res);
8582

app/client/platforms/baidu.ts

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
LLMApi,
1515
LLMModel,
1616
MultimodalContent,
17+
SpeechOptions,
1718
} from "../api";
1819
import Locale from "../../locales";
1920
import {
@@ -75,6 +76,10 @@ export class ErnieApi implements LLMApi {
7576
return [baseUrl, path].join("/");
7677
}
7778

79+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
80+
throw new Error("Method not implemented.");
81+
}
82+
7883
async chat(options: ChatOptions) {
7984
const messages = options.messages.map((v) => ({
8085
// "error_code": 336006, "error_msg": "the role of message with even index in the messages must be user or function",

app/client/platforms/bytedance.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
LLMApi,
1414
LLMModel,
1515
MultimodalContent,
16+
SpeechOptions,
1617
} from "../api";
1718
import Locale from "../../locales";
1819
import {
@@ -77,6 +78,10 @@ export class DoubaoApi implements LLMApi {
7778
return res.choices?.at(0)?.message?.content ?? "";
7879
}
7980

81+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
82+
throw new Error("Method not implemented.");
83+
}
84+
8085
async chat(options: ChatOptions) {
8186
const messages = options.messages.map((v) => ({
8287
role: v.role,

app/client/platforms/google.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { ApiPath, Google, REQUEST_TIMEOUT_MS } from "@/app/constant";
2-
import { ChatOptions, getHeaders, LLMApi, LLMModel, LLMUsage } from "../api";
2+
import {
3+
ChatOptions,
4+
getHeaders,
5+
LLMApi,
6+
LLMModel,
7+
LLMUsage,
8+
SpeechOptions,
9+
} from "../api";
310
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
411
import { getClientConfig } from "@/app/config/client";
512
import { DEFAULT_API_HOST } from "@/app/constant";
@@ -56,6 +63,10 @@ export class GeminiProApi implements LLMApi {
5663
""
5764
);
5865
}
66+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
67+
throw new Error("Method not implemented.");
68+
}
69+
5970
async chat(options: ChatOptions): Promise<void> {
6071
const apiClient = this;
6172
let multimodal = false;

app/client/platforms/iflytek.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import {
77
} from "@/app/constant";
88
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
99

10-
import { ChatOptions, getHeaders, LLMApi, LLMModel } from "../api";
10+
import {
11+
ChatOptions,
12+
getHeaders,
13+
LLMApi,
14+
LLMModel,
15+
SpeechOptions,
16+
} from "../api";
1117
import Locale from "../../locales";
1218
import {
1319
EventStreamContentType,
@@ -17,7 +23,7 @@ import { prettyObject } from "@/app/utils/format";
1723
import { getClientConfig } from "@/app/config/client";
1824
import { getMessageTextContent } from "@/app/utils";
1925

20-
import { OpenAIListModelResponse, RequestPayload } from "./openai";
26+
import { RequestPayload } from "./openai";
2127

2228
export class SparkApi implements LLMApi {
2329
private disableListModels = true;
@@ -53,6 +59,10 @@ export class SparkApi implements LLMApi {
5359
return res.choices?.at(0)?.message?.content ?? "";
5460
}
5561

62+
speech(options: SpeechOptions): Promise<ArrayBuffer> {
63+
throw new Error("Method not implemented.");
64+
}
65+
5666
async chat(options: ChatOptions) {
5767
const messages: ChatOptions["messages"] = [];
5868
for (const v of options.messages) {

0 commit comments

Comments
 (0)