fix(custom_url_support): makes api key optional

This commit is contained in:
sauravniraula 2025-07-08 16:12:47 +05:45
parent d597464717
commit d5cb629d2b
No known key found for this signature in database
GPG key ID: 60FCC1B5A5E83326
5 changed files with 12 additions and 18 deletions

View file

@ -36,10 +36,10 @@ def get_selected_llm_provider() -> SelectedLLMProvider:
async def list_available_custom_models(
url: Optional[str] = None, api_key: Optional[str] = None
) -> list[str]:
if not url or not api_key:
if not url:
client = get_llm_client()
else:
client = openai.AsyncOpenAI(api_key=api_key, base_url=url)
client = openai.AsyncOpenAI(api_key=api_key or "null", base_url=url)
models = []
async for model in client.models.list():
models.append(model.id)
@ -70,7 +70,7 @@ def get_llm_api_key():
elif selected_llm == SelectedLLMProvider.OLLAMA:
return "ollama"
elif selected_llm == SelectedLLMProvider.CUSTOM:
return os.getenv("CUSTOM_LLM_API_KEY")
return os.getenv("CUSTOM_LLM_API_KEY") or "null"
else:
raise ValueError(f"Invalid LLM API key")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 397 KiB

View file

@ -266,8 +266,7 @@ const SettingsPage = () => {
fetchOllamaModels();
} else if (userConfigState.llm_config.LLM === 'custom' &&
userConfigState.llm_config.CUSTOM_MODEL &&
userConfigState.llm_config.CUSTOM_LLM_URL &&
userConfigState.llm_config.CUSTOM_LLM_API_KEY) {
userConfigState.llm_config.CUSTOM_LLM_URL) {
fetchCustomModels();
}
}, [userConfigState.llm_config.LLM]);
@ -515,11 +514,6 @@ const SettingsPage = () => {
</div>
<p className="mt-2 text-sm text-gray-500">Provide a Pexels API key to generate presentation images</p>
</div>
{downloadingModel.status && downloadingModel.status !== 'pulled' && (
<div className="text-sm text-center bg-green-100 rounded-lg p-2 font-semibold capitalize text-gray-600">
{downloadingModel.status}
</div>
)}
</div>
)}
@ -618,8 +612,8 @@ const SettingsPage = () => {
<div>
<button
onClick={fetchCustomModels}
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 font-semibold ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 font-semibold ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL
? 'bg-gray-100 border-gray-300 cursor-not-allowed text-gray-500'
: 'bg-white border-blue-600 text-blue-600 hover:bg-blue-50 focus:ring-2 focus:ring-blue-500/20'
}`}
@ -650,8 +644,8 @@ const SettingsPage = () => {
<div>
<button
onClick={fetchCustomModels}
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 font-semibold ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 font-semibold ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL
? 'bg-gray-100 border-gray-300 cursor-not-allowed text-gray-500'
: 'bg-white border-gray-600 text-gray-600 hover:bg-gray-50 focus:ring-2 focus:ring-gray-500/20'
}`}

View file

@ -622,7 +622,7 @@ export default function Home() {
</div>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
OpenAI Compatible API Key
OpenAI Compatible API Key (optional)
</label>
<div className="relative">
<input
@ -697,8 +697,8 @@ export default function Home() {
<div className="mb-4">
<button
onClick={fetchCustomModels}
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL || !llmConfig.CUSTOM_LLM_API_KEY
disabled={customModelsLoading || !llmConfig.CUSTOM_LLM_URL}
className={`w-full py-2.5 px-4 rounded-lg transition-all duration-200 border-2 ${customModelsLoading || !llmConfig.CUSTOM_LLM_URL
? 'bg-gray-100 border-gray-300 cursor-not-allowed text-gray-500'
: 'bg-white border-blue-600 text-blue-600 hover:bg-blue-50 focus:ring-2 focus:ring-blue-500/20'
}`}

View file

@ -20,7 +20,7 @@ export const hasValidLLMConfig = (llmConfig: LLMConfig) => {
const GOOGLE_API_KEY = llmConfig.GOOGLE_API_KEY;
const isOllamaConfigValid = llmConfig.OLLAMA_MODEL !== '' && llmConfig.OLLAMA_MODEL !== null && llmConfig.OLLAMA_MODEL !== undefined && llmConfig.OLLAMA_URL !== '' && llmConfig.OLLAMA_URL !== null && llmConfig.OLLAMA_URL !== undefined;
const isCustomConfigValid = llmConfig.CUSTOM_LLM_URL !== '' && llmConfig.CUSTOM_LLM_URL !== null && llmConfig.CUSTOM_LLM_URL !== undefined && llmConfig.CUSTOM_LLM_API_KEY !== '' && llmConfig.CUSTOM_LLM_API_KEY !== null && llmConfig.CUSTOM_LLM_API_KEY !== undefined && llmConfig.CUSTOM_MODEL !== '' && llmConfig.CUSTOM_MODEL !== null && llmConfig.CUSTOM_MODEL !== undefined;
const isCustomConfigValid = llmConfig.CUSTOM_LLM_URL !== '' && llmConfig.CUSTOM_LLM_URL !== null && llmConfig.CUSTOM_LLM_URL !== undefined && llmConfig.CUSTOM_MODEL !== '' && llmConfig.CUSTOM_MODEL !== null && llmConfig.CUSTOM_MODEL !== undefined;
return llmConfig.LLM === 'openai' ?
OPENAI_API_KEY !== '' && OPENAI_API_KEY !== null && OPENAI_API_KEY !== undefined :