(baseUrl: string, modelId: string)
| 10 | export const hasLoadedFullDetails = (modelId: string): boolean => modelsWithLoadedDetails.has(modelId) |
| 11 | |
| 12 | export const forceFullModelDetailsLoad = async (baseUrl: string, modelId: string): Promise<void> => { |
| 13 | try { |
| 14 | // Test the connection to LM Studio first |
| 15 | // Crrors will be caught further down. |
| 16 | await axios.get(`${baseUrl}/v1/models`) |
| 17 | const lmsUrl = baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://") |
| 18 | |
| 19 | const client = new LMStudioClient({ baseUrl: lmsUrl }) |
| 20 | await client.llm.model(modelId) |
| 21 | // Flush and refresh cache to get updated model details |
| 22 | await flushModels({ provider: "lmstudio", baseUrl }, true) |
| 23 | |
| 24 | // Mark this model as having full details loaded. |
| 25 | modelsWithLoadedDetails.add(modelId) |
| 26 | } catch (error) { |
| 27 | if (error.code === "ECONNREFUSED") { |
| 28 | console.warn(`Error connecting to LMStudio at ${baseUrl}`) |
| 29 | } else { |
| 30 | console.error( |
| 31 | `Error refreshing LMStudio model details: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`, |
| 32 | ) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | export const parseLMStudioModel = (rawModel: LLMInstanceInfo | LLMInfo): ModelInfo => { |
| 38 | // Handle both LLMInstanceInfo (from loaded models) and LLMInfo (from downloaded models) |
no test coverage detected