From 98ca9166722654b303b5be5b3e8a2616803e5f06 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Tue, 22 Oct 2024 02:03:37 -0400 Subject: [PATCH 1/2] feat(deriver) Claude Caching --- src/deriver/voe.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/deriver/voe.py b/src/deriver/voe.py index 3635d9c..34ac693 100644 --- a/src/deriver/voe.py +++ b/src/deriver/voe.py @@ -47,6 +47,7 @@ async def tom_inference( { "type": "text", "text": "Hello there! I'm Claude, an AI assistant. I'm excited to explore what you could be thinking! To start, could you please provide the conversation and the representation of you if it exists?", + "cache_control": {"type": "emphemeral"}, } ], }, @@ -108,6 +109,7 @@ async def user_representation( { "type": "text", "text": "Hello there! I'm Claude, an AI assistant. I'm excited to explore how best to represent you! To start, could you please provide the conversation, the other instance's theory of mind prediction, and the representation of you if they exist?", + "cache_control": {"type": "emphemeral"}, } ], }, From 2661f52e5e507af22352c1109161c55d2171705a Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:33:21 -0400 Subject: [PATCH 2/2] Tested Deriver --- src/deriver/voe.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/deriver/voe.py b/src/deriver/voe.py index 34ac693..d2763e8 100644 --- a/src/deriver/voe.py +++ b/src/deriver/voe.py @@ -1,15 +1,15 @@ import os -from anthropic import AsyncAnthropic +from anthropic import Anthropic # Initialize the Anthropic client -anthropic = AsyncAnthropic(api_key=os.getenv("ANTHROPIC_API_KEY")) +anthropic = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY")) async def tom_inference( chat_history: str, session_id: str, user_representation: str = "None" ) -> str: - message = await anthropic.messages.create( + message = anthropic.beta.prompt_caching.messages.create( model="claude-3-5-sonnet-20240620", max_tokens=1000, temperature=0, @@ -47,7 +47,7 @@ async def tom_inference( { "type": "text", "text": "Hello there! I'm Claude, an AI assistant. I'm excited to explore what you could be thinking! To start, could you please provide the conversation and the representation of you if it exists?", - "cache_control": {"type": "emphemeral"}, + "cache_control": {"type": "ephemeral"}, } ], }, @@ -71,7 +71,7 @@ async def user_representation( user_representation: str = "None", tom_inference: str = "None", ) -> str: - message = await anthropic.messages.create( + message = anthropic.beta.prompt_caching.messages.create( model="claude-3-5-sonnet-20240620", max_tokens=1000, temperature=0, @@ -109,7 +109,7 @@ async def user_representation( { "type": "text", "text": "Hello there! I'm Claude, an AI assistant. I'm excited to explore how best to represent you! To start, could you please provide the conversation, the other instance's theory of mind prediction, and the representation of you if they exist?", - "cache_control": {"type": "emphemeral"}, + "cache_control": {"type": "ephemeral"}, } ], },