From 22cd638add274635bb88eade529aa0e6e020d10b Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 18 May 2025 18:43:40 -0700 Subject: [PATCH] Fix handling unset openai_base_url to run eval with openai chat models The github run_eval workflow sets OPENAI_BASE_URL to empty string. The ai model api created during initialization for openai models gets set to empty string rather than None or the actual openai base url This tries to call llm at to empty string base url instead of the default openai api base url, which obviously fails. Fix is to map empty base url's to the actual openai api base url. --- .github/workflows/run_evals.yml | 4 ++-- src/khoj/utils/initialization.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_evals.yml b/.github/workflows/run_evals.yml index 4faeaec6..0d6490d5 100644 --- a/.github/workflows/run_evals.yml +++ b/.github/workflows/run_evals.yml @@ -58,7 +58,7 @@ on: openai_base_url: description: 'Base URL of OpenAI compatible API' required: false - default: '' + default: 'https://api.openai.com/v1' type: string auto_read_webpage: description: 'Auto read webpage on online search' @@ -150,7 +150,7 @@ jobs: KHOJ_RESEARCH_ITERATIONS: ${{ github.event_name == 'workflow_dispatch' && inputs.max_research_iterations || 10 }} KHOJ_AUTO_READ_WEBPAGE: ${{ github.event_name == 'workflow_dispatch' && inputs.auto_read_webpage || 'false' }} GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} - OPENAI_BASE_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.openai_base_url || '' }} + OPENAI_BASE_URL: ${{ github.event_name == 'workflow_dispatch' && inputs.openai_base_url || 'https://api.openai.com/v1' }} SERPER_DEV_API_KEY: ${{ matrix.dataset != 'math500' && secrets.SERPER_DEV_API_KEY || '' }} OLOSTEP_API_KEY: ${{ matrix.dataset != 'math500' && secrets.OLOSTEP_API_KEY || ''}} FIRECRAWL_API_KEY: ${{ matrix.dataset != 'math500' && secrets.FIRECRAWL_API_KEY || '' }} diff --git a/src/khoj/utils/initialization.py b/src/khoj/utils/initialization.py index b039c30d..903c1278 100644 --- a/src/khoj/utils/initialization.py +++ b/src/khoj/utils/initialization.py @@ -43,7 +43,7 @@ def initialization(interactive: bool = True): "🗣️ Configure chat models available to your server. You can always update these at /server/admin using your admin account" ) - openai_base_url = os.getenv("OPENAI_BASE_URL") + openai_base_url = os.getenv("OPENAI_BASE_URL") or None provider = "Ollama" if openai_base_url and openai_base_url.endswith(":11434/v1/") else "OpenAI" openai_api_key = os.getenv("OPENAI_API_KEY", "placeholder" if openai_base_url else None) default_chat_models = default_openai_chat_models @@ -329,4 +329,4 @@ def initialization(interactive: bool = True): ) return ConversationAdapters.set_default_chat_model(chat_model) - logger.info(f"🗣️ Default chat model set to {chat_model.name}") + logger.info(f"🗣️ Default chat model set to {chat_model.name} served by {chat_model.ai_model_api}")