feat(chat): 打通场景对话与结果展示

This commit is contained in:
2026-05-30 00:10:47 +08:00
parent 5c9718ddb1
commit ba3f5fc584
7 changed files with 224 additions and 0 deletions

30
apps/chat/forms.py Normal file
View File

@@ -0,0 +1,30 @@
from django import forms
class ChatForm(forms.Form):
message = forms.CharField(
label="问题",
max_length=4000,
error_messages={
"required": "请输入要咨询的问题。",
"max_length": "问题过长,请控制在 4000 字以内。",
},
widget=forms.Textarea(attrs={"rows": 6}),
)
document_ids = forms.MultipleChoiceField(
label="文档范围",
required=False,
choices=(),
widget=forms.CheckboxSelectMultiple,
error_messages={"invalid_choice": "请选择当前场景下已入库的文档。"},
)
def __init__(self, *args, documents=None, **kwargs):
super().__init__(*args, **kwargs)
documents = documents or []
self.fields["document_ids"].choices = [
(str(document.id), document.original_name) for document in documents
]
def clean_document_ids(self):
return [int(document_id) for document_id in self.cleaned_data.get("document_ids", [])]