Skip to content

Commit e2e9835

Browse files
committed
feat: 添加了自动拉取AI模型到本地的功能
1 parent a22c5db commit e2e9835

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

src-tauri/src/commands/utils.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,48 @@ fn export_logs_internal(log_dir: &str, save_path: &str) -> Result<(), String> {
148148
pub fn command_get_arch() -> String {
149149
std::env::consts::ARCH.to_string()
150150
}
151+
152+
#[tauri::command]
153+
pub fn command_download_model(save_path: String) {
154+
let url = "https://github.com/ghost-him/ZeroLaunch-rs/releases/download/model/EmbeddingGemma-300m.zip";
155+
let save_path = Path::new(&save_path).join("EmbeddingGemma-300m.zip");
156+
let save_path_str = save_path
157+
.to_str()
158+
.unwrap_or("EmbeddingGemma-300m.zip")
159+
.replace("'", "''");
160+
161+
let script = format!(
162+
"Write-Host 'Downloading AI Model...'; \
163+
Write-Host (' '); \
164+
Write-Host (' '); \
165+
Write-Host (' '); \
166+
Write-Host (' '); \
167+
Write-Host (' '); \
168+
Write-Host (' '); \
169+
Write-Host (' '); \
170+
$url = '{}'; \
171+
$output = '{}'; \
172+
Write-Host ('Source: ' + $url); \
173+
Write-Host ('Destination: ' + $output); \
174+
try {{ \
175+
$start = Get-Date; \
176+
Invoke-WebRequest -Uri $url -OutFile $output; \
177+
$end = Get-Date; \
178+
$duration = $end - $start; \
179+
$file = Get-Item $output; \
180+
$sizeMB = $file.Length / 1MB; \
181+
Write-Host ('Download Complete!'); \
182+
Write-Host ('File Size: {{0:N2}} MB' -f $sizeMB); \
183+
Write-Host ('Time Elapsed: ' + $duration); \
184+
}} catch {{ \
185+
Write-Error $_; \
186+
}} \
187+
Read-Host 'Press Enter to exit...'",
188+
url, save_path_str
189+
);
190+
191+
std::process::Command::new("cmd")
192+
.args(["/C", "start", "powershell", "-Command", &script])
193+
.spawn()
194+
.ok();
195+
}

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub fn run() {
215215
command_search_programs_lightweight,
216216
command_update_program_icon,
217217
command_get_arch,
218+
command_download_model,
218219
get_everything_icon,
219220
])
220221
.build(tauri::generate_context!())

src-ui/i18n/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@
243243
"semantic_tip_description": "Providing richer description information helps the model deliver more accurate functional search.",
244244
"semantic_tip_performance": "When enabled, initialization and database updates may use the GPU and significantly increase loading time.",
245245
"open_model_folder": "Open Model Folder",
246+
"download_model": "Download Model",
247+
"select_download_folder": "Select Download Folder",
246248
"open_model_description": "Open Description File",
247249
"sorting_algorithm_settings": "Sorting Algorithm Parameters",
248250
"enable_sorting": "Enable Sorting Algorithm",

src-ui/i18n/locales/zh-Hans.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@
243243
"semantic_tip_description": "如果补充更丰富的描述信息,可让模型提供更准确的功能性搜索。",
244244
"semantic_tip_performance": "启用后,在初始化与更新数据库阶段可能占用 GPU,并显著延长加载时间。",
245245
"open_model_folder": "打开模型文件夹",
246+
"download_model": "下载模型",
247+
"select_download_folder": "选择下载保存的文件夹",
246248
"open_model_description": "打开描述信息文件",
247249
"sorting_algorithm_settings": "排序算法参数设置",
248250
"enable_sorting": "启用排序算法",

src-ui/i18n/locales/zh-Hant.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@
243243
"semantic_tip_description": "若補充更完整的描述資訊,可讓模型提供更精準的功能性搜尋。",
244244
"semantic_tip_performance": "啟用後,在初始化與更新資料庫階段可能佔用 GPU,並明顯延長載入時間。",
245245
"open_model_folder": "開啟模型資料夾",
246+
"download_model": "下載模型",
247+
"select_download_folder": "選擇下載保存的資料夾",
246248
"open_model_description": "開啟描述資訊檔案",
247249
"sorting_algorithm_settings": "排序演算法參數設定",
248250
"enable_sorting": "啟用排序演算法",

src-ui/windows/settings/programs/Advanced.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@
125125
>
126126
{{ t('program_index.open_model_folder') || '打开模型文件夹 (TODO)' }}
127127
</el-button>
128+
<el-button
129+
type="primary"
130+
@click="downloadModel"
131+
>
132+
{{ t('program_index.download_model') || '下载模型' }}
133+
</el-button>
128134
</div>
129135
</el-card>
130136
</div>
@@ -376,6 +382,7 @@ import { useRemoteConfigStore } from '../../../stores/remote_config'
376382
import { storeToRefs } from 'pinia'
377383
import { QuestionFilled } from '@element-plus/icons-vue'
378384
import { invoke } from '@tauri-apps/api/core'
385+
import { open } from '@tauri-apps/plugin-dialog'
379386
380387
const { t } = useI18n()
381388
const configStore = useRemoteConfigStore()
@@ -391,6 +398,18 @@ const search_model = computed(() => [
391398
const openModelFolder = async () => {
392399
await invoke('command_open_models_dir')
393400
}
401+
402+
const downloadModel = async () => {
403+
const selected = await open({
404+
directory: true,
405+
multiple: false,
406+
title: t('program_index.select_download_folder') || '选择下载保存的文件夹',
407+
});
408+
409+
if (selected) {
410+
await invoke('command_download_model', { savePath: selected });
411+
}
412+
}
394413
</script>
395414

396415
<style scoped>

0 commit comments

Comments
 (0)