Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

975 B
Raw Blame
import { resolveModelCatalogKey } from 'librechat-data-provider';

type ProviderOption = string | { value?: string | number | null };

export function getAvailableModelSelection(model: string, models: readonly string[]): string {
  return models.includes(model) ? model : '';
}

export function getAvailableAgentSelection({
  provider,
  model,
  providers,
  models,
}: {
  provider: string;
  model: string;
  providers: readonly ProviderOption[];
  models: Record<string, string[] | undefined>;
}): { provider: string; model: string } {
  const providerExists =
    models[resolveModelCatalogKey(provider, models)] != null &&
    providers.some((option) =>
      typeof option === 'string' ? option === provider : option.value === provider,
    );

  if (!providerExists) {
    return { provider: '', model: '' };
  }

  return {
    provider,
    model: getAvailableModelSelection(
      model,
      models[resolveModelCatalogKey(provider, models)] ?? [],
    ),
  };
}