Implement AI workspace and mitigation workflow

This commit is contained in:
2026-02-15 04:27:28 +00:00
parent de2b9a9bbb
commit 2d3b8fdac6
64 changed files with 7669 additions and 769 deletions

View File

@@ -1,18 +1,21 @@
from core.lib.prompts import bases
from asgiref.sync import sync_to_async
from core.models import Message, ChatSession, AI, Person, Manipulation
from core.util import logs
import json
import asyncio
from django.utils import timezone
import json
import random
from asgiref.sync import sync_to_async
from django.utils import timezone
from core.lib.prompts import bases
from core.models import AI, ChatSession, Manipulation, Message, Person
from core.util import logs
log = logs.get_logger("replies")
def should_reply(
reply_to_self,
reply_to_others,
is_outgoing_message,
reply_to_self,
reply_to_others,
is_outgoing_message,
):
reply = False
if reply_to_self:
@@ -26,7 +29,14 @@ def should_reply(
return reply
def generate_mutate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_history: str, mutate: bool = False):
def generate_mutate_reply_prompt(
msg: dict,
person: Person,
manip: Manipulation,
chat_history: str,
mutate: bool = False,
):
"""
Strictly rewrites the message in the personas tone and style
while keeping the original meaning. No added explanations.
@@ -66,16 +76,12 @@ def generate_mutate_reply_prompt(msg: dict, person: Person, manip: Manipulation,
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.)"
)
@@ -83,8 +89,13 @@ def generate_mutate_reply_prompt(msg: dict, person: Person, manip: Manipulation,
return [{"role": "system", "content": system_message}]
def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_history: str, mutate: bool = False):
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.
"""
@@ -108,7 +119,6 @@ def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_h
"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"
@@ -119,7 +129,6 @@ def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_h
f"- **Response Tactics:** {persona.response_tactics}\n"
f"- **Persuasion Techniques:** {persona.persuasion_tactics}\n"
f"- **Boundaries:** {persona.boundaries} | **Adaptability:** {persona.adaptability}%\n\n"
"### Contact Information ###\n"
f"- **Summary:** {person.summary or 'N/A'}\n"
f"- **Profile:** {person.profile or 'N/A'}\n"
@@ -128,7 +137,6 @@ def generate_reply_prompt(msg: dict, person: Person, manip: Manipulation, chat_h
f"- **Timezone:** {person.timezone or 'N/A'}\n"
f"- **Last Interaction:** {person.last_interaction or 'Never'}\n"
f"- **Current Date/Time:** {now}\n\n"
"### Conversation Context ###\n"
f"{chat_history if chat_history else 'No prior chat history.'}\n\n"
)