Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LM Studio support to the Assistant #23097

Merged
merged 10 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ members = [
"crates/livekit_client",
"crates/livekit_client_macos",
"crates/livekit_server",
"crates/lmstudio",
"crates/lsp",
"crates/markdown",
"crates/markdown_preview",
Expand Down Expand Up @@ -255,6 +256,7 @@ languages = { path = "crates/languages" }
livekit_client = { path = "crates/livekit_client" }
livekit_client_macos = { path = "crates/livekit_client_macos" }
livekit_server = { path = "crates/livekit_server" }
lmstudio = { path = "crates/lmstudio" }
lsp = { path = "crates/lsp" }
markdown = { path = "crates/markdown" }
markdown_preview = { path = "crates/markdown_preview" }
Expand Down Expand Up @@ -614,6 +616,7 @@ image_viewer = { codegen-units = 1 }
inline_completion_button = { codegen-units = 1 }
install_cli = { codegen-units = 1 }
journal = { codegen-units = 1 }
lmstudio = { codegen-units = 1 }
menu = { codegen-units = 1 }
notifications = { codegen-units = 1 }
ollama = { codegen-units = 1 }
Expand Down
33 changes: 33 additions & 0 deletions assets/icons/ai_lm_studio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@
"openai": {
"version": "1",
"api_url": "https://api.openai.com/v1"
},
"lmstudio": {
"api_url": "http://localhost:1234/api/v0"
}
},
// Zed's Prettier integration settings.
Expand Down
1 change: 1 addition & 0 deletions crates/assistant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ language.workspace = true
language_model.workspace = true
language_model_selector.workspace = true
language_models.workspace = true
lmstudio = { workspace = true, features = ["schemars"] }
log.workspace = true
lsp.workspace = true
markdown.workspace = true
Expand Down
26 changes: 25 additions & 1 deletion crates/assistant/src/assistant_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anthropic::Model as AnthropicModel;
use feature_flags::FeatureFlagAppExt;
use gpui::{AppContext, Pixels};
use language_model::{CloudModel, LanguageModel};
use lmstudio::Model as LmStudioModel;
use ollama::Model as OllamaModel;
use schemars::{schema::Schema, JsonSchema};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -40,6 +41,10 @@ pub enum AssistantProviderContentV1 {
default_model: Option<OllamaModel>,
api_url: Option<String>,
},
LmStudio {
default_model: Option<LmStudioModel>,
api_url: Option<String>,
},
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -137,6 +142,12 @@ impl AssistantSettingsContent {
model: model.id().to_string(),
})
}
AssistantProviderContentV1::LmStudio { default_model, .. } => {
default_model.map(|model| LanguageModelSelection {
provider: "lmstudio".to_string(),
model: model.id().to_string(),
})
}
}),
inline_alternatives: None,
enable_experimental_live_diffs: None,
Expand Down Expand Up @@ -214,6 +225,18 @@ impl AssistantSettingsContent {
api_url,
});
}
"lmstudio" => {
let api_url = match &settings.provider {
Some(AssistantProviderContentV1::LmStudio { api_url, .. }) => {
api_url.clone()
}
_ => None,
};
settings.provider = Some(AssistantProviderContentV1::LmStudio {
default_model: Some(lmstudio::Model::new(&model, None, None)),
api_url,
});
}
"openai" => {
let (api_url, available_models) = match &settings.provider {
Some(AssistantProviderContentV1::OpenAi {
Expand Down Expand Up @@ -313,6 +336,7 @@ fn providers_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema:
"anthropic".into(),
"google".into(),
"ollama".into(),
"lmstudio".into(),
"openai".into(),
"zed.dev".into(),
"copilot_chat".into(),
Expand Down Expand Up @@ -355,7 +379,7 @@ pub struct AssistantSettingsContentV1 {
default_height: Option<f32>,
/// The provider of the assistant service.
///
/// This can be "openai", "anthropic", "ollama", "zed.dev"
/// This can be "openai", "anthropic", "ollama", "lmstudio", "zed.dev"
/// each with their respective default models and configurations.
provider: Option<AssistantProviderContentV1>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/assistant2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ markdown.workspace = true
menu.workspace = true
multi_buffer.workspace = true
ollama = { workspace = true, features = ["schemars"] }
lmstudio = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
ordered-float.workspace = true
parking_lot.workspace = true
Expand Down
25 changes: 25 additions & 0 deletions crates/assistant2/src/assistant_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ::open_ai::Model as OpenAiModel;
use anthropic::Model as AnthropicModel;
use gpui::Pixels;
use language_model::{CloudModel, LanguageModel};
use lmstudio::Model as LmStudioModel;
use ollama::Model as OllamaModel;
use schemars::{schema::Schema, JsonSchema};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -39,6 +40,11 @@ pub enum AssistantProviderContentV1 {
default_model: Option<OllamaModel>,
api_url: Option<String>,
},
#[serde(rename = "lmstudio")]
LmStudio {
default_model: Option<LmStudioModel>,
api_url: Option<String>,
},
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -130,6 +136,12 @@ impl AssistantSettingsContent {
model: model.id().to_string(),
})
}
AssistantProviderContentV1::LmStudio { default_model, .. } => {
default_model.map(|model| LanguageModelSelection {
provider: "lmstudio".to_string(),
model: model.id().to_string(),
})
}
}),
inline_alternatives: None,
enable_experimental_live_diffs: None,
Expand Down Expand Up @@ -207,6 +219,18 @@ impl AssistantSettingsContent {
api_url,
});
}
"lmstudio" => {
let api_url = match &settings.provider {
Some(AssistantProviderContentV1::LmStudio { api_url, .. }) => {
api_url.clone()
}
_ => None,
};
settings.provider = Some(AssistantProviderContentV1::LmStudio {
default_model: Some(lmstudio::Model::new(&model, None, None)),
api_url,
});
}
"openai" => {
let (api_url, available_models) = match &settings.provider {
Some(AssistantProviderContentV1::OpenAi {
Expand Down Expand Up @@ -305,6 +329,7 @@ fn providers_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema:
enum_values: Some(vec![
"anthropic".into(),
"google".into(),
"lmstudio".into(),
"ollama".into(),
"openai".into(),
"zed.dev".into(),
Expand Down
1 change: 1 addition & 0 deletions crates/language_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ image.workspace = true
log.workspace = true
ollama = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
lmstudio = { workspace = true, features = ["schemars"] }
parking_lot.workspace = true
proto.workspace = true
schemars.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/language_model/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pub mod cloud_model;

pub use anthropic::Model as AnthropicModel;
pub use cloud_model::*;
pub use lmstudio::Model as LmStudioModel;
pub use ollama::Model as OllamaModel;
pub use open_ai::Model as OpenAiModel;
10 changes: 10 additions & 0 deletions crates/language_model/src/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ impl From<Role> for open_ai::Role {
}
}
}

impl From<Role> for lmstudio::Role {
fn from(val: Role) -> Self {
match val {
Role::User => lmstudio::Role::User,
Role::Assistant => lmstudio::Role::Assistant,
Role::System => lmstudio::Role::System,
}
}
}
1 change: 1 addition & 0 deletions crates/language_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ http_client.workspace = true
language_model.workspace = true
menu.workspace = true
ollama = { workspace = true, features = ["schemars"] }
lmstudio = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
project.workspace = true
proto.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions crates/language_models/src/language_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use crate::provider::cloud::LlmApiToken;
pub use crate::provider::cloud::RefreshLlmTokenListener;
use crate::provider::copilot_chat::CopilotChatLanguageModelProvider;
use crate::provider::google::GoogleLanguageModelProvider;
use crate::provider::lmstudio::LmStudioLanguageModelProvider;
use crate::provider::ollama::OllamaLanguageModelProvider;
use crate::provider::open_ai::OpenAiLanguageModelProvider;
pub use crate::settings::*;
Expand Down Expand Up @@ -55,6 +56,10 @@ fn register_language_model_providers(
OllamaLanguageModelProvider::new(client.http_client(), cx),
cx,
);
registry.register_provider(
LmStudioLanguageModelProvider::new(client.http_client(), cx),
cx,
);
registry.register_provider(
GoogleLanguageModelProvider::new(client.http_client(), cx),
cx,
Expand Down
1 change: 1 addition & 0 deletions crates/language_models/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pub mod anthropic;
pub mod cloud;
pub mod copilot_chat;
pub mod google;
pub mod lmstudio;
pub mod ollama;
pub mod open_ai;
Loading
Loading