Skip to content

Commit 7244fa2

Browse files
committed
Cache system prompt
1 parent a6b7c52 commit 7244fa2

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

plugins/chat.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,27 +336,30 @@ async def hey(self, ctx: commands.Context):
336336
model="claude-sonnet-4-5",
337337
max_tokens=2048,
338338
thinking={"type": "enabled", "budget_tokens": 1048},
339-
system=self.INITIAL_PROMPT.format(
340-
channel_name=ctx.channel.name,
341-
server_name=ctx.guild.name,
342-
date=now.strftime("%A, %d.%m.%Y"),
343-
time=now.strftime("%H:%M"),
344-
command_prefix=configuration["command_prefix"],
345-
bot_nickname=ctx.guild.me.display_name,
346-
),
339+
system=[
340+
{
341+
"type": "text",
342+
"text": self.INITIAL_PROMPT.format(
343+
channel_name=ctx.channel.name,
344+
server_name=ctx.guild.name,
345+
date=now.strftime("%A, %d.%m.%Y"),
346+
time=now.strftime("%H:%M"),
347+
command_prefix=configuration["command_prefix"],
348+
bot_nickname=ctx.guild.me.display_name,
349+
),
350+
"cache_control": {"type": "ephemeral", "ttl": "1h"},
351+
}
352+
],
347353
messages=prompt_messages,
348354
tools=self._all_available_commands_as_tools if iterations_left else [],
349355
)
350-
tool_calls = []
356+
tool_calls: list[anthropic.types.ToolUseBlock] = []
351357
full_text = ""
352358
prompt_messages.append({"role": "assistant", "content": response.content})
353359
for item in response.content:
354360
if item.type == "text":
355361
full_text += item.text
356362
if item.citations:
357-
full_text += "".join(
358-
f" ({md_link(urlsplit(c.url).netloc, c.url)})" for c in item.citations
359-
)
360363
elif item.type == "tool_use":
361364
tool_calls.append(item)
362365
elif item.type == "server_tool_use" and item.name == "web_search" and "query" in item.input:

0 commit comments

Comments
 (0)