Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions apps/application/serializers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def resolve_chat_user(chat_user_id, chat_user_type, asker=None):
if asker:
if isinstance(asker, dict):
return asker
return {"username": asker}
return {"username": "游客"}
return {"username": asker, "id": str(chat_user_id)}
return {"username": "游客", "id": str(chat_user_id)}


def resolve_chat_user_group(chat_user):
Expand Down Expand Up @@ -390,33 +390,16 @@ def save_chat(self):
).save()

def set_chat_variable(self, chat_context):
if not self.debug:
chat = QuerySet(Chat).filter(id=self.chat_id).first()
if chat:
chat.meta = {**(chat.meta if isinstance(chat.meta, dict) else {}), **chat_context}
chat.save()
else:
cache.set(
Cache_Version.CHAT_VARIABLE.get_key(key=self.chat_id),
chat_context,
version=Cache_Version.CHAT_VARIABLE.get_version(),
timeout=60 * 30,
)
chat = QuerySet(Chat).filter(id=self.chat_id).first()
if chat:
chat.meta = {**(chat.meta if isinstance(chat.meta, dict) else {}), **chat_context}
chat.save()

def get_chat_variable(self):
if not self.debug:
chat = QuerySet(Chat).filter(id=self.chat_id).first()
if chat:
return chat.meta
return {}
else:
return (
cache.get(
Cache_Version.CHAT_VARIABLE.get_key(key=self.chat_id),
version=Cache_Version.CHAT_VARIABLE.get_version(),
)
or {}
)
chat = QuerySet(Chat).filter(id=self.chat_id).first()
if chat:
return chat.meta
return {}

def append_chat_record(self, chat_record: ChatRecord):
chat_record.problem_text = chat_record.problem_text[0:10240] if chat_record.problem_text is not None else ""
Expand Down
1 change: 1 addition & 0 deletions apps/application/workflow/content_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class ContentType(Enum):
TEXT = "TEXT"
HTML = "HTML"
REASONING = "REASONING"
FAILURE = "FAILURE"
TOOL = "TOOL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
from typing import Dict, Type, Optional

from application.workflow.message.aggregator.content_aggregator import ContentAggregator
from application.workflow.message.aggregator.impl import FormAggregator
from application.workflow.message.aggregator.impl import FormAggregator, HtmlAggregator
from application.workflow.message.aggregator.impl.reasoning_aggregator import ReasoningAggregator
from application.workflow.message.aggregator.impl.text_aggregator import TextAggregator
from application.workflow.message.aggregator.impl.tool_aggregator import ToolAggregator
from application.workflow.message.struct.content import Content
from application.workflow.message.struct.form_content import FormContent
from application.workflow.message.struct.html_content import HtmlContent
from application.workflow.message.struct.reasoning_content import ReasoningContent
from application.workflow.message.struct.text_content import TextContent
from application.workflow.message.struct.tool_content import ToolContent
Expand All @@ -31,6 +32,7 @@ class AggregatorFactory:
ReasoningContent: ReasoningAggregator(),
ToolContent: ToolAggregator(),
FormContent: FormAggregator(),
HtmlContent: HtmlAggregator(),
}

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
from application.workflow.message.aggregator.impl.reasoning_aggregator import ReasoningAggregator
from application.workflow.message.aggregator.impl.tool_aggregator import ToolAggregator
from application.workflow.message.aggregator.impl.form_aggregator import FormAggregator
from application.workflow.message.aggregator.impl.html_aggregator import HtmlAggregator

__all__ = ["TextAggregator", "ReasoningAggregator", "ToolAggregator", "FormAggregator"]
__all__ = ["TextAggregator", "ReasoningAggregator", "ToolAggregator", "FormAggregator", "HtmlAggregator"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8
"""
@project: MaxKB
@file: html_aggregator.py
@date:2026/10/16
@desc: HtmlContent 聚合器
"""

from application.workflow.message.aggregator.content_aggregator import ContentAggregator
from application.workflow.message.struct.html_content import HtmlContent


class HtmlAggregator(ContentAggregator[HtmlContent]):
"""
HTML 内容聚合器
与文本一致,按顺序拼接内容块
"""

def aggregate(self, prev: HtmlContent, chunk: HtmlContent) -> HtmlContent:
if prev is None:
return chunk
return HtmlContent(
chunk.id or prev.id,
(prev.content or "") + (chunk.content or ""),
chunk.status or prev.status,
chunk.node_info or prev.node_info,
chunk.position or prev.position,
)
22 changes: 22 additions & 0 deletions apps/application/workflow/message/struct/html_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# coding=utf-8
"""
@project: MaxKB
@file: html_content.py
@date:2026/10/16
@desc: HTML 内容,前端净化后渲染
"""

from application.workflow.content_type import ContentType
from application.workflow.message.struct.content import Content, NodeInfo, Position
from application.workflow.status import Status


class HtmlContent(Content):
def __init__(self, _id, content: str, status: Status, node_info: NodeInfo, position: Position, **kwargs):
self.content = content
super().__init__(_id, status, ContentType.HTML, node_info, position, **kwargs)

def to_dict(self):
result = super().to_dict()
result["content"] = self.content
return result
10 changes: 10 additions & 0 deletions apps/application/workflow/nodes/llm_node/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# coding=utf-8
"""
@project: MaxKB
@Author:虎虎虎
@file: __init__.py
@date:2026/10/16
@desc:
"""

from .llm_node import LLMNode
Loading
Loading