mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
fix: Add cache control headers to chat messages
This commit is contained in:
parent
a849a98164
commit
022d103a99
2 changed files with 35 additions and 5 deletions
|
@ -66,14 +66,39 @@ class ChatChunks:
|
|||
return (
|
||||
self.system
|
||||
+ self.examples
|
||||
+ self.done
|
||||
+ self.repo
|
||||
+ self.readonly_files
|
||||
+ self.done
|
||||
+ self.chat_files
|
||||
+ self.cur
|
||||
+ self.reminder
|
||||
)
|
||||
|
||||
def add_cache_control_headers(self):
|
||||
if self.examples:
|
||||
self.add_cache_control(self.examples)
|
||||
else:
|
||||
self.add_cache_control(self.system)
|
||||
|
||||
if self.readonly_files:
|
||||
self.add_cache_control(self.readonly_files)
|
||||
else:
|
||||
self.add_cache_control(self.repo)
|
||||
|
||||
self.add_cache_control(self.chat_files)
|
||||
|
||||
def add_cache_control(self, messages):
|
||||
if not messages:
|
||||
return
|
||||
|
||||
content = messages[-1]
|
||||
if type(content) is str:
|
||||
content = dict(
|
||||
type="text",
|
||||
text=content,
|
||||
)
|
||||
content["cache_control"] = {"type": "ephemeral"}
|
||||
|
||||
|
||||
class Coder:
|
||||
abs_fnames = None
|
||||
|
@ -257,12 +282,12 @@ class Coder:
|
|||
total_cost=0.0,
|
||||
map_refresh="auto",
|
||||
cache_prompts=False,
|
||||
cache_prompts=False,
|
||||
):
|
||||
self.commit_before_message = []
|
||||
self.aider_commit_hashes = set()
|
||||
self.rejected_urls = set()
|
||||
self.abs_root_path_cache = {}
|
||||
self.cache_prompts = cache_prompts
|
||||
|
||||
if not fnames:
|
||||
fnames = []
|
||||
|
@ -991,6 +1016,9 @@ class Coder:
|
|||
|
||||
def format_messages(self):
|
||||
chunks = self.format_chat_chunks()
|
||||
if self.cache_prompts and self.main_model.cache_control:
|
||||
chunks.add_cache_control_headers()
|
||||
|
||||
return chunks.all_messages()
|
||||
|
||||
def send_message(self, inp):
|
||||
|
|
|
@ -74,7 +74,7 @@ class ModelSettings:
|
|||
examples_as_sys_msg: bool = False
|
||||
extra_headers: Optional[dict] = None
|
||||
max_tokens: Optional[int] = None
|
||||
cache_control_enabled: bool = False
|
||||
cache_control: bool = False
|
||||
|
||||
|
||||
# https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
|
||||
|
@ -274,6 +274,7 @@ MODEL_SETTINGS = [
|
|||
extra_headers={
|
||||
"anthropic-beta": ANTHROPIC_BETA_HEADER,
|
||||
},
|
||||
cache_control=True,
|
||||
),
|
||||
ModelSettings(
|
||||
"anthropic/claude-3-5-sonnet-20240620",
|
||||
|
@ -285,6 +286,7 @@ MODEL_SETTINGS = [
|
|||
extra_headers={
|
||||
"anthropic-beta": ANTHROPIC_BETA_HEADER,
|
||||
},
|
||||
cache_control=True,
|
||||
),
|
||||
ModelSettings(
|
||||
"openrouter/anthropic/claude-3.5-sonnet",
|
||||
|
@ -296,8 +298,8 @@ MODEL_SETTINGS = [
|
|||
max_tokens=8192,
|
||||
extra_headers={
|
||||
"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15",
|
||||
"HTTP-Referer": "https://aider.chat",
|
||||
"X-Title": "Aider",
|
||||
"HTTP-Referer": AIDER_SITE_URL,
|
||||
"X-Title": AIDER_APP_NAME,
|
||||
},
|
||||
),
|
||||
# Vertex AI Claude models
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue