Skip to content

Commit bde21d0

Browse files
committed
pull lm studio models from the list of loaded models; use lm studio model contextLength
1 parent 9089def commit bde21d0

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/api/providers/fetchers/__tests__/lmstudio.test.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios"
22
import { vi, describe, it, expect, beforeEach } from "vitest"
3-
import { LMStudioClient, LLMInfo } from "@lmstudio/sdk" // LLMInfo is a type
3+
import { LMStudioClient, LLMInfo, LLMInstanceInfo } from "@lmstudio/sdk" // LLMInfo is a type
44
import { getLMStudioModels, parseLMStudioModel } from "../lmstudio"
55
import { ModelInfo, lMStudioDefaultModelInfo } from "@roo-code/types" // ModelInfo is a type
66

@@ -29,28 +29,30 @@ describe("LMStudio Fetcher", () => {
2929

3030
describe("parseLMStudioModel", () => {
3131
it("should correctly parse raw LLMInfo to ModelInfo", () => {
32-
const rawModel: LLMInfo = {
33-
architecture: "llama",
34-
modelKey: "mistral-7b-instruct-v0.2.Q4_K_M.gguf",
35-
path: "/Users/username/.cache/lm-studio/models/Mistral AI/Mistral-7B-Instruct-v0.2/mistral-7b-instruct-v0.2.Q4_K_M.gguf",
32+
const rawModel: LLMInstanceInfo = {
3633
type: "llm",
37-
displayName: "Mistral-7B-Instruct-v0.2-Q4_K_M",
38-
maxContextLength: 8192,
39-
paramsString: "7B params, 8k context",
34+
modelKey: "mistralai/devstral-small-2505",
35+
format: "safetensors",
36+
displayName: "Devstral Small 2505",
37+
path: "mistralai/devstral-small-2505",
38+
sizeBytes: 13277565112,
39+
architecture: "mistral",
40+
identifier: "mistralai/devstral-small-2505",
41+
instanceReference: "RAP5qbeHVjJgBiGFQ6STCuTJ",
4042
vision: false,
41-
format: "gguf",
42-
sizeBytes: 4080000000,
43-
trainedForToolUse: false, // Added
43+
trainedForToolUse: false,
44+
maxContextLength: 131072,
45+
contextLength: 7161,
4446
}
4547

4648
const expectedModelInfo: ModelInfo = {
4749
...lMStudioDefaultModelInfo,
4850
description: `${rawModel.displayName} - ${rawModel.paramsString} - ${rawModel.path}`,
49-
contextWindow: rawModel.maxContextLength,
51+
contextWindow: rawModel.contextLength,
5052
supportsPromptCache: true,
5153
supportsImages: rawModel.vision,
5254
supportsComputerUse: false,
53-
maxTokens: rawModel.maxContextLength,
55+
maxTokens: rawModel.contextLength,
5456
inputPrice: 0,
5557
outputPrice: 0,
5658
cacheWritesPrice: 0,
@@ -66,13 +68,16 @@ describe("LMStudio Fetcher", () => {
6668
const baseUrl = "http://localhost:1234"
6769
const lmsUrl = "ws://localhost:1234"
6870

69-
const mockRawModel: LLMInfo = {
71+
const mockRawModel: LLMInstanceInfo = {
7072
architecture: "test-arch",
73+
identifier: "mistralai/devstral-small-2505",
74+
instanceReference: "RAP5qbeHVjJgBiGFQ6STCuTJ",
7175
modelKey: "test-model-key-1",
7276
path: "/path/to/test-model-1",
7377
type: "llm",
7478
displayName: "Test Model One",
7579
maxContextLength: 2048,
80+
contextLength: 7161,
7681
paramsString: "1B params, 2k context",
7782
vision: true,
7883
format: "gguf",
@@ -81,7 +86,7 @@ describe("LMStudio Fetcher", () => {
8186
}
8287

8388
it("should fetch and parse models successfully", async () => {
84-
const mockApiResponse: LLMInfo[] = [mockRawModel]
89+
const mockApiResponse: LLMInstanceInfo[] = [mockRawModel]
8590
mockedAxios.get.mockResolvedValueOnce({ data: { status: "ok" } })
8691
mockListDownloadedModels.mockResolvedValueOnce(mockApiResponse)
8792

src/api/providers/fetchers/lmstudio.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ModelInfo, lMStudioDefaultModelInfo } from "@roo-code/types"
2-
import { LLMInfo, LMStudioClient } from "@lmstudio/sdk"
2+
import { LLM, LLMInfo, LLMInstanceInfo, LMStudioClient } from "@lmstudio/sdk"
33
import axios from "axios"
44

5-
export const parseLMStudioModel = (rawModel: LLMInfo): ModelInfo => {
5+
export const parseLMStudioModel = (rawModel: LLMInstanceInfo): ModelInfo => {
66
const modelInfo: ModelInfo = Object.assign({}, lMStudioDefaultModelInfo, {
7-
description: `${rawModel.displayName} - ${rawModel.paramsString} - ${rawModel.path}`,
8-
contextWindow: rawModel.maxContextLength,
7+
description: `${rawModel.displayName} - ${rawModel} - ${rawModel.path}`,
8+
contextWindow: rawModel.contextLength,
99
supportsPromptCache: true,
1010
supportsImages: rawModel.vision,
1111
supportsComputerUse: false,
12-
maxTokens: rawModel.maxContextLength,
12+
maxTokens: rawModel.contextLength,
1313
})
1414

1515
return modelInfo
@@ -33,7 +33,9 @@ export async function getLMStudioModels(baseUrl = "http://localhost:1234"): Prom
3333
await axios.get(`${baseUrl}/v1/models`)
3434

3535
const client = new LMStudioClient({ baseUrl: lmsUrl })
36-
const response = (await client.system.listDownloadedModels()) as Array<LLMInfo>
36+
const response = (await client.llm.listLoaded().then((models: LLM[]) => {
37+
return Promise.all(models.map((m) => m.getModelInfo()))
38+
})) as Array<LLMInstanceInfo>
3739

3840
for (const lmstudioModel of response) {
3941
models[lmstudioModel.modelKey] = parseLMStudioModel(lmstudioModel)

0 commit comments

Comments
 (0)