Skip to content

Commit 3628d68

Browse files
committed
update
1 parent 2387208 commit 3628d68

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ async function request(req: NextRequest) {
6868
const controller = new AbortController();
6969

7070
// alibaba use base url or just remove the path
71-
let path = `${req.nextUrl.pathname}`.replaceAll(
72-
ApiPath.Alibaba + "/" + Alibaba.ChatPath,
73-
"",
74-
);
71+
let path = `${req.nextUrl.pathname}`.replaceAll(ApiPath.Alibaba, "");
7572

7673
let baseUrl = serverConfig.alibabaUrl || ALIBABA_BASE_URL;
7774

@@ -153,11 +150,9 @@ async function request(req: NextRequest) {
153150
console.error(`[Alibaba] filter`, e);
154151
}
155152
}
156-
console.log("[Alibaba request]", fetchOptions.headers, req.method);
157153
try {
158154
const res = await fetch(fetchUrl, fetchOptions);
159155

160-
console.log("[Alibaba response]", res.status, " ", res.headers, res.url);
161156
// to prevent browser prompt for credentials
162157
const newHeaders = new Headers(res.headers);
163158
newHeaders.delete("www-authenticate");

app/client/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export function getHeaders() {
185185
const isAnthropic = modelConfig.providerName === ServiceProvider.Anthropic;
186186
const isBaidu = modelConfig.providerName == ServiceProvider.Baidu;
187187
const isByteDance = modelConfig.providerName === ServiceProvider.ByteDance;
188+
const isAlibaba = modelConfig.providerName === ServiceProvider.Alibaba;
188189
const isEnabledAccessControl = accessStore.enabledAccessControl();
189190
const apiKey = isGoogle
190191
? accessStore.googleApiKey
@@ -194,13 +195,16 @@ export function getHeaders() {
194195
? accessStore.anthropicApiKey
195196
: isByteDance
196197
? accessStore.bytedanceApiKey
198+
: isAlibaba
199+
? accessStore.alibabaApiKey
197200
: accessStore.openaiApiKey;
198201
return {
199202
isGoogle,
200203
isAzure,
201204
isAnthropic,
202205
isBaidu,
203206
isByteDance,
207+
isAlibaba,
204208
apiKey,
205209
isEnabledAccessControl,
206210
};

app/client/platforms/alibaba.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
ApiPath,
44
Alibaba,
5-
DEFAULT_API_HOST,
5+
ALIBABA_BASE_URL,
66
REQUEST_TIMEOUT_MS,
77
} from "@/app/constant";
88
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
@@ -58,9 +58,7 @@ export class QwenApi implements LLMApi {
5858

5959
if (baseUrl.length === 0) {
6060
const isApp = !!getClientConfig()?.isApp;
61-
baseUrl = isApp
62-
? DEFAULT_API_HOST + "/api/proxy/alibaba"
63-
: ApiPath.Alibaba;
61+
baseUrl = isApp ? ALIBABA_BASE_URL : ApiPath.Alibaba;
6462
}
6563

6664
if (baseUrl.endsWith("/")) {
@@ -76,14 +74,13 @@ export class QwenApi implements LLMApi {
7674
}
7775

7876
extractMessage(res: any) {
79-
return res.choices?.at(0)?.message?.content ?? "";
77+
return res?.output?.choices?.at(0)?.message?.content ?? "";
8078
}
8179

8280
async chat(options: ChatOptions) {
83-
const visionModel = isVisionModel(options.config.model);
8481
const messages = options.messages.map((v) => ({
8582
role: v.role,
86-
content: visionModel ? v.content : getMessageTextContent(v),
83+
content: getMessageTextContent(v),
8784
}));
8885

8986
const modelConfig = {
@@ -104,8 +101,6 @@ export class QwenApi implements LLMApi {
104101
top_p: modelConfig.top_p,
105102
};
106103

107-
console.log("[Request] Alibaba payload: ", requestPayload);
108-
109104
const shouldStream = !!options.config.stream;
110105
const controller = new AbortController();
111106
options.onController?.(controller);

app/constant.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export const BAIDU_OATUH_URL = `${BAIDU_BASE_URL}/oauth/2.0/token`;
1919

2020
export const BYTEDANCE_BASE_URL = "https://ark.cn-beijing.volces.com";
2121

22-
export const ALIBABA_BASE_URL =
23-
"https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
22+
export const ALIBABA_BASE_URL = "https://dashscope.aliyuncs.com/api/";
2423

2524
export enum Path {
2625
Home = "/",
@@ -144,7 +143,8 @@ export const ByteDance = {
144143
};
145144

146145
export const Alibaba = {
147-
ChatPath: "chat/completions",
146+
ExampleEndpoint: ALIBABA_BASE_URL,
147+
ChatPath: "v1/services/aigc/text-generation/generation",
148148
};
149149

150150
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang

0 commit comments

Comments
 (0)