MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / detectLMStudioModels

Function detectLMStudioModels

src/setup/model-detector.ts:108–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106 * 1234 is LM Studio default; 8080 is llama.cpp default; 11435 is a common Ollama-clone port.
107 */
108export async function detectLMStudioModels(): Promise<DetectedModel[]> {
109 const ports = [1234, 8080];
110 const all: DetectedModel[] = [];
111 const seen = new Set<string>();
112 // Pull real context windows from LM Studio's native API up-front (one probe).
113 const ctxMap = await detectLmStudioContextWindows(ports);
114 for (const port of ports) {
115 const r = await fetchWithTimeout(`http://127.0.0.1:${port}/v1/models`);
116 if (!r || !r.ok) continue;
117 try {
118 const body = await r.json() as { data?: Array<{ id: string; meta?: any }> };
119 if (!Array.isArray(body.data)) continue;
120 for (const m of body.data) {
121 if (seen.has(m.id)) continue;
122 seen.add(m.id);
123 // Skip embedding-only models — they can't drive a chat agent.
124 if (/embed/i.test(m.id)) continue;
125 const paramsB = parseParamsFromId(m.id) ?? (m.meta?.n_params ? m.meta.n_params / 1e9 : undefined);
126 const sizeGb = m.meta?.size ? m.meta.size / (1024 ** 3) : undefined;
127 all.push({
128 provider: 'openai',
129 id: m.id,
130 label: m.id,
131 source: 'lm-studio',
132 sizeGb: sizeGb ? Math.round(sizeGb * 10) / 10 : undefined,
133 paramsB: paramsB ? Math.round(paramsB) : undefined,
134 // LM Studio surfaces an OpenAI-compatible API; whether the model honours
135 // structured tool_calls depends on the model itself. Same heuristic.
136 toolCallsLikely: looksLikeToolCallCapable(m.id),
137 // Real window from the native API, else a RAM-safe family heuristic.
138 contextWindow: ctxMap[m.id] ?? guessContextWindow(m.id),
139 visionLikely: looksVisionCapable(m.id),
140 });
141 }
142 } catch (e: any) {
143 logger.debug(`LM Studio response parse failed on port ${port}`, { err: e?.message });
144 }
145 }
146 return all;
147}
148
149/** Run all detectors in parallel; combine + sort results. */
150export async function detectAllLocalModels(): Promise<DetectedModel[]> {

Callers 1

detectAllLocalModelsFunction · 0.85

Calls 10

fetchWithTimeoutFunction · 0.85
parseParamsFromIdFunction · 0.85
looksLikeToolCallCapableFunction · 0.85
guessContextWindowFunction · 0.85
looksVisionCapableFunction · 0.85
addMethod · 0.80
debugMethod · 0.80
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected