update
This commit is contained in:
parent
e1d6131f13
commit
c359b92ddc
|
@ -67,12 +67,6 @@ export const preferredRegion = [
|
||||||
async function request(req: NextRequest) {
|
async function request(req: NextRequest) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
|
||||||
// tencent just use base url or just remove the path
|
|
||||||
let path = `${req.nextUrl.pathname}`.replaceAll(
|
|
||||||
ApiPath.Tencent + "/" + Tencent.ChatPath,
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
|
|
||||||
let baseUrl = serverConfig.tencentUrl || TENCENT_BASE_URL;
|
let baseUrl = serverConfig.tencentUrl || TENCENT_BASE_URL;
|
||||||
|
|
||||||
if (!baseUrl.startsWith("http")) {
|
if (!baseUrl.startsWith("http")) {
|
||||||
|
@ -83,7 +77,6 @@ async function request(req: NextRequest) {
|
||||||
baseUrl = baseUrl.slice(0, -1);
|
baseUrl = baseUrl.slice(0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[Proxy] ", path);
|
|
||||||
console.log("[Base Url]", baseUrl);
|
console.log("[Base Url]", baseUrl);
|
||||||
|
|
||||||
const timeoutId = setTimeout(
|
const timeoutId = setTimeout(
|
||||||
|
@ -93,7 +86,7 @@ async function request(req: NextRequest) {
|
||||||
10 * 60 * 1000,
|
10 * 60 * 1000,
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchUrl = `${baseUrl}${path}`;
|
const fetchUrl = baseUrl;
|
||||||
|
|
||||||
const body = await req.text();
|
const body = await req.text();
|
||||||
const headers = await getHeader(
|
const headers = await getHeader(
|
|
@ -91,8 +91,7 @@ export class HunyuanApi implements LLMApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[Proxy Endpoint] ", baseUrl);
|
console.log("[Proxy Endpoint] ", baseUrl);
|
||||||
|
return baseUrl;
|
||||||
return [baseUrl, path].join("/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extractMessage(res: any) {
|
extractMessage(res: any) {
|
||||||
|
@ -115,11 +114,11 @@ export class HunyuanApi implements LLMApi {
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestPayload: RequestPayload = capitalizeKeys({
|
const requestPayload: RequestPayload = capitalizeKeys({
|
||||||
messages,
|
|
||||||
stream: options.config.stream,
|
|
||||||
model: modelConfig.model,
|
model: modelConfig.model,
|
||||||
|
messages,
|
||||||
temperature: modelConfig.temperature,
|
temperature: modelConfig.temperature,
|
||||||
top_p: modelConfig.top_p,
|
top_p: modelConfig.top_p,
|
||||||
|
stream: options.config.stream,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[Request] Tencent payload: ", requestPayload);
|
console.log("[Request] Tencent payload: ", requestPayload);
|
||||||
|
|
|
@ -195,7 +195,6 @@ export const Alibaba = {
|
||||||
|
|
||||||
export const Tencent = {
|
export const Tencent = {
|
||||||
ExampleEndpoint: TENCENT_BASE_URL,
|
ExampleEndpoint: TENCENT_BASE_URL,
|
||||||
ChatPath: "v1/chat/completions",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Moonshot = {
|
export const Moonshot = {
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
"use server";
|
import { createHash, createHmac } from "node:crypto";
|
||||||
import * as crypto from "node:crypto";
|
|
||||||
// 使用 SHA-256 和 secret 进行 HMAC 加密
|
// 使用 SHA-256 和 secret 进行 HMAC 加密
|
||||||
function sha256(message: any, secret = "", encoding?: string) {
|
function sha256(message: any, secret = "", encoding?: string) {
|
||||||
return crypto
|
return createHmac("sha256", secret)
|
||||||
.createHmac("sha256", secret)
|
|
||||||
.update(message)
|
.update(message)
|
||||||
.digest(encoding as any);
|
.digest(encoding as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用 SHA-256 进行哈希
|
// 使用 SHA-256 进行哈希
|
||||||
function getHash(message: any, encoding = "hex") {
|
function getHash(message: any, encoding = "hex") {
|
||||||
return crypto
|
return createHash("sha256")
|
||||||
.createHash("sha256")
|
|
||||||
.update(message)
|
.update(message)
|
||||||
.digest(encoding as any);
|
.digest(encoding as any);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue