This commit is contained in:
lloydzhou 2024-07-09 19:56:52 +08:00
parent 23872086fa
commit 3628d68d9a
4 changed files with 12 additions and 18 deletions

View File

@ -68,10 +68,7 @@ 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.Alibaba + "/" + Alibaba.ChatPath,
"",
);
let path = `${req.nextUrl.pathname}`.replaceAll(ApiPath.Alibaba, "");
let baseUrl = serverConfig.alibabaUrl || ALIBABA_BASE_URL;
@ -153,11 +150,9 @@ async function request(req: NextRequest) {
console.error(`[Alibaba] filter`, e);
}
}
console.log("[Alibaba request]", fetchOptions.headers, req.method);
try {
const res = await fetch(fetchUrl, fetchOptions);
console.log("[Alibaba response]", res.status, " ", res.headers, res.url);
// to prevent browser prompt for credentials
const newHeaders = new Headers(res.headers);
newHeaders.delete("www-authenticate");

View File

@ -185,6 +185,7 @@ export function getHeaders() {
const isAnthropic = modelConfig.providerName === ServiceProvider.Anthropic;
const isBaidu = modelConfig.providerName == ServiceProvider.Baidu;
const isByteDance = modelConfig.providerName === ServiceProvider.ByteDance;
const isAlibaba = modelConfig.providerName === ServiceProvider.Alibaba;
const isEnabledAccessControl = accessStore.enabledAccessControl();
const apiKey = isGoogle
? accessStore.googleApiKey
@ -194,6 +195,8 @@ export function getHeaders() {
? accessStore.anthropicApiKey
: isByteDance
? accessStore.bytedanceApiKey
: isAlibaba
? accessStore.alibabaApiKey
: accessStore.openaiApiKey;
return {
isGoogle,
@ -201,6 +204,7 @@ export function getHeaders() {
isAnthropic,
isBaidu,
isByteDance,
isAlibaba,
apiKey,
isEnabledAccessControl,
};

View File

@ -2,7 +2,7 @@
import {
ApiPath,
Alibaba,
DEFAULT_API_HOST,
ALIBABA_BASE_URL,
REQUEST_TIMEOUT_MS,
} from "@/app/constant";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
@ -58,9 +58,7 @@ export class QwenApi implements LLMApi {
if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
baseUrl = isApp
? DEFAULT_API_HOST + "/api/proxy/alibaba"
: ApiPath.Alibaba;
baseUrl = isApp ? ALIBABA_BASE_URL : ApiPath.Alibaba;
}
if (baseUrl.endsWith("/")) {
@ -76,14 +74,13 @@ export class QwenApi implements LLMApi {
}
extractMessage(res: any) {
return res.choices?.at(0)?.message?.content ?? "";
return res?.output?.choices?.at(0)?.message?.content ?? "";
}
async chat(options: ChatOptions) {
const visionModel = isVisionModel(options.config.model);
const messages = options.messages.map((v) => ({
role: v.role,
content: visionModel ? v.content : getMessageTextContent(v),
content: getMessageTextContent(v),
}));
const modelConfig = {
@ -104,8 +101,6 @@ export class QwenApi implements LLMApi {
top_p: modelConfig.top_p,
};
console.log("[Request] Alibaba payload: ", requestPayload);
const shouldStream = !!options.config.stream;
const controller = new AbortController();
options.onController?.(controller);

View File

@ -19,8 +19,7 @@ export const BAIDU_OATUH_URL = `${BAIDU_BASE_URL}/oauth/2.0/token`;
export const BYTEDANCE_BASE_URL = "https://ark.cn-beijing.volces.com";
export const ALIBABA_BASE_URL =
"https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation";
export const ALIBABA_BASE_URL = "https://dashscope.aliyuncs.com/api/";
export enum Path {
Home = "/",
@ -144,7 +143,8 @@ export const ByteDance = {
};
export const Alibaba = {
ChatPath: "chat/completions",
ExampleEndpoint: ALIBABA_BASE_URL,
ChatPath: "v1/services/aigc/text-generation/generation",
};
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang