Skip to main content

llm_manager/tui/app/
pickers.rs

1use super::types::App;
2use crate::backend::hardware;
3
4impl App {
5    pub fn fetch_host_picker_entries() -> Vec<(String, String)> {
6        let mut entries = Vec::new();
7
8        // Always include these two at the top
9        entries.push(("127.0.0.1".to_string(), "localhost".to_string()));
10        entries.push(("0.0.0.0".to_string(), "All interfaces".to_string()));
11
12        // Add real network interfaces
13        if let Ok(ifaces) = local_ip_address::list_afinet_netifas() {
14            for (name, ip) in ifaces {
15                let ip_str = ip.to_string();
16                if ip_str != "127.0.0.1" && ip_str != "0.0.0.0" {
17                    entries.push((ip_str, name));
18                }
19            }
20        }
21
22        entries
23    }
24
25    pub fn fetch_backend_picker_entries(&self) -> Vec<(crate::models::Backend, Option<String>)> {
26        let platform = hardware::detect_platform();
27        let mut entries = Vec::new();
28
29        // 1. Add "latest" entries for backends supported on this platform
30        match platform {
31            crate::backend::hardware::Platform::Linux => {
32                entries.push((crate::models::Backend::Cpu, None));
33                entries.push((crate::models::Backend::Vulkan, None));
34                if hardware::is_arm64() {
35                    entries.push((crate::models::Backend::CpuArm64, None));
36                }
37                for vendor in hardware::detect_gpu_vendors() {
38                    match vendor {
39                        hardware::GpuVendor::Amd => {
40                            entries.push((crate::models::Backend::Rocm, None));
41                            entries.push((crate::models::Backend::RocmLemonade, None));
42                        }
43                        hardware::GpuVendor::Nvidia => {
44                            entries.push((crate::models::Backend::Cuda, None));
45                        }
46                        _ => {}
47                    }
48                }
49            }
50            crate::backend::hardware::Platform::Windows => {
51                entries.push((crate::models::Backend::CpuWindows, None));
52                entries.push((crate::models::Backend::VulkanWindows, None));
53                for vendor in hardware::detect_gpu_vendors() {
54                    match vendor {
55                        hardware::GpuVendor::Nvidia => {
56                            entries.push((crate::models::Backend::CudaWindows12_4, None));
57                            entries.push((crate::models::Backend::CudaWindows13_1, None));
58                        }
59                        hardware::GpuVendor::Amd => {
60                            entries.push((crate::models::Backend::HipWindows, None));
61                        }
62                        _ => {}
63                    }
64                }
65            }
66            crate::backend::hardware::Platform::Macos => {
67                if hardware::is_arm64() {
68                    entries.push((crate::models::Backend::CpuMacosArm64, None));
69                } else {
70                    entries.push((crate::models::Backend::CpuMacosX64, None));
71                }
72            }
73        }
74
75        // 2. Add all installed versions (filtered by platform)
76        let installed = crate::backend::hub::list_installed_backends();
77        for (b, tag) in installed {
78            if hardware::backend_supported(b, platform) {
79                entries.push((b, Some(tag)));
80            }
81        }
82
83        entries
84    }
85}