foley.agent.local_llm

Offline / local-LLM SELECT rungs — OpenAI-compatible Decomposer / Judge / Refiner.

The offline sibling of the Anthropic-backed SELECT rungs: instead of calling the hosted Claude API, these hit any OpenAI-compatible chat endpoint — an on-device server such as Ollama (http://localhost:11434/v1), llama.cpp’s server, or vLLM — so foley.find can run its LLM decomposition / judging / refinement with nothing leaving the device (report 12’s offline posture). They satisfy the same foley.agent.protocols seams and REUSE the exact system prompts + JSON schemas the Anthropic rungs use (one prompt SSOT), differing only in the transport.

Zero-config wiring: set FOLEY_LLM_BASE_URL (+ optionally FOLEY_LLM_MODEL / FOLEY_LLM_API_KEY) and the SELECT defaults auto-upgrade to these — see local_llm_configured(), consulted by _default_decomposer / _default_judge / _default_refiner. openai (the thin OpenAI client, foley[local-llm]) is imported LAZILY inside the call path only, so import foley / import foley.agent stay dol-only; tests inject a fake client and never touch the network.

foley.agent.local_llm.DEFAULT_LOCAL_MODEL = 'llama3.1'

The default local model id (override per call or via FOLEY_LLM_MODEL).

class foley.agent.local_llm.LocalLLMDecomposer(*, client=None, model: str | None = None, max_tokens: int = 2000)[source]

OpenAI-compatible Decomposer (local endpoint).

decompose(context: str, *, max_events: int = 6, seconds: float | None = None) list[SoundEvent][source]

Decompose context into <= max_events events via the local LLM.

class foley.agent.local_llm.LocalLLMJudge(*, client=None, model: str | None = None, max_tokens: int = 500)[source]

OpenAI-compatible Judge for the judge rung.

judge(event: SoundEvent, candidate: Candidate, *, level=None) Verdict[source]

Arbitrate the match via the local LLM; returns a Verdict at level.

class foley.agent.local_llm.LocalLLMRefiner(*, client=None, model: str | None = None, max_tokens: int = 500)[source]

OpenAI-compatible Refiner (local endpoint).

refine(query: str, *, n: int = 3, hint: str | None = None) list[str][source]

Return n paraphrases via the local LLM (the original query always first).

foley.agent.local_llm.local_llm_configured() bool[source]

True iff a local OpenAI-compatible endpoint is configured (FOLEY_LLM_BASE_URL).