diff --git a/apps/models_provider/serializers/model_serializer.py b/apps/models_provider/serializers/model_serializer.py index a5b09119255..29f5ddb5e0d 100644 --- a/apps/models_provider/serializers/model_serializer.py +++ b/apps/models_provider/serializers/model_serializer.py @@ -454,7 +454,7 @@ def _build_query_params(self, workspace_id, workspace_manage: bool, user_id): queryset = queryset.filter(user_id=value) else: queryset = queryset.filter(**{field: value}) - queryset = queryset.order_by("-create_time") + queryset = queryset.select_related("user").order_by("-create_time") return ( { "model_query_set": queryset, diff --git a/ui/src/api/admin/system/resource-management/application/conversation.ts b/ui/src/api/admin/system/resource-management/application/conversation.ts new file mode 100644 index 00000000000..d81fe97c20a --- /dev/null +++ b/ui/src/api/admin/system/resource-management/application/conversation.ts @@ -0,0 +1,59 @@ +import { get, post, put, del, postStream } from '@/api/admin/core/request' +import { ADMIN_API_BASE_PATH as adminApiBase } from '@/api/constants' + +const getPrefix = (applicationId: string) => `/system/resource/application/${applicationId}` + +/** 打开对话。 */ +const getConversationOpen = (applicationId: string) => get(`${getPrefix(applicationId)}/open`) + +/** 发送对话消息并返回原始流式响应。 */ +const postConversationMessage = (chatId: string, data: unknown, applicationId: string) => + postStream(adminApiBase, `${getPrefix(applicationId)}/chat/${chatId}/chat_message`, data) + +/** 取消对话消息生成。 */ +const postCancelConversationMessage = (chatId: string, applicationId: string) => + post(`${getPrefix(applicationId)}/chat/${chatId}/cancel_chat_message`, {}) + +/** 恢复对话消息流。 */ +const postResumeConversationMessage = (chatId: string, chatRecordId: string, applicationId: string) => + postStream( + adminApiBase, + `${getPrefix(applicationId)}/chat/${chatId}/chat_record/${chatRecordId}/resume_chat_message`, + ) + +/** 获取历史会话分页。 */ +const getConversationPage = (page: number, size: number, applicationId: string) => + get(`${getPrefix(applicationId)}/historical_conversation/${page}/${size}`) + +/** 获取会话记录详情。 */ +const getConversationRecordDetail = (chatId: string, chatRecordId: string, applicationId: string) => + get(`${getPrefix(applicationId)}/chat/${chatId}/chat_record/${chatRecordId}`) + +/** 获取会话记录分页。 */ +const getConversationRecordPage = (chatId: string, page: number, size: number, applicationId: string) => + get(`${getPrefix(applicationId)}/historical_conversation_record/${chatId}/${page}/${size}`) + +/** 删除会话。 */ +const deleteConversation = (chatId: string, applicationId: string) => + del(`${getPrefix(applicationId)}/historical_conversation/${chatId}`) + +/** 修改会话信息。 */ +const putConversation = (chatId: string, data: unknown, applicationId: string) => + put(`${getPrefix(applicationId)}/historical_conversation/${chatId}`, data) + +/** 使用指定智能体将语音转换为文字。 */ +const postSpeechToText = (applicationId: string, data: unknown) => + post(`${getPrefix(applicationId)}/speech_to_text`, data) + +export default { + getConversationOpen, + postConversationMessage, + postCancelConversationMessage, + postResumeConversationMessage, + getConversationPage, + getConversationRecordDetail, + getConversationRecordPage, + deleteConversation, + putConversation, + postSpeechToText, +} diff --git a/ui/src/conversation-panel/view/debug/index.ts b/ui/src/conversation-panel/view/debug/index.ts index ed2d1a01c07..300cf2adaed 100644 --- a/ui/src/conversation-panel/view/debug/index.ts +++ b/ui/src/conversation-panel/view/debug/index.ts @@ -1,6 +1,8 @@ import { computed } from 'vue' import { useRoute } from 'vue-router' -import ConversationApi from '@/api/admin/workspace/conversation' +import WorkspaceConversationApi from '@/api/admin/workspace/conversation' +import SystemResourceConversationApi from '@/api/admin/system/resource-management/application/conversation' +import { isSystemResource } from '@/utils/resource-context' import { useStore } from '@/stores' import FileApi from '@/api/admin/file' import { FILE_SOURCE_TYPE } from '@/api/enums' @@ -14,6 +16,7 @@ import type { ConversationBundle } from '../types' /** debug 模式:装配各组件 store。adapter 走 admin(带 applicationId)。 */ export function createDebugConversation(): ConversationBundle { const route = useRoute() + const ConversationApi = isSystemResource() ? SystemResourceConversationApi : WorkspaceConversationApi const appId = computed( () => (route.params.id as string) || (route.params.applicationId as string) || '', )