feat(config): configurable LLM request timeout#134
Merged
Conversation
Add an optional `timeout:` config key, forwarded to LiteLLM's `timeout` parameter on OpenKB's own LLM calls. LiteLLM defaults to a 600s per-request timeout, which slow local backends (e.g. Ollama on large inputs) can exceed, raising `litellm.Timeout`. - config: resolve_timeout() validates a positive number of seconds; set_timeout()/get_timeout() stash it process-wide (mirrors extra_headers) - compiler: _llm_call / _llm_call_async forward the configured timeout, without overriding an explicit per-call value - cli: _setup_llm_key resolves + applies it from .openkb/config.yaml - tests + README Refs #132. The PageIndex long-doc path hardcodes its own litellm calls and is unaffected by this (covering it would need an upstream pageindex change).
Addresses self-review of the configurable LLM timeout:
- resolve_timeout(): reject non-finite values (nan/inf, including YAML's
`.nan`/`.inf`) via math.isfinite — they slipped past the `<= 0` guard and
would reach litellm as a bogus timeout (hang on nan, OverflowError on inf).
- Extend the configured timeout to the openai-agents paths (query, chat,
lint, skill) via ModelSettings(extra_args={"timeout": ...}), the way
extra_headers already reaches them. Previously only the compiler calls
honored it, so `openkb chat`/`query`/`lint`/`skill` still hit LiteLLM's 600s.
- Tests: nan/inf rejection; async omit/override symmetry; cli wiring
(config -> stash + reset-when-absent); query-agent extra_args coverage.
- README: note the broadened coverage and that PageIndex indexing is exempt.
- README: list `timeout` in the main config.yaml example (marked optional) instead of a separate advanced-options paragraph - config: shorten the resolve_timeout / _runtime_timeout / get_timeout_extra_args comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
timeout:config key (seconds), forwarded to LiteLLM'stimeouton all of OpenKB's own LLM calls. LiteLLM applies a 600s per-request timeout by default, which slow local backends (e.g. Ollama on large inputs) exceed, raisinglitellm.Timeout— see #132.What changed
resolve_timeout()validates a finite positive number of seconds (rejects bool /nan/inf/ non-numeric);set_timeout()/get_timeout()stash it process-wide, mirroring the existingextra_headersmechanism._llm_call/_llm_call_asyncforward the timeout, without overriding an explicit per-call value.ModelSettings(extra_args={"timeout": ...}), the wayextra_headersalready reaches them._setup_llm_keyresolves + applies it from.openkb/config.yaml.Test plan
tests/test_config.py— resolver cases incl.nan/inf/bool/non-numeric rejection.tests/test_llm_timeout.py— timeout forwarded / omitted / not-overridden, sync and async.tests/test_cli.py— config → stash wiring + reset-when-absent.tests/test_query.py— agent-pathextra_argscoverage.tests/test_url_ingest.pyfailures are a pre-existing local-env issue —trafilaturanot installed — and are unrelated to this change.)Refs #132. Covers OpenKB's own calls; PageIndex's internal LLM calls hardcode their request and would need an upstream change to honor this.