Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt Caching in Deriver #75

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/deriver/voe.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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": "ephemeral"},
}
],
},
Expand All @@ -70,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,
Expand Down Expand Up @@ -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": "ephemeral"},
}
],
},
Expand Down