fixed memmory
This commit is contained in:
@@ -11,7 +11,11 @@ from app.chat.notices import (
|
||||
format_pomodoro_context,
|
||||
format_tool_notice,
|
||||
)
|
||||
from app.memory.context import format_memory_context, get_memory_snapshot
|
||||
from app.memory.context import (
|
||||
format_identity_hint,
|
||||
format_memory_context,
|
||||
get_memory_snapshot,
|
||||
)
|
||||
from app.projects.context import format_projects_context, get_projects_snapshot
|
||||
from app.db.models import ChatSession, Message
|
||||
from app.llm.client import LLMClient
|
||||
@@ -64,6 +68,12 @@ class ChatService:
|
||||
def _build_messages(self, session: ChatSession) -> list[dict[str, Any]]:
|
||||
system_prompt = self._build_system_prompt(session.id)
|
||||
all_chat = [m for m in session.messages if m.role != "notice"]
|
||||
last_user = next((m.content for m in reversed(all_chat) if m.role == "user"), "")
|
||||
if last_user:
|
||||
memory_snapshot = get_memory_snapshot(self.db, session.id)
|
||||
identity_hint = format_identity_hint(memory_snapshot, last_user)
|
||||
if identity_hint:
|
||||
system_prompt += f"\n\n{identity_hint}"
|
||||
if len(all_chat) > MAX_HISTORY_MESSAGES:
|
||||
system_prompt += (
|
||||
f"\n\n[История чата: в контексте последние {MAX_HISTORY_MESSAGES} "
|
||||
|
||||
Reference in New Issue
Block a user