-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: The demonstration page supports modifying dialogue summaries #2348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
752e1eb
b50db41
cd03e6b
b1a3d97
43e2e5e
3d7a9fc
fbca792
f034f2a
097c5f8
83254bf
3518433
8b293ae
b6de93e
131b186
1a4cc6e
99b8448
5869af0
a6525d3
28c2d6b
ff99830
16cfca6
efd6de3
22fb799
1368d37
3e347d2
3361acf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,34 @@ def get_request_params_api(): | |
| description=_('Application ID')) | ||
| ] | ||
|
|
||
| class Operate(ApiMixin): | ||
| @staticmethod | ||
| def get_request_params_api(): | ||
| return [openapi.Parameter(name='application_id', | ||
| in_=openapi.IN_PATH, | ||
| type=openapi.TYPE_STRING, | ||
| required=True, | ||
| description=_('Application ID')), | ||
| openapi.Parameter(name='chat_id', | ||
| in_=openapi.IN_PATH, | ||
| type=openapi.TYPE_STRING, | ||
| required=True, | ||
| description=_('Conversation ID')), | ||
| ] | ||
|
|
||
| class ReAbstract(ApiMixin): | ||
| @staticmethod | ||
| def get_request_body_api(): | ||
| return openapi.Schema( | ||
| type=openapi.TYPE_OBJECT, | ||
| required=['abstract'], | ||
| properties={ | ||
| 'abstract': openapi.Schema(type=openapi.TYPE_STRING, title=_("abstract"), | ||
| description=_("abstract")) | ||
|
|
||
| } | ||
| ) | ||
|
|
||
|
|
||
| class OpenAIChatApi(ApiMixin): | ||
| @staticmethod | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet looks generally structured but contains some areas that could benefit from improvements, such as documentation clarity and adherence to best practices. Here's a review with suggestions: General Comments:
Implementation Suggestions:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,7 +150,7 @@ def post(self, request: Request, chat_id: str): | |
| operation_id=_("Get the conversation list"), | ||
| manual_parameters=ChatApi.get_request_params_api(), | ||
| responses=result.get_api_array_response(ChatApi.get_response_body_api()), | ||
| tags=[_("Application/Conversation Log")] | ||
| tags=[_("Application/Conversation Log")] | ||
| ) | ||
| @has_permissions( | ||
| ViewPermission([RoleConstants.ADMIN, RoleConstants.USER, RoleConstants.APPLICATION_KEY], | ||
|
|
@@ -222,6 +222,23 @@ def delete(self, request: Request, application_id: str, chat_id: str): | |
| data={'application_id': application_id, 'user_id': request.user.id, | ||
| 'chat_id': chat_id}).logic_delete()) | ||
|
|
||
| @action(methods=['PUT'], detail=False) | ||
| @swagger_auto_schema(operation_summary=_("Client modifies dialogue summary"), | ||
| operation_id=_("Client modifies dialogue summary"), | ||
| request_body=ChatClientHistoryApi.Operate.ReAbstract.get_request_body_api(), | ||
| tags=[_("Application/Conversation Log")]) | ||
| @has_permissions(ViewPermission( | ||
| [RoleConstants.APPLICATION_ACCESS_TOKEN], | ||
| [lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.USE, | ||
| dynamic_tag=keywords.get('application_id'))], | ||
| compare=CompareConstants.AND), | ||
| compare=CompareConstants.AND) | ||
| def put(self, request: Request, application_id: str, chat_id: str): | ||
| return result.success( | ||
| ChatSerializers.Operate( | ||
| data={'application_id': application_id, 'user_id': request.user.id, | ||
| 'chat_id': chat_id}).re_abstract(request.data)) | ||
|
|
||
| class Page(APIView): | ||
| authentication_classes = [TokenAuth] | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code appears mostly clean and functional. However, I do have a few optimizations and suggestions:
These suggested changes should help optimize and clarify the given codebase. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,5 +90,6 @@ export default { | |
| title: '知識庫引用', | ||
| question: '用戶問題', | ||
| optimizationQuestion: '優化後問題' | ||
| } | ||
| }, | ||
| editTitle: '編輯標題', | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <template> | ||
| <el-dialog | ||
| :title="$t('chat.editTitle')" | ||
| v-model="dialogVisible" | ||
| :close-on-click-modal="false" | ||
| :close-on-press-escape="false" | ||
| :destroy-on-close="true" | ||
| append-to-body | ||
| > | ||
| <el-form | ||
| label-position="top" | ||
| ref="fieldFormRef" | ||
| :model="form" | ||
| require-asterisk-position="right" | ||
| > | ||
| <el-form-item | ||
| prop="abstract" | ||
| :rules="[ | ||
| { | ||
| required: true, | ||
| message: $t('common.inputPlaceholder'), | ||
| trigger: 'blur' | ||
| } | ||
| ]" | ||
| > | ||
| <el-input | ||
| v-model="form.abstract" | ||
| maxlength="1024" | ||
| show-word-limit | ||
| @blur="form.abstract = form.abstract.trim()" | ||
| /> | ||
| </el-form-item> | ||
| </el-form> | ||
| <template #footer> | ||
| <span class="dialog-footer"> | ||
| <el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button> | ||
| <el-button type="primary" @click="submit(fieldFormRef)" :loading="loading"> | ||
| {{ $t('common.save') }} | ||
| </el-button> | ||
| </span> | ||
| </template> | ||
| </el-dialog> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { reactive, ref, watch } from 'vue' | ||
| import type { FormInstance } from 'element-plus' | ||
| import useStore from '@/stores' | ||
| import { t } from '@/locales' | ||
| const { log } = useStore() | ||
| const emit = defineEmits(['refresh']) | ||
| const fieldFormRef = ref() | ||
| const loading = ref<boolean>(false) | ||
| const applicationId = ref<string>('') | ||
| const chatId = ref<string>('') | ||
| const form = ref<any>({ | ||
| abstract: '' | ||
| }) | ||
| const dialogVisible = ref<boolean>(false) | ||
| const open = (row: any, id: string) => { | ||
| applicationId.value = id | ||
| chatId.value = row.id | ||
| form.value.abstract = row.abstract | ||
| dialogVisible.value = true | ||
| } | ||
| const submit = async (formEl: FormInstance | undefined) => { | ||
| if (!formEl) return | ||
| await formEl.validate((valid) => { | ||
| if (valid) { | ||
| log.asyncPutChatClientLog(applicationId.value, chatId.value, form.value, loading).then(() => { | ||
| emit('refresh') | ||
| dialogVisible.value = false | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
| defineExpose({ open, close }) | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code is syntactically correct and should work as intended with Element Plus components. There are a few minor improvements you might consider:
Here's a slightly refined version of the code incorporating these considerations: @@ -0,0 +1,85 @@
+<template>
+ <el-dialog
+ :title="$t('chat.editTitle')"
+ v-model="dialogVisible"
+ :close-on-click-modal="false"
+ :close-on-press-escape="false"
+ :destroy-on-close="true"
+ append-to-body
+ >
+ <el-form
+ label-position="top"
+ ref="fieldFormRef"
+ :model="form"
+ require-asterisk-position="right"
+ >
+ <el-form-item
+ prop="abstract"
+ :rules="[
+ {
+ required: true,
+ message: $t('common.inputPlaceholder'),
+ trigger: 'blur'
+ }
+ ]"
+ >
+ <el-input
+ v-model="form.abstract"
+ maxlength="1024"
+ show-word-limit
+ @blur="form.abstract = form.abstract.trim()"
+ />
+ </el-form-item>
+ </el-form>
+ <template #footer>
+ <span class="dialog-footer">
+ <el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
+ <el-button type="primary" @click="submit(fieldFormRef)" :loading="loading">
+ {{ $t('common.save') }}
+ </el-button>
+ </span>
+ </template>
+ </el-dialog>
+</template>
<script setup lang="ts">
import { reactive, ref, watch } from 'vue';
import type { FormInstance } from 'element-plus';
import useStore from '@/stores';
import { t } from '@/locales';
const store = useStore() // Specify the actual type of your store
const emit = defineEmits(['refresh']);
const fieldFormRef = ref<FormInstance>();
const loading = ref(false);
const applicationId = ref('');
const chatId = ref('');
const form = ref<{ abstract: string }>({
abstract: ''
});
const dialogVisible = ref(false);
const open = (row: any, id: string) => {
applicationId.value = id;
chatId.value = row.id;
form.value.abstract = row.abstract;
dialogVisible.value = true;
};
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
try {
await formEl.validate();
await store.asyncPutChatClientLog(applicationId.value, chatId.value, form.value, loading.value);
emit('refresh');
dialogVisible.value = false;
} catch (error) {
console.error(error); // Log error in development environment
}
};
defineExpose({ open });
</script>
<style lang="scss" scoped></style>Ensure that all imports and dependencies are correctly installed and available in your project. This revised code provides type safety and basic accessibility improvements while maintaining functional correctness.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears to be a Vue component implementing an edit form for chat messages using Element Plus components. Here are some points and potential improvements: Potential Issues and Improvements:
Here's a simplified version with additional type definitions and some logging for errors during the save operation: <script setup lang="ts">
import { ref, watchEffect } from 'vue';
import type { FormInstance } from 'element-plus';
import useStore from '@/stores';
import { t } from '@/locales';
const { log } = useStore();
const emit = defineEmits(['refresh']);
const fieldFormRef = ref<FormInstance>();
const loading = ref(false);
const applicationId = ref('');
const chatId = ref('');
interface FormData {
abstract: string;
}
let formState: formData | null = null;
const form = ref({
abstract: ''
});
const dialogVisible = ref<boolean>(false);
// Initialize state data when opening the dialog
const updateFormData = (row: any, id: string) => {
applicationId.value = id;
chatId.value = row.id;
form.value.abstract = row.abstract;
};
const open = (rowData: any, id: string): void => {
// Fetch and load initial data before showing the dialog
Promise.resolve().then(() => {
updateFormData(rowData, id);
dialogVisible.value = true;
}).catch(e => console.error("Failed to fetch data:", e));
};By addressing these areas, you'll create a more robust and maintainable component. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,10 +66,22 @@ | |
| <auto-tooltip :content="row.abstract"> | ||
| {{ row.abstract }} | ||
| </auto-tooltip> | ||
| <div @click.stop v-if="mouseId === row.id && row.id !== 'new'"> | ||
| <el-button style="padding: 0" link @click.stop="deleteLog(row)"> | ||
| <el-icon><Delete /></el-icon> | ||
| </el-button> | ||
| <div @click.stop v-show="mouseId === row.id && row.id !== 'new'"> | ||
| <el-dropdown trigger="click" :teleported="false"> | ||
| <el-icon class="rotate-90 mt-4"><MoreFilled /></el-icon> | ||
| <template #dropdown> | ||
| <el-dropdown-menu> | ||
| <el-dropdown-item @click.stop="editLogTitle(row)"> | ||
| <el-icon><EditPen /></el-icon> | ||
| {{ $t('common.edit') }} | ||
| </el-dropdown-item> | ||
| <el-dropdown-item @click.stop="deleteLog(row)"> | ||
| <el-icon><Delete /></el-icon> | ||
| {{ $t('common.delete') }} | ||
| </el-dropdown-item> | ||
| </el-dropdown-menu> | ||
| </template> | ||
| </el-dropdown> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
@@ -145,6 +157,7 @@ | |
| </div> | ||
| </div> | ||
| </div> | ||
| <EditTitleDialog ref="EditTitleDialogRef" @refresh="refreshFieldTitle" /> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
|
|
@@ -155,14 +168,13 @@ import { isAppIcon } from '@/utils/application' | |
| import useStore from '@/stores' | ||
| import useResize from '@/layout/hooks/useResize' | ||
| import { hexToRgba } from '@/utils/theme' | ||
| import EditTitleDialog from './EditTitleDialog.vue' | ||
| import { t } from '@/locales' | ||
| useResize() | ||
|
|
||
| const { user, log, common } = useStore() | ||
|
|
||
| const isDefaultTheme = computed(() => { | ||
| return user.isDefaultTheme() | ||
| }) | ||
| const EditTitleDialogRef = ref() | ||
|
|
||
| const isCollapse = ref(false) | ||
|
|
||
|
|
@@ -216,6 +228,13 @@ const mouseId = ref('') | |
| function mouseenter(row: any) { | ||
| mouseId.value = row.id | ||
| } | ||
|
|
||
| function editLogTitle(row: any) { | ||
| EditTitleDialogRef.value.open(row, applicationDetail.value.id) | ||
| } | ||
| function refreshFieldTitle() { | ||
| getChatLog(applicationDetail.value.id) | ||
| } | ||
| function deleteLog(row: any) { | ||
| log.asyncDelChatClientLog(applicationDetail.value.id, row.id, left_loading).then(() => { | ||
| if (currentChatId.value === row.id) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears mostly correct overall. However, there are a few minor improvements and clarifications that can be made:
Here's the updated code with these considerations: <template>
<!-- ...existing template content here... -->
<div @click.stop v-show="mouseId === row.id && row.id !== 'new'">
<el-dropdown trigger="click" :teleported="false">
<el-icon class="rotate-90 mt-4"><MoreFilled /></el-icon>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click.stop="editLogTitle(row)">
<el-icon><EditPen /></el-icon>
{{ $t('common.edit') }}
</el-dropdown-item>
<el-dropdown-item @click.stop="deleteLog(row)">
<el-icon><Delete /></el-icon>
{{ $t('common.delete') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
<!-- ...existing template content here... -->
</template>
<script setup lang="ts">
<!-- ... existing script setup content here... -->
import { ref } from 'vue'
// Assuming applicationDetail value and related logic exist
const EditTitleDialogRef = ref();
export default defineComponent({
// ... existing script export statement here...
});Additional Suggestions:
These suggestions will help ensure the code remains maintainable and efficient over time. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some recommendations for optimizing and improving the code:
Class Naming Conventions: Consider using PascalCase or CamelCase for class names to make them more readable.
Serializer Structure Simplification: The
ChatSerializershas a nested serializer in itsOperateclass which adds unnecessary complexity. It might be better to have separate classes for different operations instead of nesting serializers.Error Handling Cleanup: Use consistent error handling throughout. Currently, it's okay but ensure that all exceptions raise the same type of exception.
Optimization in Logic Delete Method: The method can be optimized by directly accessing the database without filtering first, then updating based on conditions.
ReAbstract Instance Method:
.get()inside the loop if you're using Python 3.7+, as dictionaries maintain insertion order.Add a check before attempting to update the abstract field to ensure there is an abstract value to overwrite.
General Formatting: Ensure consistent formatting including spacing between statements, variable definitions, etc., this improves readability.
Example refactored version:
This version consolidates similar functionalities under separate methods and ensures cleaner, more efficient execution of each operation.