MCPcopy
hub / github.com/di-sukharev/opencommit / selectModel

Function selectModel

out/cli.cjs:86541–86624  ·  view source on GitHub ↗
(provider, apiKey)

Source from the content-addressed store, hash-verified

86539 const hours = Math.floor(ageMs / (1e3 * 60 * 60));
86540 if (days > 0) {
86541 return `${days} day${days === 1 ? "" : "s"} ago`;
86542 } else if (hours > 0) {
86543 return `${hours} hour${hours === 1 ? "" : "s"} ago`;
86544 }
86545 return "just now";
86546}
86547async function selectModel(provider, apiKey) {
86548 const providerDisplayName = PROVIDER_DISPLAY_NAMES[provider]?.split(" (")[0] || provider;
86549 const loadingSpinner = le();
86550 loadingSpinner.start(`Fetching models from ${providerDisplayName}...`);
86551 let models = [];
86552 let usedFallback = false;
86553 try {
86554 models = await fetchModelsForProvider(provider, apiKey);
86555 } catch {
86556 usedFallback = true;
86557 const providerKey = provider.toLowerCase();
86558 models = MODEL_LIST[providerKey] || [];
86559 }
86560 const cacheInfo = getCacheInfo();
86561 const cacheAge = formatCacheAge(cacheInfo.timestamp);
86562 if (usedFallback) {
86563 loadingSpinner.stop(
86564 source_default.yellow("Could not fetch models from API. Using default list.")
86565 );
86566 } else if (cacheAge) {
86567 loadingSpinner.stop(`Models loaded ${source_default.dim(`(cached ${cacheAge})`)}`);
86568 } else {
86569 loadingSpinner.stop("Models loaded");
86570 }
86571 if (models.length === 0) {
86572 if (NO_API_KEY_PROVIDERS.includes(provider)) {
86573 return await J4({
86574 message: "Enter model name (e.g., llama3:8b, mistral):",
86575 placeholder: "llama3:8b",
86576 validate: (value) => {
86577 if (!value || value.trim().length === 0) {
86578 return "Model name is required";
86579 }
86580 return void 0;
86581 }
86582 });
86583 }
86584 const providerKey = provider.toLowerCase();
86585 return MODEL_LIST[providerKey]?.[0] || "gpt-4o-mini";
86586 }
86587 const recommended = RECOMMENDED_MODELS[provider];
86588 const options = [];
86589 if (recommended && models.includes(recommended)) {
86590 options.push({
86591 value: recommended,
86592 label: `${recommended} (Recommended)`
86593 });
86594 }
86595 const otherModels = models.filter((m5) => m5 !== recommended).slice(0, 10);
86596 otherModels.forEach((model) => {
86597 options.push({ value: model, label: model });
86598 });

Callers 1

runSetupFunction · 0.70

Calls 12

hD2Function · 0.85
toLowerCaseMethod · 0.80
includesMethod · 0.80
trimMethod · 0.80
filterMethod · 0.80
fetchModelsForProviderFunction · 0.70
getCacheInfoFunction · 0.70
formatCacheAgeFunction · 0.70
startMethod · 0.45
pushMethod · 0.45
sliceMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…