feat : server response cache
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user