From 6e0dd4a779615774c69ad73e1f017dbd94ab84e6 Mon Sep 17 00:00:00 2001 From: Kwindla Hultman Kramer Date: Thu, 15 Aug 2024 00:54:43 -0700 Subject: [PATCH] Anthropic beta prompt caching --- .../foundational/19b-tools-video-anthropic.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/foundational/19b-tools-video-anthropic.py b/examples/foundational/19b-tools-video-anthropic.py index 4ba29ab37..26d466e9e 100644 --- a/examples/foundational/19b-tools-video-anthropic.py +++ b/examples/foundational/19b-tools-video-anthropic.py @@ -77,7 +77,8 @@ async def main(): llm = AnthropicLLMService( api_key=os.getenv("ANTHROPIC_API_KEY"), - model="claude-3-5-sonnet-20240620" + model="claude-3-5-sonnet-20240620", + enable_prompt_caching_beta=True ) llm.register_function("get_weather", get_weather) llm.register_function("get_image", get_image) @@ -136,10 +137,20 @@ indicate you should use the get_image tool are: If you need to use a tool, simply use the tool. Do not tell the user the tool you are using. Be brief and concise. """ - messages = [{"role": "system", - "content": system_prompt}, - {"role": "user", - "content": "Start the conversation by introducing yourself."}] + messages = [ + { + "role": "system", + "content": [ + { + "type": "text", + "text": system_prompt, + } + ] + }, + { + "role": "user", + "content": "Start the conversation by introducing yourself." + }] context = OpenAILLMContext(messages, tools) context_aggregator = llm.create_context_aggregator(context)