mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44: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 rich.markdown import Markdown
|
||||||
|
|
||||||
from aider import __version__, models, prompts, urls, utils
|
from aider import __version__, models, prompts, urls, utils
|
||||||
|
from aider.sendchat import retry_exceptions
|
||||||
from aider.commands import Commands
|
from aider.commands import Commands
|
||||||
from aider.history import ChatSummary
|
from aider.history import ChatSummary
|
||||||
from aider.io import ConfirmGroup, InputOutput
|
from aider.io import ConfirmGroup, InputOutput
|
||||||
|
@ -984,6 +985,26 @@ class Coder:
|
||||||
|
|
||||||
return chunks
|
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):
|
def send_message(self, inp):
|
||||||
self.cur_messages += [
|
self.cur_messages += [
|
||||||
dict(role="user", content=inp),
|
dict(role="user", content=inp),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue