|
11 | 11 | from typing import Dict |
12 | 12 |
|
13 | 13 | import uuid_utils.compat as uuid |
14 | | -from application.models import Application, ApplicationAccessToken, ChatRecord |
| 14 | +from application.models import Application, ApplicationAccessToken, ChatRecord, Chat |
15 | 15 | from application.serializers.application_chat import ChatCountSerializer |
16 | 16 | from application.serializers.common import ChatInfo |
17 | 17 | from common.auth.authentication import get_is_permissions |
@@ -71,7 +71,7 @@ def is_valid(self, *, debug=False, raise_exception=False): |
71 | 71 | if not query_set.exists(): |
72 | 72 | raise AppApiException(500, _("Application id does not exist")) |
73 | 73 | 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") |
75 | 75 | ).exists() and not debug: |
76 | 76 | raise AppApiException(500, _("Chat records for the application do not exist")) |
77 | 77 | application_access_token = ( |
@@ -126,8 +126,8 @@ def is_valid(self, *, raise_exception=False): |
126 | 126 | query_set = query_set.filter(workspace_id=workspace_id) |
127 | 127 | if not query_set.exists(): |
128 | 128 | 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") |
131 | 131 | ).exists(): |
132 | 132 | raise AppApiException(500, _("Chat records for the application do not exist")) |
133 | 133 |
|
@@ -157,8 +157,8 @@ def reset_chat_record(chat_record, show_source, show_exec): |
157 | 157 | knowledge_list = [] |
158 | 158 | paragraph_list = [] |
159 | 159 | 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 |
162 | 162 | ): |
163 | 163 | paragraph_list = chat_record.details.get("search_step").get("paragraph_list") |
164 | 164 |
|
@@ -316,7 +316,7 @@ def is_valid(self, *, raise_exception=False): |
316 | 316 | if not Document.objects.filter(id=self.data["document_id"], knowledge_id=self.data["knowledge_id"]).exists(): |
317 | 317 | raise AppApiException(500, gettext("The document id is incorrect")) |
318 | 318 | 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"] |
320 | 320 | ).exists(): |
321 | 321 | raise AppApiException(500, gettext("The chat id is incorrect")) |
322 | 322 |
|
@@ -452,9 +452,9 @@ def is_valid(self, *, raise_exception=False): |
452 | 452 | raise AppApiException(500, _("Knowledge id does not exist")) |
453 | 453 |
|
454 | 454 | 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() |
458 | 458 | ): |
459 | 459 | raise AppApiException(500, gettext("The document id is incorrect")) |
460 | 460 |
|
@@ -499,8 +499,9 @@ def improve(self, instance: Dict, request=None, scope="WORKSPACE", with_valid=Tr |
499 | 499 | document_id = self.data.get("document_id") |
500 | 500 | knowledge_id = self.data.get("knowledge_id") |
501 | 501 | 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 |
504 | 505 | ) |
505 | 506 | paragraph = Paragraph( |
506 | 507 | id=uuid.uuid7(), |
|
0 commit comments