feat(frontend): 优化对话与管理页面展示体验
This commit is contained in:
@@ -2,6 +2,8 @@ from django import forms
|
||||
|
||||
|
||||
class ChatForm(forms.Form):
|
||||
# 该表单只负责收集用户问题和可选文档范围,
|
||||
# 不承载任何 Agent 业务逻辑,便于在 View 层保持轻量。
|
||||
message = forms.CharField(
|
||||
label="问题",
|
||||
max_length=4000,
|
||||
@@ -9,7 +11,12 @@ class ChatForm(forms.Form):
|
||||
"required": "请输入要咨询的问题。",
|
||||
"max_length": "问题过长,请控制在 4000 字以内。",
|
||||
},
|
||||
widget=forms.Textarea(attrs={"rows": 6}),
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"rows": 8,
|
||||
"placeholder": "例如:请结合已上传 SOP,分析当前异常的原因、风险等级和建议动作。",
|
||||
}
|
||||
),
|
||||
)
|
||||
document_ids = forms.MultipleChoiceField(
|
||||
label="文档范围",
|
||||
@@ -22,9 +29,12 @@ class ChatForm(forms.Form):
|
||||
def __init__(self, *args, documents=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
documents = documents or []
|
||||
# 仅允许选择当前场景且已完成入库的文档,
|
||||
# 避免前端把无效文件范围传入 Agent Core。
|
||||
self.fields["document_ids"].choices = [
|
||||
(str(document.id), document.original_name) for document in documents
|
||||
]
|
||||
|
||||
def clean_document_ids(self):
|
||||
# View 与 Agent Core 都使用整型文档 ID,统一在表单层完成转换。
|
||||
return [int(document_id) for document_id in self.cleaned_data.get("document_ids", [])]
|
||||
|
||||
Reference in New Issue
Block a user