Skip to content

Commit 3aa5dd3

Browse files
authored
feat: The demonstration page supports modifying dialogue summaries (#2348)
1 parent 5a3acc8 commit 3aa5dd3

File tree

17 files changed

+273
-32
lines changed

17 files changed

+273
-32
lines changed

apps/application/serializers/chat_serializers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def valid_model_params_setting(model_id, model_params_setting):
6666
credential.get_model_params_setting_form(model.model_name).valid_form(model_params_setting)
6767

6868

69+
class ReAbstractInstanceSerializers(serializers.Serializer):
70+
abstract = serializers.CharField(required=True, error_messages=ErrMessage.char(_("abstract")))
71+
72+
6973
class ChatSerializers(serializers.Serializer):
7074
class Operate(serializers.Serializer):
7175
chat_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid(_("Conversation ID")))
@@ -78,6 +82,15 @@ def logic_delete(self, with_valid=True):
7882
is_deleted=True)
7983
return True
8084

85+
def re_abstract(self, instance, with_valid=True):
86+
if with_valid:
87+
self.is_valid(raise_exception=True)
88+
ReAbstractInstanceSerializers(data=instance).is_valid(raise_exception=True)
89+
90+
QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id')).update(
91+
abstract=instance.get('abstract'))
92+
return True
93+
8194
def delete(self, with_valid=True):
8295
if with_valid:
8396
self.is_valid(raise_exception=True)

apps/application/swagger_api/chat_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ def get_request_params_api():
2323
description=_('Application ID'))
2424
]
2525

26+
class Operate(ApiMixin):
27+
@staticmethod
28+
def get_request_params_api():
29+
return [openapi.Parameter(name='application_id',
30+
in_=openapi.IN_PATH,
31+
type=openapi.TYPE_STRING,
32+
required=True,
33+
description=_('Application ID')),
34+
openapi.Parameter(name='chat_id',
35+
in_=openapi.IN_PATH,
36+
type=openapi.TYPE_STRING,
37+
required=True,
38+
description=_('Conversation ID')),
39+
]
40+
41+
class ReAbstract(ApiMixin):
42+
@staticmethod
43+
def get_request_body_api():
44+
return openapi.Schema(
45+
type=openapi.TYPE_OBJECT,
46+
required=['abstract'],
47+
properties={
48+
'abstract': openapi.Schema(type=openapi.TYPE_STRING, title=_("abstract"),
49+
description=_("abstract"))
50+
51+
}
52+
)
53+
2654

2755
class OpenAIChatApi(ApiMixin):
2856
@staticmethod

apps/application/views/chat_views.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def post(self, request: Request, chat_id: str):
150150
operation_id=_("Get the conversation list"),
151151
manual_parameters=ChatApi.get_request_params_api(),
152152
responses=result.get_api_array_response(ChatApi.get_response_body_api()),
153-
tags=[_("Application/Conversation Log")]
153+
tags=[_("Application/Conversation Log")]
154154
)
155155
@has_permissions(
156156
ViewPermission([RoleConstants.ADMIN, RoleConstants.USER, RoleConstants.APPLICATION_KEY],
@@ -222,6 +222,23 @@ def delete(self, request: Request, application_id: str, chat_id: str):
222222
data={'application_id': application_id, 'user_id': request.user.id,
223223
'chat_id': chat_id}).logic_delete())
224224

225+
@action(methods=['PUT'], detail=False)
226+
@swagger_auto_schema(operation_summary=_("Client modifies dialogue summary"),
227+
operation_id=_("Client modifies dialogue summary"),
228+
request_body=ChatClientHistoryApi.Operate.ReAbstract.get_request_body_api(),
229+
tags=[_("Application/Conversation Log")])
230+
@has_permissions(ViewPermission(
231+
[RoleConstants.APPLICATION_ACCESS_TOKEN],
232+
[lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.USE,
233+
dynamic_tag=keywords.get('application_id'))],
234+
compare=CompareConstants.AND),
235+
compare=CompareConstants.AND)
236+
def put(self, request: Request, application_id: str, chat_id: str):
237+
return result.success(
238+
ChatSerializers.Operate(
239+
data={'application_id': application_id, 'user_id': request.user.id,
240+
'chat_id': chat_id}).re_abstract(request.data))
241+
225242
class Page(APIView):
226243
authentication_classes = [TokenAuth]
227244

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6753,3 +6753,5 @@ msgstr ""
67536753
msgid "Image download failed, check network"
67546754
msgstr ""
67556755

6756+
msgid "Client modifies dialogue summary"
6757+
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6892,4 +6892,5 @@ msgstr "超出许可证使用限制。"
68926892
msgid "Image download failed, check network"
68936893
msgstr "图片下载失败,请检查网络"
68946894

6895-
6895+
msgid "Client modifies dialogue summary"
6896+
msgstr "客户端修改对话摘要"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6902,4 +6902,7 @@ msgid "License usage limit exceeded."
69026902
msgstr "超出許可證使用限制。"
69036903

69046904
msgid "Image download failed, check network"
6905-
msgstr "圖片下載失敗,檢查網絡"
6905+
msgstr "圖片下載失敗,檢查網絡"
6906+
6907+
msgid "Client modifies dialogue summary"
6908+
msgstr "用戶端修改對話摘要"

ui/src/api/log.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,29 @@ const delChatClientLog: (
220220
return del(`${prefix}/${application_id}/chat/client/${chat_id}`, undefined, {}, loading)
221221
}
222222

223+
/**
224+
* 修改历史日志abstract
225+
* @param 参数
226+
* application_id, chat_id,
227+
* data {
228+
"abstract": "string",
229+
}
230+
*/
231+
232+
const putChatClientLog: (
233+
application_id: string,
234+
chat_id: string,
235+
data: any,
236+
loading?: Ref<boolean>
237+
) => Promise<Result<boolean>> = (application_id, chat_id, data, loading) => {
238+
return put(
239+
`${prefix}/${application_id}/chat/client/${chat_id}`,
240+
data,
241+
undefined,
242+
loading
243+
)
244+
}
245+
223246
export default {
224247
getChatLog,
225248
delChatLog,
@@ -231,5 +254,6 @@ export default {
231254
exportChatLog,
232255
getChatLogClient,
233256
delChatClientLog,
234-
postChatRecordLog
257+
postChatRecordLog,
258+
putChatClientLog
235259
}

ui/src/components/ai-chat/ExecutionDetailDialog.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-dialog
3-
class="execution-details-dialog"
3+
class="execution-details-dialog responsive-dialog"
44
:title="$t('chat.executionDetails.title')"
55
v-model="dialogVisible"
66
destroy-on-close
@@ -697,9 +697,5 @@ defineExpose({ open })
697697
}
698698
}
699699
700-
@media only screen and (max-width: 768px) {
701-
.execution-details-dialog {
702-
width: 90% !important;
703-
}
704-
}
700+
705701
</style>

ui/src/components/ai-chat/ParagraphSourceDialog.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<el-dialog
3-
class="paragraph-source"
3+
class="paragraph-source responsive-dialog"
44
:title="$t('chat.paragraphSource.title')"
55
v-model="dialogVisible"
66
destroy-on-close
@@ -76,9 +76,4 @@ defineExpose({ open })
7676
max-height: calc(100vh - 260px);
7777
}
7878
}
79-
@media only screen and (max-width: 768px) {
80-
.paragraph-source {
81-
width: 90% !important;
82-
}
83-
}
8479
</style>

ui/src/locales/lang/en-US/ai-chat.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ export default {
9090
title: 'Knowledge Quote',
9191
question: 'User Question',
9292
optimizationQuestion: 'Optimized Question'
93-
}
93+
},
94+
editTitle: 'Edit Title',
9495
}

0 commit comments

Comments
 (0)