Browse Source

feat: swap name and displayName for bytedance in custom models

Dogtiti 1 year ago
parent
commit
1caa61f4c0
4 changed files with 23 additions and 6 deletions
  1. 2 0
      app/client/api.ts
  2. 3 3
      app/config/server.ts
  3. 8 1
      app/constant.ts
  4. 10 2
      app/utils/model.ts

+ 2 - 0
app/client/api.ts

@@ -225,6 +225,8 @@ export function getClientApi(provider: ServiceProvider): ClientApi {
       return new ClientApi(ModelProvider.GeminiPro);
     case ServiceProvider.Anthropic:
       return new ClientApi(ModelProvider.Claude);
+    case ServiceProvider.ByteDance:
+      return new ClientApi(ModelProvider.Doubao);
     default:
       return new ClientApi(ModelProvider.GPT);
   }

+ 3 - 3
app/config/server.ts

@@ -32,13 +32,13 @@ declare global {
       GOOGLE_API_KEY?: string;
       GOOGLE_URL?: string;
 
+      // google tag manager
+      GTM_ID?: string;
+
       // bytedance only
       BYTEDANCE_URL?: string;
       BYTEDANCE_API_KEY?: string;
 
-      // google tag manager
-      GTM_ID?: string;
-
       // custom template for preprocessing user input
       DEFAULT_INPUT_TEMPLATE?: string;
     }

+ 8 - 1
app/constant.ts

@@ -183,7 +183,14 @@ const anthropicModels = [
   "claude-3-5-sonnet-20240620",
 ];
 
-const bytedanceModels = ["ep-20240520082937-424bw=Doubao-lite-4k"];
+const bytedanceModels = [
+  "Doubao-lite-4k",
+  "Doubao-lite-32k",
+  "Doubao-lite-128k",
+  "Doubao-pro-4k",
+  "Doubao-pro-32k",
+  "Doubao-pro-128k",
+];
 
 export const DEFAULT_MODELS = [
   ...openaiModels.map((name) => ({

+ 10 - 2
app/utils/model.ts

@@ -39,7 +39,7 @@ export function collectModelTable(
       const available = !m.startsWith("-");
       const nameConfig =
         m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
-      const [name, displayName] = nameConfig.split("=");
+      let [name, displayName] = nameConfig.split("=");
 
       // enable or disable all models
       if (name === "all") {
@@ -50,9 +50,17 @@ export function collectModelTable(
         // 1. find model by name(), and set available value
         let count = 0;
         for (const fullName in modelTable) {
-          if (fullName.split("@").shift() == name) {
+          const [modelName, providerName] = fullName.split("@");
+          if (modelName === name) {
             count += 1;
             modelTable[fullName]["available"] = available;
+            // swap name and displayName for bytedance
+            if (providerName === "bytedance") {
+              const tempName = name;
+              name = displayName;
+              displayName = tempName;
+              modelTable[fullName]["name"] = name;
+            }
             if (displayName) {
               modelTable[fullName]["displayName"] = displayName;
             }