feat: Add cache warming functionality to base_coder.py

This commit is contained in:
Paul Gauthier (aider) 2024-08-26 15:27:58 -07:00
parent 0f8354dd6a
commit 17d210be4a

View file

@ -23,6 +23,7 @@ from rich.console import Console, Text
from rich.markdown import Markdown
from aider import __version__, models, prompts, urls, utils
from aider.sendchat import retry_exceptions
from aider.commands import Commands
from aider.history import ChatSummary
from aider.io import ConfirmGroup, InputOutput
@ -984,6 +985,26 @@ class Coder:
return chunks
def warm_cache(self, chunks):
if self.add_cache_headers:
chunks.add_cache_control_headers()
if self.cache_warming_thread and self.cache_warming_thread.is_alive():
self.cache_warming_thread.cancel()
def warm_cache_worker():
for _ in range(5):
try:
self.send(chunks.cacheable_messages(), stream=False)
except retry_exceptions() as err:
self.io.tool_error(f"Cache warming error: {str(err)}")
time.sleep(290) # 4 minutes and 50 seconds
self.cache_warming_thread = threading.Timer(0, warm_cache_worker)
self.cache_warming_thread.start()
return chunks
def send_message(self, inp):
self.cur_messages += [
dict(role="user", content=inp),