Vince/sf prompting changes (#81)

* fix representation and dialectic prompts

* update stream method as well
This commit is contained in:
vintro 2024-12-15 19:12:09 -08:00 committed by GitHub
parent 57ef19315e
commit 6995f878a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 15 deletions

View File

@ -38,6 +38,7 @@ class Dialectic:
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):
@ -45,14 +46,13 @@ class Dialectic:
op="dialectic-inference", name="Dialectic API Response"
):
prompt = f"""
You are tasked with responding to the query based on the context provided.
<query>{self.agent_input}</query>
<context>{self.user_representation}</context>
<conversation_history>{self.chat_history}</conversation_history>
Provide a brief, matter-of-fact, and appropriate response to the query based on the context provided. If the context provided doesn't aid in addressing the query, return only the word "None".
"""
response = self.client.messages.create(
system=self.system_prompt,
messages=[
{
"role": "user",
@ -60,31 +60,30 @@ class Dialectic:
}
],
model="claude-3-5-sonnet-20240620",
max_tokens=300,
max_tokens=150,
)
return response.content
@ai_track("Dialectic Call")
def stream(self):
with sentry_sdk.start_transaction(
op="dialectic-inference", name="Dialect API Response"
op="dialectic-inference", name="Dialectic API Response"
):
prompt = f"""
You are tasked with responding to the query based on the context provided.
<query>{self.agent_input}</query>
<context>{self.user_representation}</context>
<conversation_history>{self.chat_history}</conversation_history>
Provide a brief, matter-of-fact, and appropriate response to the query based on the context provided. If the context provided doesn't aid in addressing the query, return only the word "None".
<conversation_history>{self.chat_history}</conversation_history>
"""
return self.client.messages.stream(
model="claude-3-5-sonnet-20241022",
model="claude-3-5-sonnet-20240620",
system=self.system_prompt,
messages=[
{
"role": "user",
"content": prompt,
}
],
max_tokens=300,
max_tokens=150,
)

View File

@ -60,7 +60,7 @@ async def process_ai_message(
"""
Process an AI message. Make a prediction about what the user is going to say to it.
"""
console.print(f"Processing AI message: {content}", style="green")
console.print(f"Processing AI message: {content}", style="bright_magenta")
subquery = (
select(models.Message.id)
@ -136,7 +136,7 @@ async def process_user_message(
ai_message = response.scalar_one_or_none()
if ai_message and ai_message.content:
console.print(f"AI Message: {ai_message.content}", style="orange1")
console.print(f"AI Message: {ai_message.content}", style="bright_magenta")
# Fetch the tom_inference metamessage
tom_inference_stmt = (
@ -153,7 +153,7 @@ async def process_user_message(
if tom_inference_metamessage and tom_inference_metamessage.content:
console.print(
f"Tom Inference: {tom_inference_metamessage.content}", style="orange1"
f"Tom Inference: {tom_inference_metamessage.content}", style="blue"
)
# Fetch the latest user representation
@ -204,8 +204,7 @@ async def process_user_message(
user_representation_response, "representation"
)
console.print("User Representation:", style="bright_magenta")
console.print(user_representation_response, style="bright_magenta")
console.print(f"User Representation:\n{user_representation_response}", style="bright_green")
else:
raise Exception(

File diff suppressed because one or more lines are too long