Files
Felix 920dc2117e feat(llm): add deterministic local response cache
Cache Pi LLM responses by a stable hash of system instruction, model, combined prompt, and seed. Default the node to use cached responses when present and generate/store them on first run, with modes for refresh, cache-only, and disabling cache. Document same-machine reproducibility behavior and cover cache decisions with unit tests.
2026-07-05 13:39:42 +01:00

51 lines
1.6 KiB
Python

from __future__ import annotations
import unittest
from unittest.mock import patch
from nodes import PiLLMText
class PiLLMTextNodeTests(unittest.TestCase):
def test_saved_text_if_present_skips_pi_call(self):
node = PiLLMText()
with patch("nodes.resolve_pi_response") as resolve_pi_response:
result = node.generate(
system_instruction="sys",
model_name="minimax/MiniMax-M3",
prompt="prompt",
response_mode="use_saved_text_if_present",
cache_mode="use_cache_or_generate",
saved_response=" saved output ",
seed=0,
timeout_seconds=120,
run_every_queue=False,
)
resolve_pi_response.assert_not_called()
self.assertEqual(result, ("saved output",))
def test_saved_text_if_present_generates_when_saved_text_is_empty(self):
node = PiLLMText()
with patch("nodes.resolve_pi_response", return_value="live output") as resolve_pi_response:
result = node.generate(
system_instruction="sys",
model_name="minimax/MiniMax-M3",
prompt="prompt",
response_mode="use_saved_text_if_present",
cache_mode="use_cache_or_generate",
saved_response=" ",
seed=0,
timeout_seconds=120,
run_every_queue=False,
)
resolve_pi_response.assert_called_once()
self.assertEqual(result, ("live output",))
if __name__ == "__main__":
unittest.main()