feat : server response cache

This commit is contained in:
martin legrand
2025-04-05 16:36:58 +02:00
parent 688e94d97c
commit 97708c7947
7 changed files with 50 additions and 28 deletions
+5
View File
@@ -13,6 +13,10 @@ class OllamaLLM(GeneratorLLM):
def generate(self, history):
self.logger.info(f"Using {self.model} for generation with Ollama")
if cache.is_cached(history[-1]['content']):
self.state.current_buffer = cache.get_cached_response(history[-1]['content'])
self.state.is_generating = False
return
try:
with self.state.lock:
self.state.is_generating = True
@@ -43,6 +47,7 @@ class OllamaLLM(GeneratorLLM):
self.logger.info("Generation complete")
with self.state.lock:
self.state.is_generating = False
self.cache.add_message_pair(history[-1]['content'], self.state.current_buffer)
if __name__ == "__main__":
generator = OllamaLLM()