Increase platform abstraction cohesion
This commit is contained in:
@@ -14,6 +14,7 @@ from django.views import View
|
||||
|
||||
from core.forms import AIWorkspaceWindowForm
|
||||
from core.lib.notify import raw_sendmsg
|
||||
from core.memory.retrieval import retrieve_memories_for_prompt
|
||||
from core.messaging import ai as ai_runner
|
||||
from core.messaging.utils import messages_to_string
|
||||
from core.models import (
|
||||
@@ -3936,8 +3937,27 @@ class AIWorkspaceRunOperation(LoginRequiredMixin, View):
|
||||
)
|
||||
return rows
|
||||
|
||||
def _build_prompt(self, operation, owner_name, person, transcript, user_notes):
|
||||
def _build_prompt(
|
||||
self,
|
||||
operation,
|
||||
owner_name,
|
||||
person,
|
||||
transcript,
|
||||
user_notes,
|
||||
memory_context,
|
||||
):
|
||||
notes = (user_notes or "").strip()
|
||||
memory_lines = []
|
||||
for index, item in enumerate(memory_context or [], start=1):
|
||||
content = item.get("content") or {}
|
||||
text = str(content.get("text") or "").strip()
|
||||
if not text:
|
||||
text = str(content).strip()
|
||||
if not text:
|
||||
continue
|
||||
kind = str(item.get("memory_kind") or "fact")
|
||||
memory_lines.append(f"{index}. [{kind}] {text}")
|
||||
memory_text = "\n".join(memory_lines) if memory_lines else "None"
|
||||
if operation == "draft_reply":
|
||||
instruction = (
|
||||
"Generate 3 concise reply options in different tones: soft, neutral, firm. "
|
||||
@@ -3965,6 +3985,8 @@ class AIWorkspaceRunOperation(LoginRequiredMixin, View):
|
||||
f"Owner: {owner_name}\n"
|
||||
f"Person: {person.name}\n"
|
||||
f"Notes: {notes or 'None'}\n\n"
|
||||
"Approved Memory Context:\n"
|
||||
f"{memory_text}\n\n"
|
||||
f"Conversation:\n{transcript}"
|
||||
),
|
||||
},
|
||||
@@ -4111,12 +4133,20 @@ class AIWorkspaceRunOperation(LoginRequiredMixin, View):
|
||||
)
|
||||
|
||||
try:
|
||||
memory_context = retrieve_memories_for_prompt(
|
||||
user_id=request.user.id,
|
||||
person_id=str(person.id),
|
||||
conversation_id=str(conversation.id),
|
||||
statuses=("active",),
|
||||
limit=12,
|
||||
)
|
||||
prompt = self._build_prompt(
|
||||
operation=operation,
|
||||
owner_name=owner_name,
|
||||
person=person,
|
||||
transcript=transcript,
|
||||
user_notes=user_notes,
|
||||
memory_context=memory_context,
|
||||
)
|
||||
result_text = async_to_sync(ai_runner.run_prompt)(prompt, ai_obj)
|
||||
draft_options = (
|
||||
|
||||
Reference in New Issue
Block a user