Add LM Studio support (#22)

This commit is contained in:
Piotr Wilkin (ilintar)
2025-05-02 23:51:32 +02:00
committed by GitHub
parent 3529627172
commit 5fc49231ee
15 changed files with 394 additions and 123 deletions

View File

@@ -3,7 +3,7 @@ import { createGoogleGenerativeAI as createGoogle } from "@ai-sdk/google";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createOllama } from "ollama-ai-provider";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import type { LargeLanguageModel, UserSettings } from "../../lib/schemas";
import {
PROVIDER_TO_ENV_VAR,
@@ -82,8 +82,14 @@ export function getModelClient(
case "ollama": {
const provider = createOllama();
return provider(model.name);
}
default: {
}
case "lmstudio": {
// Using LM Studio's OpenAI compatible API
const baseURL = "http://localhost:1234/v1"; // Default LM Studio OpenAI API URL
const provider = createOpenAICompatible({ name: "lmstudio", baseURL });
return provider(model.name);
}
default: {
// Ensure exhaustive check if more providers are added
const _exhaustiveCheck: never = model.provider;
throw new Error(`Unsupported model provider: ${model.provider}`);