feat(models): Implement model visibility management with hidden models configuration
This commit is contained in:
parent
e47307d1d4
commit
18fdb192d8
8 changed files with 459 additions and 22 deletions
|
|
@ -10,6 +10,7 @@ import {
|
|||
getCustomOpenaiApiKey,
|
||||
getCustomOpenaiApiUrl,
|
||||
getCustomOpenaiModelName,
|
||||
getHiddenModels,
|
||||
} from '../config';
|
||||
import { ChatOpenAI } from '@langchain/openai';
|
||||
import {
|
||||
|
|
@ -90,7 +91,10 @@ export const embeddingModelProviders: Record<
|
|||
lmstudio: loadLMStudioEmbeddingsModels,
|
||||
};
|
||||
|
||||
export const getAvailableChatModelProviders = async () => {
|
||||
export const getAvailableChatModelProviders = async (
|
||||
options: { includeHidden?: boolean } = {}
|
||||
) => {
|
||||
const { includeHidden = false } = options;
|
||||
const models: Record<string, Record<string, ChatModel>> = {};
|
||||
|
||||
for (const provider in chatModelProviders) {
|
||||
|
|
@ -111,28 +115,48 @@ export const getAvailableChatModelProviders = async () => {
|
|||
const customOpenAiApiUrl = getCustomOpenaiApiUrl();
|
||||
const customOpenAiModelName = getCustomOpenaiModelName();
|
||||
|
||||
models['custom_openai'] = {
|
||||
...(customOpenAiApiKey && customOpenAiApiUrl && customOpenAiModelName
|
||||
? {
|
||||
[customOpenAiModelName]: {
|
||||
displayName: customOpenAiModelName,
|
||||
model: new ChatOpenAI({
|
||||
openAIApiKey: customOpenAiApiKey,
|
||||
modelName: customOpenAiModelName,
|
||||
// temperature: 0.7,
|
||||
configuration: {
|
||||
baseURL: customOpenAiApiUrl,
|
||||
},
|
||||
}) as unknown as BaseChatModel,
|
||||
// Only add custom_openai provider if all required fields are configured
|
||||
if (customOpenAiApiKey && customOpenAiApiUrl && customOpenAiModelName) {
|
||||
models['custom_openai'] = {
|
||||
[customOpenAiModelName]: {
|
||||
displayName: customOpenAiModelName,
|
||||
model: new ChatOpenAI({
|
||||
openAIApiKey: customOpenAiApiKey,
|
||||
modelName: customOpenAiModelName,
|
||||
// temperature: 0.7,
|
||||
configuration: {
|
||||
baseURL: customOpenAiApiUrl,
|
||||
},
|
||||
}) as unknown as BaseChatModel,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Filter out hidden models if includeHidden is false
|
||||
if (!includeHidden) {
|
||||
const hiddenModels = getHiddenModels();
|
||||
if (hiddenModels.length > 0) {
|
||||
for (const provider in models) {
|
||||
for (const modelKey in models[provider]) {
|
||||
if (hiddenModels.includes(modelKey)) {
|
||||
delete models[provider][modelKey];
|
||||
}
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
// Remove provider if all models are hidden
|
||||
if (Object.keys(models[provider]).length === 0) {
|
||||
delete models[provider];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return models;
|
||||
};
|
||||
|
||||
export const getAvailableEmbeddingModelProviders = async () => {
|
||||
export const getAvailableEmbeddingModelProviders = async (
|
||||
options: { includeHidden?: boolean } = {}
|
||||
) => {
|
||||
const { includeHidden = false } = options;
|
||||
const models: Record<string, Record<string, EmbeddingModel>> = {};
|
||||
|
||||
for (const provider in embeddingModelProviders) {
|
||||
|
|
@ -149,5 +173,23 @@ export const getAvailableEmbeddingModelProviders = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Filter out hidden models if includeHidden is false
|
||||
if (!includeHidden) {
|
||||
const hiddenModels = getHiddenModels();
|
||||
if (hiddenModels.length > 0) {
|
||||
for (const provider in models) {
|
||||
for (const modelKey in models[provider]) {
|
||||
if (hiddenModels.includes(modelKey)) {
|
||||
delete models[provider][modelKey];
|
||||
}
|
||||
}
|
||||
// Remove provider if all models are hidden
|
||||
if (Object.keys(models[provider]).length === 0) {
|
||||
delete models[provider];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return models;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue