瀏覽代碼

display doubao model name when select model

lloydzhou 1 年之前
父節點
當前提交
9d7e19cebf
共有 3 個文件被更改,包括 28 次插入19 次删除
  1. 1 8
      app/api/bytedance/[...path]/route.ts
  2. 4 8
      app/client/platforms/bytedance.ts
  3. 23 3
      app/components/chat.tsx

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

@@ -132,17 +132,10 @@ async function request(req: NextRequest) {
       console.error(`[ByteDance] filter`, e);
     }
   }
-  console.log("[ByteDance request]", fetchOptions.headers, req.method);
+
   try {
     const res = await fetch(fetchUrl, fetchOptions);
 
-    console.log(
-      "[ByteDance response]",
-      res.status,
-      "   ",
-      res.headers,
-      res.url,
-    );
     // to prevent browser prompt for credentials
     const newHeaders = new Headers(res.headers);
     newHeaders.delete("www-authenticate");

+ 4 - 8
app/client/platforms/bytedance.ts

@@ -2,7 +2,7 @@
 import {
   ApiPath,
   ByteDance,
-  DEFAULT_API_HOST,
+  BYTEDANCE_BASE_URL,
   REQUEST_TIMEOUT_MS,
 } from "@/app/constant";
 import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
@@ -58,9 +58,7 @@ export class DoubaoApi implements LLMApi {
 
     if (baseUrl.length === 0) {
       const isApp = !!getClientConfig()?.isApp;
-      baseUrl = isApp
-        ? DEFAULT_API_HOST + "/api/proxy/bytedance"
-        : ApiPath.ByteDance;
+      baseUrl = isApp ? BYTEDANCE_BASE_URL : ApiPath.ByteDance;
     }
 
     if (baseUrl.endsWith("/")) {
@@ -94,9 +92,10 @@ export class DoubaoApi implements LLMApi {
       },
     };
 
+    const shouldStream = !!options.config.stream;
     const requestPayload: RequestPayload = {
       messages,
-      stream: options.config.stream,
+      stream: shouldStream,
       model: modelConfig.model,
       temperature: modelConfig.temperature,
       presence_penalty: modelConfig.presence_penalty,
@@ -104,9 +103,6 @@ export class DoubaoApi implements LLMApi {
       top_p: modelConfig.top_p,
     };
 
-    console.log("[Request] ByteDance payload: ", requestPayload);
-
-    const shouldStream = !!options.config.stream;
     const controller = new AbortController();
     options.onController?.(controller);
 

+ 23 - 3
app/components/chat.tsx

@@ -467,6 +467,14 @@ export function ChatActions(props: {
       return filteredModels;
     }
   }, [allModels]);
+  const currentModelName = useMemo(() => {
+    const model = models.find(
+      (m) =>
+        m.name == currentModel &&
+        m?.provider?.providerName == currentProviderName,
+    );
+    return model?.displayName ?? "";
+  }, [models, currentModel, currentProviderName]);
   const [showModelSelector, setShowModelSelector] = useState(false);
   const [showUploadImage, setShowUploadImage] = useState(false);
 
@@ -489,7 +497,11 @@ export function ChatActions(props: {
         session.mask.modelConfig.providerName = nextModel?.provider
           ?.providerName as ServiceProvider;
       });
-      showToast(nextModel.name);
+      showToast(
+        nextModel?.provider?.providerName == "ByteDance"
+          ? nextModel.displayName
+          : nextModel.name,
+      );
     }
   }, [chatStore, currentModel, models]);
 
@@ -571,7 +583,7 @@ export function ChatActions(props: {
 
       <ChatAction
         onClick={() => setShowModelSelector(true)}
-        text={currentModel}
+        text={currentModelName}
         icon={<RobotIcon />}
       />
 
@@ -596,7 +608,15 @@ export function ChatActions(props: {
                 providerName as ServiceProvider;
               session.mask.syncGlobalConfig = false;
             });
-            showToast(model);
+            if (providerName == "ByteDance") {
+              const selectedModel = models.find(
+                (m) =>
+                  m.name == model && m?.provider.providerName == providerName,
+              );
+              showToast(selectedModel?.displayName ?? "");
+            } else {
+              showToast(model);
+            }
           }}
         />
       )}