Add ollama support
Fixes #115
What this adds
--base-urlCLI flag for pointing PageIndex at any OpenAI-compatible endpoint (Ollama, LM Studio, Azure OpenAI, AWS Bedrock, Mistral, etc.).base_urlparameter threaded through all LLM call functions inpage_index.py,page_index_md.py, andutils.py.base_url: nulladded toconfig.yamldefaults so existing behaviour is completely unchanged when the flag is not provided.- Fixes a
KeyErrorcrash incount_tokens()where tiktoken could not find an encoding for non-OpenAI model names. Now falls back tocl100k_baseinstead of crashing.
Usage
# Ollama
python run_pageindex.py --pdf_path doc.pdf --model llama3.1 --base-url http://localhost:11434/v1
# Any OpenAI-compatible provider
python run_pageindex.py --pdf_path doc.pdf --model mistral --base-url https://your-custom-endpoint/v1
Breaking changes
None. base_url defaults to null and all existing calls work without any changes.
Tested
- Default usage (no
--base-url) - behaviour identical to before count_tokens()with a non-OpenAI model name - no longer crashes--base-urlflag accepted by CLI and passed through to all LLM calls
got API key errors: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable. I don have the api keys saved in but it should use local models in ollama to generate json file instead of using the APIs? Am I misunderstanding here?
Since pageIndex used litellm to connect to LLMs, as an interim solution, I set an OS environment variable OLLAMA_API_BASE to http://xxxxxx:11434 and set the model to something like "ollama/...." and it seems working.
Thanks @rajo69! Ollama is now supported out of the box through the LiteLLM integration (#168, merged) — just pass an ollama/<model> model name. Closing as covered, appreciate the contribution! 🙏