Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 9, 2024
1 parent 2387208 commit 3628d68
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
7 changes: 1 addition & 6 deletions app/api/alibaba/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions app/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -194,13 +195,16 @@ export function getHeaders() {
? accessStore.anthropicApiKey
: isByteDance
? accessStore.bytedanceApiKey
: isAlibaba
? accessStore.alibabaApiKey
: accessStore.openaiApiKey;
return {
isGoogle,
isAzure,
isAnthropic,
isBaidu,
isByteDance,
isAlibaba,
apiKey,
isEnabledAccessControl,
};
Expand Down
13 changes: 4 additions & 9 deletions app/client/platforms/alibaba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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("/")) {
Expand All @@ -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 = {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3628d68

Please sign in to comment.