Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a way to define default model from CUSTOM_MODELS env. #3961

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,17 @@ export function ChatActions(props: {
// switch model
const currentModel = chatStore.currentSession().mask.modelConfig.model;
const allModels = useAllModels();
const models = useMemo(
() => allModels.filter((m) => m.available),
[allModels],
);
const models = useMemo(() => {
const filteredModels = allModels.filter((m) => m.available);
const defaultModel = filteredModels.find((m) => m.isDefault);
if (defaultModel) {
const arr = [defaultModel, ...filteredModels.filter((m) => m !== defaultModel)];
return arr;
} else {
return filteredModels;
}
}, [allModels]);

const [showModelSelector, setShowModelSelector] = useState(false);

useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions app/store/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getHeaders } from "../client/api";
import { getClientConfig } from "../config/client";
import { createPersistStore } from "../utils/store";
import { ensure } from "../utils/clone";
import { DEFAULT_CONFIG } from "./config";

let fetchState = 0; // 0 not fetch, 1 fetching, 2 done

Expand Down Expand Up @@ -88,6 +89,14 @@ export const useAccessStore = createPersistStore(
},
})
.then((res) => res.json())
.then((res) => {
// Set default model from env request
let custom_models = res.customModels ?? "";
const models = custom_models.split(",");
const model_default = models.find((model: string) => model.startsWith("+*"))?.substring(2) || "gpt-3.5-turbo";
DEFAULT_CONFIG.modelConfig.model = model_default;
return res
})
.then((res: DangerConfig) => {
console.log("[Config] got config from server", res);
set(() => ({ ...res }));
Expand Down
17 changes: 15 additions & 2 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function collectModelTable(
available: boolean;
name: string;
displayName: string;
isDefault?: boolean;
provider?: LLMModel["provider"]; // Marked as optional
}
> = {};
Expand All @@ -22,6 +23,8 @@ export function collectModelTable(
};
});



// server custom models
customModels
.split(",")
Expand All @@ -32,8 +35,17 @@ export function collectModelTable(
m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
const [name, displayName] = nameConfig.split("=");

// enable or disable all models
if (name === "all") {
if (name.startsWith("*")) { // Check if name starts with wildcard
let defaultName: string | null = null; // Add variable to store wildcard value
defaultName = displayName || name.slice(1); // Store wildcard value
modelTable[defaultName] = {
name : defaultName,
displayName: defaultName,
available,
isDefault : true,
provider: modelTable[defaultName]?.provider, // Use optional chaining
};
} else if (name === "all") {
Object.values(modelTable).forEach((model) => (model.available = available));
} else {
modelTable[name] = {
Expand All @@ -44,6 +56,7 @@ export function collectModelTable(
};
}
});

return modelTable;
}

Expand Down
Loading