Skip to content

AutoShorts is a local-first desktop application for turning long-form video or audio recordings into high-impact, vertical short-form clip candidates (9:16 portrait) with AI-powered viral moment ranking.

Rust

feat: add support for custom OpenRouter model selection via frontend settings and backend API calls

Jethro Adamu5901e8b3b084
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 7e0f790..fad9cc7 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -479,7 +479,7 @@ async fn generate_candidates(
let key = api_key
.or_else(|| std::env::var("OPENROUTER_API_KEY").ok())
.ok_or_else(|| "Set OPENROUTER_API_KEY or supply OpenRouter API Key to generate candidates.".to_string())?;
- llm::detect_candidates_with_openrouter(&normalized, &key)
+ llm::detect_candidates_with_openrouter(&normalized, &key, model_name.as_deref())
.await
.map_err(to_command_error)?
}
diff --git a/src-tauri/src/llm.rs b/src-tauri/src/llm.rs
index 1620ab1..56f7f9b 100644
--- a/src-tauri/src/llm.rs
+++ b/src-tauri/src/llm.rs
@@ -252,6 +252,7 @@ Avoid rambling setup, context-dependent references, and pure filler. Return up t
pub async fn detect_candidates_with_openrouter(
transcript: &NormalizedTranscript,
api_key: &str,
+ model_name: Option<&str>,
) -> Result<Vec<CandidateDraft>> {
let segments = compact_segments(&transcript.segments);
let prompt = format!(
@@ -263,8 +264,12 @@ Avoid rambling setup, context-dependent references, and pure filler. Return up t
{{\"candidates\":[{{\"start\":0.0,\"end\":0.0,\"score\":0.0,\"hook\":\"...\",\"rationale\":\"...\"}}]}}\n\nTranscript:\n{segments}"
);
- let model =
- std::env::var("OPENROUTER_MODEL").unwrap_or_else(|_| "google/gemini-2.5-flash".to_string());
+ let default_model = "google/gemini-2.5-flash".to_string();
+ let model = model_name
+ .filter(|m| !m.trim().is_empty())
+ .map(|m| m.trim().to_string())
+ .or_else(|| std::env::var("OPENROUTER_MODEL").ok().filter(|m| !m.trim().is_empty()))
+ .unwrap_or(default_model);
let response = reqwest::Client::new()
.post("https://openrouter.ai/api/v1/chat/completions")
diff --git a/src/main.tsx b/src/main.tsx
index 21ef244..0a0c630 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -155,6 +155,9 @@ function App() {
const [openrouterKey, setOpenrouterKey] = useState(() => {
return localStorage.getItem("autoshorts_openrouter_key") || "";
});
+ const [openrouterModel, setOpenrouterModel] = useState(() => {
+ return localStorage.getItem("autoshorts_openrouter_model") || "";
+ });
const [downloadingModelName, setDownloadingModelName] = useState<string | null>(null);
const [modelDownloadStatus, setModelDownloadStatus] = useState("");
@@ -255,6 +258,10 @@ function App() {
localStorage.setItem("autoshorts_openrouter_key", openrouterKey);
}, [openrouterKey]);
+ useEffect(() => {
+ localStorage.setItem("autoshorts_openrouter_model", openrouterModel);
+ }, [openrouterModel]);
+
const pullModelDirectly = async (modelName: string) => {
setDownloadingModelName(modelName);
setModelDownloadProgress(0);
@@ -420,7 +427,7 @@ function App() {
projectId,
apiKey: activeKey || null,
provider: llmEngine,
- modelName: llmEngine === "local" ? localLlmModel.trim() : (llmEngine === "deepseek" ? (deepseekModel.trim() || null) : null),
+ modelName: llmEngine === "local" ? localLlmModel.trim() : (llmEngine === "deepseek" ? (deepseekModel.trim() || null) : (llmEngine === "openrouter" ? (openrouterModel.trim() || null) : null)),
allowDemo: false,
});
await refresh(projectId);
@@ -502,7 +509,7 @@ function App() {
projectId: detail.project.id,
apiKey: activeKey || null,
provider: llmEngine,
- modelName: llmEngine === "local" ? localLlmModel.trim() : (llmEngine === "deepseek" ? (deepseekModel.trim() || null) : null),
+ modelName: llmEngine === "local" ? localLlmModel.trim() : (llmEngine === "deepseek" ? (deepseekModel.trim() || null) : (llmEngine === "openrouter" ? (openrouterModel.trim() || null) : null)),
allowDemo,
});
await refresh(detail.project.id);
@@ -758,15 +765,26 @@ function App() {
</label>
)}
{llmEngine === "openrouter" && (
- <label>
- <span>OpenRouter API Key</span>
- <input
- value={openrouterKey}
- onChange={(event) => setOpenrouterKey(event.target.value)}
- placeholder={environment?.hasOpenrouterKey ? "Loaded from env" : "Optional (OpenRouter API Key)"}
- type="password"
- />
- </label>
+ <>
+ <label>
+ <span>OpenRouter API Key</span>
+ <input
+ value={openrouterKey}
+ onChange={(event) => setOpenrouterKey(event.target.value)}
+ placeholder={environment?.hasOpenrouterKey ? "Loaded from env" : "Optional (OpenRouter API Key)"}
+ type="password"
+ />
+ </label>
+ <label>
+ <span>OpenRouter Model</span>
+ <input
+ value={openrouterModel}
+ onChange={(event) => setOpenrouterModel(event.target.value)}
+ placeholder="Optional (e.g. google/gemini-2.5-flash, deepseek/deepseek-r1)"
+ type="text"
+ />
+ </label>
+ </>
)}
{llmEngine === "local" && (