Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Aug 1, 2024
1 parent e1d6131 commit c359b92
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ export const preferredRegion = [
async function request(req: NextRequest) {
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;

if (!baseUrl.startsWith("http")) {
Expand All @@ -83,7 +77,6 @@ async function request(req: NextRequest) {
baseUrl = baseUrl.slice(0, -1);
}

console.log("[Proxy] ", path);
console.log("[Base Url]", baseUrl);

const timeoutId = setTimeout(
Expand All @@ -93,7 +86,7 @@ async function request(req: NextRequest) {
10 * 60 * 1000,
);

const fetchUrl = `${baseUrl}${path}`;
const fetchUrl = baseUrl;

const body = await req.text();
const headers = await getHeader(
Expand Down
7 changes: 3 additions & 4 deletions app/client/platforms/tencent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export class HunyuanApi implements LLMApi {
}

console.log("[Proxy Endpoint] ", baseUrl);

return [baseUrl, path].join("/");
return baseUrl;
}

extractMessage(res: any) {
Expand All @@ -115,11 +114,11 @@ export class HunyuanApi implements LLMApi {
};

const requestPayload: RequestPayload = capitalizeKeys({
messages,
stream: options.config.stream,
model: modelConfig.model,
messages,
temperature: modelConfig.temperature,
top_p: modelConfig.top_p,
stream: options.config.stream,
});

console.log("[Request] Tencent payload: ", requestPayload);
Expand Down
1 change: 0 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export const Alibaba = {

export const Tencent = {
ExampleEndpoint: TENCENT_BASE_URL,
ChatPath: "v1/chat/completions",
};

export const Moonshot = {
Expand Down
9 changes: 3 additions & 6 deletions app/utils/tencent.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
"use server";
import * as crypto from "node:crypto";
import { createHash, createHmac } from "node:crypto";
// 使用 SHA-256 和 secret 进行 HMAC 加密
function sha256(message: any, secret = "", encoding?: string) {
return crypto
.createHmac("sha256", secret)
return createHmac("sha256", secret)
.update(message)
.digest(encoding as any);
}

// 使用 SHA-256 进行哈希
function getHash(message: any, encoding = "hex") {
return crypto
.createHash("sha256")
return createHash("sha256")
.update(message)
.digest(encoding as any);
}
Expand Down

0 comments on commit c359b92

Please sign in to comment.