PageIndex icon indicating copy to clipboard operation
PageIndex copied to clipboard

Add ollama support

Open rajo69 opened this issue 9 months ago • 2 comments

Fixes #115

What this adds

  • --base-url CLI flag for pointing PageIndex at any OpenAI-compatible endpoint (Ollama, LM Studio, Azure OpenAI, AWS Bedrock, Mistral, etc.).
  • base_url parameter threaded through all LLM call functions in page_index.py, page_index_md.py, and utils.py.
  • base_url: null added to config.yaml defaults so existing behaviour is completely unchanged when the flag is not provided.
  • Fixes a KeyError crash in count_tokens() where tiktoken could not find an encoding for non-OpenAI model names. Now falls back to cl100k_base instead 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-url flag accepted by CLI and passed through to all LLM calls

rajo69 avatar Mar 03 '26 01:03 rajo69

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?

wangxy204 avatar Mar 18 '26 08:03 wangxy204

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.

ryanwong00 avatar May 01 '26 15:05 ryanwong00

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! 🙏

KylinMountain avatar Jul 03 '26 09:07 KylinMountain