lloydzhou 1 年之前
父节点
当前提交
c359b92ddc
共有 4 个文件被更改,包括 7 次插入19 次删除
  1. 1 8
      app/api/tencent/route.ts
  2. 3 4
      app/client/platforms/tencent.ts
  3. 0 1
      app/constant.ts
  4. 3 6
      app/utils/tencent.ts

+ 1 - 8
app/api/tencent/[...path]/route.ts → app/api/tencent/route.ts

@@ -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")) {
@@ -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(
@@ -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(

+ 3 - 4
app/client/platforms/tencent.ts

@@ -91,8 +91,7 @@ export class HunyuanApi implements LLMApi {
     }
 
     console.log("[Proxy Endpoint] ", baseUrl);
-
-    return [baseUrl, path].join("/");
+    return baseUrl;
   }
 
   extractMessage(res: any) {
@@ -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);

+ 0 - 1
app/constant.ts

@@ -195,7 +195,6 @@ export const Alibaba = {
 
 export const Tencent = {
   ExampleEndpoint: TENCENT_BASE_URL,
-  ChatPath: "v1/chat/completions",
 };
 
 export const Moonshot = {

+ 3 - 6
app/utils/tencent.ts

@@ -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);
 }