Skip to content

Commit 0b21411

Browse files
committed
add list_downloaded_model
1 parent cc5793c commit 0b21411

File tree

9 files changed

+105
-2
lines changed

9 files changed

+105
-2
lines changed

plugins/local-llm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const COMMANDS: &[&str] = &[
22
"models_dir",
3+
"list_supported_models",
34
"is_server_running",
45
"is_model_downloaded",
56
"is_model_downloading",

plugins/local-llm/js/bindings.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ async getCurrentModel() : Promise<SupportedModel> {
3939
},
4040
async setCurrentModel(model: SupportedModel) : Promise<null> {
4141
return await TAURI_INVOKE("plugin:local-llm|set_current_model", { model });
42+
},
43+
async listDownloadedModel() : Promise<SupportedModel[]> {
44+
return await TAURI_INVOKE("plugin:local-llm|list_downloaded_model");
4245
}
4346
}
4447

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-list-supported-models"
7+
description = "Enables the list_supported_models command without any pre-configured scope."
8+
commands.allow = ["list_supported_models"]
9+
10+
[[permission]]
11+
identifier = "deny-list-supported-models"
12+
description = "Denies the list_supported_models command without any pre-configured scope."
13+
commands.deny = ["list_supported_models"]

plugins/local-llm/permissions/autogenerated/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Default permissions for the plugin
1414
- `allow-restart-server`
1515
- `allow-get-current-model`
1616
- `allow-set-current-model`
17+
- `allow-list-supported-models`
1718

1819
## Permission Table
1920

@@ -183,6 +184,32 @@ Denies the is_server_running command without any pre-configured scope.
183184
<tr>
184185
<td>
185186

187+
`local-llm:allow-list-supported-models`
188+
189+
</td>
190+
<td>
191+
192+
Enables the list_supported_models command without any pre-configured scope.
193+
194+
</td>
195+
</tr>
196+
197+
<tr>
198+
<td>
199+
200+
`local-llm:deny-list-supported-models`
201+
202+
</td>
203+
<td>
204+
205+
Denies the list_supported_models command without any pre-configured scope.
206+
207+
</td>
208+
</tr>
209+
210+
<tr>
211+
<td>
212+
186213
`local-llm:allow-models-dir`
187214

188215
</td>

plugins/local-llm/permissions/default.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ permissions = [
1111
"allow-restart-server",
1212
"allow-get-current-model",
1313
"allow-set-current-model",
14+
"allow-list-supported-models",
1415
]

plugins/local-llm/permissions/schemas/schema.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@
366366
"const": "deny-is-server-running",
367367
"markdownDescription": "Denies the is_server_running command without any pre-configured scope."
368368
},
369+
{
370+
"description": "Enables the list_supported_models command without any pre-configured scope.",
371+
"type": "string",
372+
"const": "allow-list-supported-models",
373+
"markdownDescription": "Enables the list_supported_models command without any pre-configured scope."
374+
},
375+
{
376+
"description": "Denies the list_supported_models command without any pre-configured scope.",
377+
"type": "string",
378+
"const": "deny-list-supported-models",
379+
"markdownDescription": "Denies the list_supported_models command without any pre-configured scope."
380+
},
369381
{
370382
"description": "Enables the models_dir command without any pre-configured scope.",
371383
"type": "string",
@@ -427,10 +439,10 @@
427439
"markdownDescription": "Denies the stop_server command without any pre-configured scope."
428440
},
429441
{
430-
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-models-dir`\n- `allow-is-server-running`\n- `allow-is-model-downloading`\n- `allow-is-model-downloaded`\n- `allow-download-model`\n- `allow-start-server`\n- `allow-stop-server`\n- `allow-restart-server`\n- `allow-get-current-model`\n- `allow-set-current-model`",
442+
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-models-dir`\n- `allow-is-server-running`\n- `allow-is-model-downloading`\n- `allow-is-model-downloaded`\n- `allow-download-model`\n- `allow-start-server`\n- `allow-stop-server`\n- `allow-restart-server`\n- `allow-get-current-model`\n- `allow-set-current-model`\n- `allow-list-supported-models`",
431443
"type": "string",
432444
"const": "default",
433-
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-models-dir`\n- `allow-is-server-running`\n- `allow-is-model-downloading`\n- `allow-is-model-downloaded`\n- `allow-download-model`\n- `allow-start-server`\n- `allow-stop-server`\n- `allow-restart-server`\n- `allow-get-current-model`\n- `allow-set-current-model`"
445+
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-models-dir`\n- `allow-is-server-running`\n- `allow-is-model-downloading`\n- `allow-is-model-downloaded`\n- `allow-download-model`\n- `allow-start-server`\n- `allow-stop-server`\n- `allow-restart-server`\n- `allow-get-current-model`\n- `allow-set-current-model`\n- `allow-list-supported-models`"
434446
}
435447
]
436448
}

plugins/local-llm/src/commands.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ pub async fn get_current_model<R: tauri::Runtime>(
7979
app.get_current_model().map_err(|e| e.to_string())
8080
}
8181

82+
#[tauri::command]
83+
#[specta::specta]
84+
pub async fn list_downloaded_model<R: tauri::Runtime>(
85+
app: tauri::AppHandle<R>,
86+
) -> Result<Vec<crate::SupportedModel>, String> {
87+
app.list_downloaded_model().await.map_err(|e| e.to_string())
88+
}
89+
8290
#[tauri::command]
8391
#[specta::specta]
8492
pub async fn set_current_model<R: tauri::Runtime>(

plugins/local-llm/src/ext.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub trait LocalLlmPluginExt<R: Runtime> {
1515
fn start_server(&self) -> impl Future<Output = Result<String, crate::Error>>;
1616
fn stop_server(&self) -> impl Future<Output = Result<(), crate::Error>>;
1717

18+
fn list_downloaded_model(
19+
&self,
20+
) -> impl Future<Output = Result<Vec<crate::SupportedModel>, crate::Error>>;
1821
fn get_current_model(&self) -> Result<crate::SupportedModel, crate::Error>;
1922
fn set_current_model(&self, model: crate::SupportedModel) -> Result<(), crate::Error>;
2023

@@ -124,6 +127,40 @@ impl<R: Runtime, T: Manager<R>> LocalLlmPluginExt<R> for T {
124127
Ok(())
125128
}
126129

130+
#[tracing::instrument(skip_all)]
131+
async fn list_downloaded_model(&self) -> Result<Vec<crate::SupportedModel>, crate::Error> {
132+
let models_dir = self.models_dir();
133+
134+
if !models_dir.exists() {
135+
return Ok(vec![]);
136+
}
137+
138+
let mut models = Vec::new();
139+
140+
for entry in models_dir.read_dir()? {
141+
let entry = match entry {
142+
Ok(e) => e,
143+
Err(_) => {
144+
continue;
145+
}
146+
};
147+
148+
let file_name = entry.file_name();
149+
let file_name_str = file_name.to_string_lossy();
150+
151+
if let Some(model) = crate::model::SUPPORTED_MODELS
152+
.iter()
153+
.find(|model| model.file_name() == file_name_str)
154+
{
155+
if entry.path().is_file() {
156+
models.push(model.clone());
157+
}
158+
}
159+
}
160+
161+
Ok(models)
162+
}
163+
127164
#[tracing::instrument(skip_all)]
128165
async fn start_server(&self) -> Result<String, crate::Error> {
129166
let current_model = self.get_current_model()?;

plugins/local-llm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
4747
commands::restart_server::<Wry>,
4848
commands::get_current_model::<Wry>,
4949
commands::set_current_model::<Wry>,
50+
commands::list_downloaded_model::<Wry>,
5051
])
5152
.error_handling(tauri_specta::ErrorHandlingMode::Throw)
5253
}

0 commit comments

Comments
 (0)