mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
feat: Add cache warming functionality to base_coder.py
This commit is contained in:
parent
0f8354dd6a
commit
17d210be4a
1 changed files with 21 additions and 0 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue