Skip to content

Commit 951503f

Browse files
authored
fix: Conversation log verification error (#7295)
1 parent c53a9b7 commit 951503f

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎apps/application/serializers/application_chat_record.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Dict
1212

1313
import uuid_utils.compat as uuid
14-
from application.models import Application, ApplicationAccessToken, ChatRecord
14+
from application.models import Application, ApplicationAccessToken, ChatRecord, Chat
1515
from application.serializers.application_chat import ChatCountSerializer
1616
from application.serializers.common import ChatInfo
1717
from common.auth.authentication import get_is_permissions
@@ -71,7 +71,7 @@ def is_valid(self, *, debug=False, raise_exception=False):
7171
if not query_set.exists():
7272
raise AppApiException(500, _("Application id does not exist"))
7373
if not ChatRecord.objects.filter(
74-
chat_id=self.data.get("chat_id"), chat__application_id=self.data.get("application_id")
74+
chat_id=self.data.get("chat_id"), chat__application_id=self.data.get("application_id")
7575
).exists() and not debug:
7676
raise AppApiException(500, _("Chat records for the application do not exist"))
7777
application_access_token = (
@@ -126,8 +126,8 @@ def is_valid(self, *, raise_exception=False):
126126
query_set = query_set.filter(workspace_id=workspace_id)
127127
if not query_set.exists():
128128
raise AppApiException(500, _("Application id does not exist"))
129-
if not ChatRecord.objects.filter(
130-
chat_id=self.data.get("chat_id"), chat__application_id=self.data.get("application_id")
129+
if not Chat.objects.filter(
130+
id=self.data.get("chat_id"), application_id=self.data.get("application_id")
131131
).exists():
132132
raise AppApiException(500, _("Chat records for the application do not exist"))
133133

@@ -157,8 +157,8 @@ def reset_chat_record(chat_record, show_source, show_exec):
157157
knowledge_list = []
158158
paragraph_list = []
159159
if (
160-
"search_step" in chat_record.details
161-
and chat_record.details.get("search_step").get("paragraph_list") is not None
160+
"search_step" in chat_record.details
161+
and chat_record.details.get("search_step").get("paragraph_list") is not None
162162
):
163163
paragraph_list = chat_record.details.get("search_step").get("paragraph_list")
164164

@@ -316,7 +316,7 @@ def is_valid(self, *, raise_exception=False):
316316
if not Document.objects.filter(id=self.data["document_id"], knowledge_id=self.data["knowledge_id"]).exists():
317317
raise AppApiException(500, gettext("The document id is incorrect"))
318318
if not ChatRecord.objects.filter(
319-
chat_id__in=self.data["chat_ids"], chat__application_id=self.data["application_id"]
319+
chat_id__in=self.data["chat_ids"], chat__application_id=self.data["application_id"]
320320
).exists():
321321
raise AppApiException(500, gettext("The chat id is incorrect"))
322322

@@ -452,9 +452,9 @@ def is_valid(self, *, raise_exception=False):
452452
raise AppApiException(500, _("Knowledge id does not exist"))
453453

454454
if (
455-
not QuerySet(Document)
456-
.filter(id=self.data.get("document_id"), knowledge_id=self.data.get("knowledge_id"))
457-
.exists()
455+
not QuerySet(Document)
456+
.filter(id=self.data.get("document_id"), knowledge_id=self.data.get("knowledge_id"))
457+
.exists()
458458
):
459459
raise AppApiException(500, gettext("The document id is incorrect"))
460460

@@ -499,8 +499,9 @@ def improve(self, instance: Dict, request=None, scope="WORKSPACE", with_valid=Tr
499499
document_id = self.data.get("document_id")
500500
knowledge_id = self.data.get("knowledge_id")
501501
max_position = (
502-
Paragraph.objects.filter(document_id=document_id).aggregate(max_position=Max("position"))["max_position"]
503-
or 0
502+
Paragraph.objects.filter(document_id=document_id).aggregate(max_position=Max("position"))[
503+
"max_position"]
504+
or 0
504505
)
505506
paragraph = Paragraph(
506507
id=uuid.uuid7(),

0 commit comments

Comments
 (0)