fix: use LM Studio native API endpoint (/api/v1) instead of OpenAI-compatible (/v1)

This commit is contained in:
Roo Code 2026-04-29 14:30:19 +00:00
parent ad25634905
commit ae03bb46de
4 changed files with 11 additions and 11 deletions

View file

@ -47,7 +47,7 @@ describe("LmStudioHandler timeout configuration", () => {
expect(getApiRequestTimeout).toHaveBeenCalled()
expect(mockOpenAIConstructor).toHaveBeenCalledWith(
expect.objectContaining({
baseURL: "http://localhost:1234/v1",
baseURL: "http://localhost:1234/api/v1",
apiKey: "noop",
timeout: 600000, // 600 seconds in milliseconds
}),

View file

@ -113,7 +113,7 @@ describe("LMStudio Fetcher", () => {
const result = await getLMStudioModels(baseUrl)
expect(mockedAxios.get).toHaveBeenCalledTimes(1)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledTimes(1)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledWith({ baseUrl: lmsUrl })
expect(mockListDownloadedModels).toHaveBeenCalledTimes(1)
@ -133,7 +133,7 @@ describe("LMStudio Fetcher", () => {
const result = await getLMStudioModels(baseUrl)
expect(mockedAxios.get).toHaveBeenCalledTimes(1)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledTimes(1)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledWith({ baseUrl: lmsUrl })
expect(mockListDownloadedModels).toHaveBeenCalledTimes(1)
@ -373,7 +373,7 @@ describe("LMStudio Fetcher", () => {
await getLMStudioModels("")
expect(mockedAxios.get).toHaveBeenCalledWith(`${defaultBaseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${defaultBaseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledWith({ baseUrl: defaultLmsUrl })
})
@ -385,7 +385,7 @@ describe("LMStudio Fetcher", () => {
await getLMStudioModels(httpsBaseUrl)
expect(mockedAxios.get).toHaveBeenCalledWith(`${httpsBaseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${httpsBaseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).toHaveBeenCalledWith({ baseUrl: wssLmsUrl })
})
@ -407,7 +407,7 @@ describe("LMStudio Fetcher", () => {
const result = await getLMStudioModels(baseUrl)
expect(mockedAxios.get).toHaveBeenCalledTimes(1)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).not.toHaveBeenCalled()
expect(mockListLoaded).not.toHaveBeenCalled()
expect(consoleErrorSpy).toHaveBeenCalledWith(
@ -426,7 +426,7 @@ describe("LMStudio Fetcher", () => {
const result = await getLMStudioModels(baseUrl)
expect(mockedAxios.get).toHaveBeenCalledTimes(1)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/v1/models`)
expect(mockedAxios.get).toHaveBeenCalledWith(`${baseUrl}/api/v1/models`)
expect(MockedLMStudioClientConstructor).not.toHaveBeenCalled()
expect(mockListLoaded).not.toHaveBeenCalled()
expect(consoleInfoSpy).toHaveBeenCalledWith(`Error connecting to LMStudio at ${baseUrl}`)

View file

@ -13,7 +13,7 @@ export const forceFullModelDetailsLoad = async (baseUrl: string, modelId: string
try {
// Test the connection to LM Studio first
// Crrors will be caught further down.
await axios.get(`${baseUrl}/v1/models`)
await axios.get(`${baseUrl}/api/v1/models`)
const lmsUrl = baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://")
const client = new LMStudioClient({ baseUrl: lmsUrl })
@ -66,7 +66,7 @@ export async function getLMStudioModels(baseUrl = "http://localhost:1234"): Prom
// test the connection to LM Studio first
// errors will be caught further down
await axios.get(`${baseUrl}/v1/models`)
await axios.get(`${baseUrl}/api/v1/models`)
const client = new LMStudioClient({ baseUrl: lmsUrl })

View file

@ -31,7 +31,7 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
const apiKey = "noop"
this.client = new OpenAI({
baseURL: (this.options.lmStudioBaseUrl || "http://localhost:1234") + "/v1",
baseURL: (this.options.lmStudioBaseUrl || "http://localhost:1234") + "/api/v1",
apiKey: apiKey,
timeout: getApiRequestTimeout(),
})
@ -221,7 +221,7 @@ export async function getLmStudioModels(baseUrl = "http://localhost:1234") {
return []
}
const response = await axios.get(`${baseUrl}/v1/models`)
const response = await axios.get(`${baseUrl}/api/v1/models`)
const modelsArray = response.data?.data?.map((model: any) => model.id) || []
return [...new Set<string>(modelsArray)]
} catch (error) {