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

feat: delete ollama model command #511

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion apps/shinkai-desktop/src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"shinkai_node_set_default_options",
"shinkai_node_get_ollama_api_url",
"shinkai_node_get_default_model",
"shinkai_node_delete_ollama_model",
"hardware_get_summary",
"galxe_generate_proof"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"shinkai_node_remove_storage",
"shinkai_node_set_default_options",
"shinkai_node_get_ollama_api_url",
"shinkai_node_get_default_model"
"shinkai_node_get_default_model",
"shinkai_node_delete_ollama_model"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ pub async fn shinkai_node_get_default_model() -> Result<String, String> {
let model = ShinkaiNodeOptions::default_initial_model();
Ok(model)
}

#[tauri::command]
pub async fn shinkai_node_delete_ollama_model(model_name: String) -> Result<(), String> {
let shinkai_node_manager_guard = SHINKAI_NODE_MANAGER_INSTANCE.get().unwrap().lock().await;
match shinkai_node_manager_guard
.delete_ollama_model(&model_name)
.await
{
Ok(_) => Ok(()),
Err(message) => Err(message),
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use futures_util::{Stream, StreamExt};
use reqwest;

use super::ollama_api_types::{OllamaApiPullRequest, OllamaApiPullResponse, OllamaApiTagsResponse};
use super::ollama_api_types::{
OllamaApiDeleteRequest, OllamaApiPullRequest, OllamaApiPullResponse, OllamaApiTagsResponse,
};

pub struct OllamaApiClient {
base_url: String,
Expand Down Expand Up @@ -120,4 +122,21 @@ impl OllamaApiClient {
as Box<dyn Stream<Item = Result<OllamaApiPullResponse, String>> + Send + Unpin>;
Ok(result)
}

pub async fn delete_model(&self, model_name: &str) -> Result<(), String> {
let url = format!("{}/api/delete", self.base_url);
let client = reqwest::Client::new();
let body = OllamaApiDeleteRequest {
model: model_name.to_string(),
};
let response = client
.delete(&url)
.send()
.await
.map_err(|e| e.to_string())?;
if response.status() != 200 {
return Err(format!("failed to delete model: {}", response.status()));
}
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ pub enum OllamaApiPullResponse {
status: String,
},
}

#[derive(Serialize, Deserialize, Clone)]
pub struct OllamaApiDeleteRequest {
pub model: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,11 @@ impl ShinkaiNodeManager {
pub fn get_ollama_api_url(&self) -> String {
self.ollama_process.get_ollama_api_base_url()
}

pub async fn delete_ollama_model(&self, model_name: &str) -> Result<(), String> {
let ollama_api_url = self.ollama_process.get_ollama_api_base_url();
let ollama_api = OllamaApiClient::new(ollama_api_url);

ollama_api.delete_model(model_name).await
}
}
9 changes: 5 additions & 4 deletions apps/shinkai-desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::commands::fetch::{get_request, post_request};
use crate::commands::galxe::galxe_generate_proof;
use crate::commands::hardware::hardware_get_summary;
use crate::commands::shinkai_node_manager_commands::{
shinkai_node_get_default_model, shinkai_node_get_last_n_logs, shinkai_node_get_ollama_api_url,
shinkai_node_get_options, shinkai_node_is_running, shinkai_node_kill,
shinkai_node_remove_storage, shinkai_node_set_default_options, shinkai_node_set_options,
shinkai_node_spawn, show_shinkai_node_manager_window,
shinkai_node_delete_ollama_model, shinkai_node_get_default_model, shinkai_node_get_last_n_logs,
shinkai_node_get_ollama_api_url, shinkai_node_get_options, shinkai_node_is_running,
shinkai_node_kill, shinkai_node_remove_storage, shinkai_node_set_default_options,
shinkai_node_set_options, shinkai_node_spawn, show_shinkai_node_manager_window,
};

use commands::spotlight_commands::hide_spotlight_window_app;
Expand Down Expand Up @@ -89,6 +89,7 @@ fn main() {
shinkai_node_set_default_options,
shinkai_node_get_ollama_api_url,
shinkai_node_get_default_model,
shinkai_node_delete_ollama_model,
hardware_get_summary,
galxe_generate_proof,
get_request,
Expand Down