Browse Source

Merge pull request #1075 from feitianbubu/fix-default-model-not-exist

fix: if default model is not exist, set the first one as default
IcedTangerine 7 months ago
parent
commit
ee07762611
1 changed files with 7 additions and 1 deletions
  1. 7 1
      web/src/pages/Playground/Playground.js

+ 7 - 1
web/src/pages/Playground/Playground.js

@@ -64,8 +64,9 @@ const Playground = () => {
     },
   ];
 
+  const defaultModel = 'gpt-4o-mini';
   const [inputs, setInputs] = useState({
-    model: 'gpt-4o-mini',
+    model: defaultModel,
     group: '',
     max_tokens: 0,
     temperature: 0,
@@ -108,6 +109,11 @@ const Playground = () => {
         value: model,
       }));
       setModels(localModelOptions);
+      // if default model is not in the list, set the first one as default
+      const hasDefault = localModelOptions.some(option => option.value === defaultModel);
+      if (!hasDefault && localModelOptions.length > 0) {
+        setInputs((inputs) => ({ ...inputs, model: localModelOptions[0].value }));
+      }
     } else {
       showError(t(message));
     }