Skip to content

Commit

Permalink
assistant: Add Mistral support (#24879)
Browse files Browse the repository at this point in the history
Closes #12519.

Release Notes:

- Added support for Mistral to the Assistant.

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
  • Loading branch information
Shidfar and maxdeviant authored Feb 14, 2025
1 parent 5c5caf1 commit 7ee4927
Show file tree
Hide file tree
Showing 15 changed files with 1,034 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ members = [
"crates/media",
"crates/menu",
"crates/migrator",
"crates/mistral",
"crates/multi_buffer",
"crates/node_runtime",
"crates/notifications",
Expand Down Expand Up @@ -283,6 +284,7 @@ markdown_preview = { path = "crates/markdown_preview" }
media = { path = "crates/media" }
menu = { path = "crates/menu" }
migrator = { path = "crates/migrator" }
mistral = { path = "crates/mistral" }
multi_buffer = { path = "crates/multi_buffer" }
node_runtime = { path = "crates/node_runtime" }
notifications = { path = "crates/notifications" }
Expand Down
1 change: 1 addition & 0 deletions assets/icons/ai_mistral.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 @@ -1193,6 +1193,9 @@
},
"deepseek": {
"api_url": "https://api.deepseek.com"
},
"mistral": {
"api_url": "https://api.mistral.ai/v1"
}
},
// Zed's Prettier integration settings.
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 @@ http_client.workspace = true
image.workspace = true
lmstudio = { workspace = true, features = ["schemars"] }
log.workspace = true
mistral = { workspace = true, features = ["schemars"] }
ollama = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
parking_lot.workspace = true
Expand Down
41 changes: 41 additions & 0 deletions crates/language_model/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,47 @@ impl LanguageModelRequest {
}
}

pub fn into_mistral(self, model: String, max_output_tokens: Option<u32>) -> mistral::Request {
let len = self.messages.len();
let merged_messages =
self.messages
.into_iter()
.fold(Vec::with_capacity(len), |mut acc, msg| {
let role = msg.role;
let content = msg.string_contents();

acc.push(match role {
Role::User => mistral::RequestMessage::User { content },
Role::Assistant => mistral::RequestMessage::Assistant {
content: Some(content),
tool_calls: Vec::new(),
},
Role::System => mistral::RequestMessage::System { content },
});
acc
});

mistral::Request {
model,
messages: merged_messages,
stream: true,
max_tokens: max_output_tokens,
temperature: self.temperature,
response_format: None,
tools: self
.tools
.into_iter()
.map(|tool| mistral::ToolDefinition::Function {
function: mistral::FunctionDefinition {
name: tool.name,
description: Some(tool.description),
parameters: Some(tool.input_schema),
},
})
.collect(),
}
}

pub fn into_google(self, model: String) -> google_ai::GenerateContentRequest {
google_ai::GenerateContentRequest {
model,
Expand Down
1 change: 1 addition & 0 deletions crates/language_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ http_client.workspace = true
language_model.workspace = true
lmstudio = { workspace = true, features = ["schemars"] }
menu.workspace = true
mistral = { workspace = true, features = ["schemars"] }
ollama = { workspace = true, features = ["schemars"] }
open_ai = { workspace = true, features = ["schemars"] }
project.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 @@ -17,6 +17,7 @@ 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::mistral::MistralLanguageModelProvider;
use crate::provider::ollama::OllamaLanguageModelProvider;
use crate::provider::open_ai::OpenAiLanguageModelProvider;
pub use crate::settings::*;
Expand Down Expand Up @@ -64,6 +65,10 @@ fn register_language_model_providers(
GoogleLanguageModelProvider::new(client.http_client(), cx),
cx,
);
registry.register_provider(
MistralLanguageModelProvider::new(client.http_client(), cx),
cx,
);
registry.register_provider(CopilotChatLanguageModelProvider::new(cx), cx);

cx.observe_flag::<feature_flags::LanguageModels, _>(move |enabled, 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 @@ -4,5 +4,6 @@ pub mod copilot_chat;
pub mod deepseek;
pub mod google;
pub mod lmstudio;
pub mod mistral;
pub mod ollama;
pub mod open_ai;
Loading

0 comments on commit 7ee4927

Please sign in to comment.