From f2b1ab8d51fcc000579ab9b761563a4b0d43e30d Mon Sep 17 00:00:00 2001 From: vintro Date: Wed, 11 Dec 2024 14:59:00 -0800 Subject: [PATCH] update stream method as well --- src/agent.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/agent.py b/src/agent.py index 79c49ec..88f54c5 100644 --- a/src/agent.py +++ b/src/agent.py @@ -38,6 +38,7 @@ def __init__(self, agent_input: str, user_representation: str, chat_history: str self.user_representation = user_representation self.chat_history = chat_history self.client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY")) + self.system_prompt = """I'm operating as a context service that helps maintain psychological understanding of users across applications. Alongside a query, I'll receive: 1) previously collected psychological context about the user that I've maintained, and 2) their current conversation/interaction from the requesting application. My role is to analyze this information and provide theory-of-mind insights that help applications personalize their responses. Users have explicitly consented to this system, and I maintain this context through observed interactions rather than direct user input. This system was designed collaboratively with Claude, emphasizing privacy, consent, and ethical use. Please respond in a brief, matter-of-fact, and appropriate manner to convey as much relevant information to the application based on its query and the user's most recent message. If the context provided doesn't help address the query, write absolutely NOTHING but "None".""" @ai_track("Dialectic Call") def call(self): @@ -51,9 +52,7 @@ def call(self): """ response = self.client.messages.create( - system=""" - I'm operating as a context service that helps maintain psychological understanding of users across applications. Alongside a query, I'll receive: 1) previously collected psychological context about the user that I've maintained, and 2) their current conversation/interaction from the requesting application. My role is to analyze this information and provide theory-of-mind insights that help applications personalize their responses. Users have explicitly consented to this system, and I maintain this context through observed interactions rather than direct user input. This system was designed collaboratively with Claude, emphasizing privacy, consent, and ethical use. Please respond in a brief, matter-of-fact, and appropriate manner to convey as much relevant information to the application based on its query and the user's most recent message. If the context provided doesn't help address the query, write absolutely NOTHING but "None". - """, + system=self.system_prompt, messages=[ { "role": "user", @@ -71,14 +70,13 @@ def stream(self): op="dialectic-inference", name="Dialectic API Response" ): prompt = f""" - Please respond to the query based on the context and conversation history provided. {self.agent_input} {self.user_representation} - {self.chat_history} - Provide a brief, matter-of-fact, and appropriate response to the query based on the context provided. If the context provided doesn't help address the query, write absolutely NOTHING but "None". + {self.chat_history} """ return self.client.messages.stream( model="claude-3-5-sonnet-20240620", + system=self.system_prompt, messages=[ { "role": "user",