Deterministic offline backend used when no credentials are available. Returns a stable hash-derived snippet so call sites can run end-to-end in tests without making network calls. The text is not meaningful — it is only intended to keep pipelines flowing.
| 330 | |
| 331 | |
| 332 | class MockLLM: |
| 333 | """Deterministic offline backend used when no credentials are available. |
| 334 | |
| 335 | Returns a stable hash-derived snippet so call sites can run end-to-end in |
| 336 | tests without making network calls. The text is not meaningful — it is |
| 337 | only intended to keep pipelines flowing. |
| 338 | """ |
| 339 | |
| 340 | name = "mock" |
| 341 | |
| 342 | def __init__(self, model: str = "mock-llm") -> None: |
| 343 | self.model = model |
| 344 | |
| 345 | def generate( |
| 346 | self, |
| 347 | prompt: str, |
| 348 | *, |
| 349 | system: Optional[str] = None, |
| 350 | temperature: float = 0.0, |
| 351 | max_tokens: int = 1024, |
| 352 | ) -> LLMResponse: |
| 353 | digest = hashlib.sha256((system or "").encode("utf-8") + b"||" + prompt.encode("utf-8")).hexdigest() |
| 354 | text = f"[mock-llm:{digest[:12]}] {prompt[:120]}" |
| 355 | return LLMResponse(text=text, model=self.model, provider=self.name) |
| 356 | |
| 357 | def stream_generate( |
| 358 | self, |
| 359 | prompt: str, |
| 360 | *, |
| 361 | system: Optional[str] = None, |
| 362 | temperature: float = 0.0, |
| 363 | max_tokens: int = 1024, |
| 364 | ) -> Iterator[str]: |
| 365 | yield from _chunk_text(self.generate(prompt, system=system, temperature=temperature, max_tokens=max_tokens).text) |
| 366 | |
| 367 | |
| 368 | def _is_placeholder(value: Optional[str]) -> bool: |
no outgoing calls