Add filter
This commit is contained in:
@@ -7,6 +7,8 @@ import asyncio
|
||||
from django.utils import timezone
|
||||
import random
|
||||
|
||||
log = logs.get_logger("replies")
|
||||
|
||||
def should_reply(
|
||||
reply_to_self,
|
||||
reply_to_others,
|
||||
@@ -24,7 +26,65 @@ def should_reply(
|
||||
|
||||
return reply
|
||||
|
||||
def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_history: str):
|
||||
def generate_mutate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_history: str, mutate: bool = False):
|
||||
"""
|
||||
Strictly rewrites the message in the persona’s tone and style
|
||||
while keeping the original meaning. No added explanations.
|
||||
"""
|
||||
|
||||
persona = manip.persona
|
||||
|
||||
# 🔹 **Strict Rules to Prevent AI from Adding Commentary**
|
||||
strict_rules = (
|
||||
"- **DO NOT add explanations, comments, or meta-thoughts**.\n"
|
||||
"- **DO NOT return multiple responses—return ONLY the rewritten message**.\n"
|
||||
"- **DO NOT change the meaning, intent, or facts in the message**.\n"
|
||||
"- **DO NOT soften insults unless the persona naturally would**.\n"
|
||||
"- **DO NOT reframe as a question or suggestion—this is NOT a conversation**.\n"
|
||||
"- **Rewrite as if the original sender wrote it this way, without extra commentary**.\n"
|
||||
"- **Start immediately with the rewritten message—NO preface, intro, or context.**\n"
|
||||
)
|
||||
|
||||
# 🔹 **What the AI SHOULD do**
|
||||
transformation_guidelines = (
|
||||
"- **Rewrite the message in the persona’s unique tone and style**.\n"
|
||||
"- **If the message is rude or harsh, reword it to match the persona’s confidence, cleverness, or wit**.\n"
|
||||
"- **If the persona is sarcastic, teasing, or flirty, maintain that energy**.\n"
|
||||
"- **Ensure the message feels natural, as if originally written that way**.\n"
|
||||
"- **Preserve original sentence structure as much as possible, adjusting only for flow.**\n"
|
||||
)
|
||||
|
||||
system_message = (
|
||||
"You are a text rewriter. Your task is to transform messages into a given persona’s unique style, "
|
||||
"while keeping the original meaning intact.\n\n"
|
||||
"### Persona Profile ###\n"
|
||||
f"- **Tone:** {persona.tone} | **Humor:** {persona.humor_style}\n"
|
||||
f"- **Core Values:** {persona.core_values}\n"
|
||||
f"- **Communication Style:** {persona.communication_style}\n"
|
||||
f"- **Flirting Style:** {persona.flirting_style}\n"
|
||||
f"- **Likes:** {persona.likes} | **Dislikes:** {persona.dislikes}\n"
|
||||
f"- **Response Tactics:** {persona.response_tactics}\n"
|
||||
f"- **Persuasion Techniques:** {persona.persuasion_tactics}\n"
|
||||
f"- **Boundaries:** {persona.boundaries} | **Adaptability:** {persona.adaptability}%\n\n"
|
||||
|
||||
"### STRICT RULES ###\n"
|
||||
f"{strict_rules}\n\n"
|
||||
|
||||
"### TRANSFORMATION GUIDELINES ###\n"
|
||||
f"{transformation_guidelines}\n\n"
|
||||
|
||||
"### Original Message ###\n"
|
||||
f"{msg}\n\n"
|
||||
|
||||
"### Rewritten Message ###\n"
|
||||
"(DO NOT include anything except the rewritten text. NO extra comments or formatting.)"
|
||||
)
|
||||
|
||||
return [{"role": "system", "content": system_message}]
|
||||
|
||||
|
||||
|
||||
def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_history: str, mutate: bool = False):
|
||||
"""
|
||||
Generate a structured prompt using the attributes of the provided Person and Manipulation models.
|
||||
"""
|
||||
@@ -32,9 +92,23 @@ def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_h
|
||||
now = timezone.now()
|
||||
persona = manip.persona
|
||||
|
||||
# 🔹 Define system instructions for filtering messages
|
||||
filter_rules = (
|
||||
"- **Strict Filtering**: If the message includes topics that are in dislikes or boundaries, "
|
||||
"modify or reject them completely to match the persona's values.\n"
|
||||
"- **Rephrase Sensitively**: If the message contains something the persona dislikes but is not "
|
||||
"a strict boundary, soften it or remove the negative elements.\n"
|
||||
"- **Enforce Persona Style**: Modify the tone, humor, and engagement level based on the persona's "
|
||||
"communication style.\n"
|
||||
"- **Never Ask for Clarifications**: Always modify the message directly without requesting clarification.\n"
|
||||
"- **Return Only the Modified Message**: Do not add any explanations or metadata.\n"
|
||||
)
|
||||
|
||||
system_message = (
|
||||
"You are my digital persona, responding on my behalf while embodying my personality, preferences, and unique style.\n\n"
|
||||
|
||||
"You must strictly apply the following persona-based filtering rules when modifying the message:\n\n"
|
||||
f"{filter_rules}\n\n"
|
||||
|
||||
"### Persona Profile ###\n"
|
||||
f"- **MBTI:** {persona.mbti} ({persona.mbti_identity} balance)\n"
|
||||
f"- **Tone:** {persona.tone} | **Humor:** {persona.humor_style}\n"
|
||||
@@ -57,19 +131,19 @@ def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_h
|
||||
|
||||
"### Conversation Context ###\n"
|
||||
f"{chat_history if chat_history else 'No prior chat history.'}\n\n"
|
||||
|
||||
"### Response Guidelines ###\n"
|
||||
"- **Engagement**: Keep responses engaging, with a balance of wit, depth, and confidence.\n"
|
||||
"- **Flirting**: Be direct, playful, and, when appropriate, subtly provocative—without hesitation.\n"
|
||||
"- **Pauses**: Use double newlines (`\\n\\n`) to pause where it enhances realism.\n"
|
||||
"- **Flow Awareness**: Maintain continuity, avoid redundancy, and adjust response length based on interaction.\n"
|
||||
)
|
||||
|
||||
user_message = f"[{msg['timestamp']}] <{person.name}> {msg['text']}"
|
||||
if not mutate:
|
||||
user_message = f"[{msg['timestamp']}] <{person.name}> {msg['text']}"
|
||||
log.info(f"User message: {user_message}")
|
||||
|
||||
return [
|
||||
{"role": "system", "content": system_message},
|
||||
{"role": "user", "content": user_message},
|
||||
]
|
||||
|
||||
|
||||
return [
|
||||
{"role": "system", "content": system_message},
|
||||
{"role": "user", "content": user_message},
|
||||
]
|
||||
else:
|
||||
user_message = f"Message to amend: {msg}"
|
||||
return [
|
||||
{"role": "system", "content": system_message},
|
||||
{"role": "user", "content": user_message},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user