fix: add --base_url CLI option for custom LLM endpoints#229
fix: add --base_url CLI option for custom LLM endpoints#229octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
Conversation
…yAI#224) Expose OPENAI_API_BASE through a --base_url CLI argument so users can point PageIndex at Ollama, vLLM, LM Studio, or any other OpenAI-compatible local server without manually setting environment variables. - run_pageindex.py: add --base_url argument that sets OPENAI_API_BASE - utils.py: read OPENAI_API_BASE in llm_completion / llm_acompletion and pass as api_base to litellm, enabling custom endpoints for all LLM calls Usage: python run_pageindex.py --pdf_path doc.pdf \ --model ollama/llama3 \ --base_url http://localhost:11434
|
Thanks for the contribution. I think we should be careful about the scope here. If the goal is to let users choose an LLM provider, this is already supported through LiteLLM model strings. For issue #224 specifically, the missing piece is not provider selection, but a custom OpenAI-compatible base URL. That is a valid feature request, but I do not think this PR
I would suggest either closing this as redundant if the intent is provider selection, or reworking it as a proper custom endpoint feature wired through the shared config/API |
Fixes #224
Problem
Users running local LLM servers (Ollama, vLLM, LM Studio, etc.) have no way to specify a custom API base URL through the CLI. The
OPENAI_API_BASEenvironment variable works when set manually, but there is no--base_urlargument, making the workflow unnecessarily awkward.Solution
run_pageindex.py: Added--base_urlargument that setsos.environ["OPENAI_API_BASE"]before any LLM calls are made.pageindex/utils.py: Updatedllm_completionandllm_acompletionto readOPENAI_API_BASEfrom the environment and forward it to litellm asapi_base, so all LLM calls in the pipeline respect the custom endpoint.The change is fully backward-compatible: if
--base_urlis not provided andOPENAI_API_BASEis not set, behaviour is identical to before.Usage
Testing
Verified that the argument is parsed correctly and
OPENAI_API_BASEis set before any LLM call. Theapi_basekwarg is only injected into litellm when the env var is present, so there is no overhead for standard OpenAI usage.