Detailed changes
@@ -374,7 +374,6 @@ pub trait LanguageModelProvider: 'static {
fn recommended_models(&self, _cx: &App) -> Vec<Arc<dyn LanguageModel>> {
Vec::new()
}
- fn load_model(&self, _model: Arc<dyn LanguageModel>, _cx: &App) {}
fn is_authenticated(&self, cx: &App) -> bool;
fn authenticate(&self, cx: &mut App) -> Task<Result<(), AuthenticateError>>;
fn configuration_view(&self, window: &mut Window, cx: &mut App) -> AnyView;
@@ -15,7 +15,7 @@ use language_model::{
LanguageModelRequest, RateLimiter, Role,
};
use lmstudio::{
- ChatCompletionRequest, ChatMessage, ModelType, ResponseStreamEvent, get_models, preload_model,
+ ChatCompletionRequest, ChatMessage, ModelType, ResponseStreamEvent, get_models,
stream_chat_completion,
};
use schemars::JsonSchema;
@@ -216,15 +216,6 @@ impl LanguageModelProvider for LmStudioLanguageModelProvider {
.collect()
}
- fn load_model(&self, model: Arc<dyn LanguageModel>, cx: &App) {
- let settings = &AllLanguageModelSettings::get_global(cx).lmstudio;
- let http_client = self.http_client.clone();
- let api_url = settings.api_url.clone();
- let id = model.id().0.to_string();
- cx.spawn(async move |_| preload_model(http_client, &api_url, &id).await)
- .detach_and_log_err(cx);
- }
-
fn is_authenticated(&self, cx: &App) -> bool {
self.state.read(cx).is_authenticated()
}
@@ -12,7 +12,7 @@ use language_model::{
};
use ollama::{
ChatMessage, ChatOptions, ChatRequest, ChatResponseDelta, KeepAlive, OllamaFunctionTool,
- OllamaToolCall, get_models, preload_model, show_model, stream_chat_completion,
+ OllamaToolCall, get_models, show_model, stream_chat_completion,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -243,15 +243,6 @@ impl LanguageModelProvider for OllamaLanguageModelProvider {
models
}
- fn load_model(&self, model: Arc<dyn LanguageModel>, cx: &App) {
- let settings = &AllLanguageModelSettings::get_global(cx).ollama;
- let http_client = self.http_client.clone();
- let api_url = settings.api_url.clone();
- let id = model.id().0.to_string();
- cx.spawn(async move |_| preload_model(http_client, &api_url, &id).await)
- .detach_and_log_err(cx);
- }
-
fn is_authenticated(&self, cx: &App) -> bool {
self.state.read(cx).is_authenticated()
}
@@ -3,7 +3,7 @@ use futures::{AsyncBufReadExt, AsyncReadExt, StreamExt, io::BufReader, stream::B
use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest, http};
use serde::{Deserialize, Serialize};
use serde_json::Value;
-use std::{convert::TryFrom, sync::Arc, time::Duration};
+use std::{convert::TryFrom, time::Duration};
pub const LMSTUDIO_API_URL: &str = "http://localhost:1234/api/v0";
@@ -391,34 +391,3 @@ pub async fn get_models(
serde_json::from_str(&body).context("Unable to parse LM Studio models response")?;
Ok(response.data)
}
-
-/// Sends an empty request to LM Studio to trigger loading the model
-pub async fn preload_model(client: Arc<dyn HttpClient>, api_url: &str, model: &str) -> Result<()> {
- let uri = format!("{api_url}/completions");
- let request = HttpRequest::builder()
- .method(Method::POST)
- .uri(uri)
- .header("Content-Type", "application/json")
- .body(AsyncBody::from(serde_json::to_string(
- &serde_json::json!({
- "model": model,
- "messages": [],
- "stream": false,
- "max_tokens": 0,
- }),
- )?))?;
-
- let mut response = client.send(request).await?;
-
- if response.status().is_success() {
- Ok(())
- } else {
- let mut body = String::new();
- response.body_mut().read_to_string(&mut body).await?;
- anyhow::bail!(
- "Failed to connect to LM Studio API: {} {}",
- response.status(),
- body,
- );
- }
-}
@@ -3,7 +3,7 @@ use futures::{AsyncBufReadExt, AsyncReadExt, StreamExt, io::BufReader, stream::B
use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest, http};
use serde::{Deserialize, Serialize};
use serde_json::Value;
-use std::{sync::Arc, time::Duration};
+use std::time::Duration;
pub const OLLAMA_API_URL: &str = "http://localhost:11434";
@@ -357,36 +357,6 @@ pub async fn show_model(client: &dyn HttpClient, api_url: &str, model: &str) ->
Ok(details)
}
-/// Sends an empty request to Ollama to trigger loading the model
-pub async fn preload_model(client: Arc<dyn HttpClient>, api_url: &str, model: &str) -> Result<()> {
- let uri = format!("{api_url}/api/generate");
- let request = HttpRequest::builder()
- .method(Method::POST)
- .uri(uri)
- .header("Content-Type", "application/json")
- .body(AsyncBody::from(
- serde_json::json!({
- "model": model,
- "keep_alive": "15m",
- })
- .to_string(),
- ))?;
-
- let mut response = client.send(request).await?;
-
- if response.status().is_success() {
- Ok(())
- } else {
- let mut body = String::new();
- response.body_mut().read_to_string(&mut body).await?;
- anyhow::bail!(
- "Failed to connect to Ollama API: {} {}",
- response.status(),
- body,
- );
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;