mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: simple application debug chat (#3244)
This commit is contained in:
parent
b624de75be
commit
c7e30bb098
|
|
@ -704,14 +704,14 @@ class ApplicationOperateSerializer(serializers.Serializer):
|
|||
self.is_valid()
|
||||
application_id = self.data.get("application_id")
|
||||
application = QuerySet(Application).get(id=application_id)
|
||||
dataset_list = self.list_knowledge(with_valid=False)
|
||||
knowledge_list = self.list_knowledge(with_valid=False)
|
||||
mapping_knowledge_id_list = [akm.knowledge_id for akm in
|
||||
QuerySet(ApplicationKnowledgeMapping).filter(application_id=application_id)]
|
||||
knowledge_id_list = [d.get('id') for d in
|
||||
list(filter(lambda row: mapping_knowledge_id_list.__contains__(row.get('id')),
|
||||
dataset_list))]
|
||||
knowledge_list))]
|
||||
return {**ApplicationSerializerModel(application).data,
|
||||
'dataset_id_list': knowledge_id_list}
|
||||
'knowledge_id_list': knowledge_id_list}
|
||||
|
||||
def list_knowledge(self, with_valid=True):
|
||||
if with_valid:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ from django.db.models import QuerySet
|
|||
from rest_framework import serializers
|
||||
from rest_framework.utils.formatting import lazy_format
|
||||
|
||||
from application.models import ChatRecord
|
||||
from application.models import ChatRecord, ApplicationAccessToken
|
||||
from application.serializers.common import ChatInfo
|
||||
from common.db.search import page_search
|
||||
from common.exception.app_exception import AppApiException
|
||||
from common.utils.common import post
|
||||
|
|
@ -37,6 +38,40 @@ class ChatRecordSerializerModel(serializers.ModelSerializer):
|
|||
'create_time', 'update_time']
|
||||
|
||||
|
||||
class ChatRecordOperateSerializer(serializers.Serializer):
|
||||
chat_id = serializers.UUIDField(required=True, label=_("Conversation ID"))
|
||||
workspace_id = serializers.CharField(required=False, label=_("Workspace ID"))
|
||||
application_id = serializers.UUIDField(required=True, label=_("Application ID"))
|
||||
chat_record_id = serializers.UUIDField(required=True, label=_("Conversation record id"))
|
||||
|
||||
def is_valid(self, *, debug=False, raise_exception=False):
|
||||
super().is_valid(raise_exception=True)
|
||||
application_access_token = QuerySet(ApplicationAccessToken).filter(
|
||||
application_id=self.data.get('application_id')).first()
|
||||
if application_access_token is None:
|
||||
raise AppApiException(500, gettext('Application authentication information does not exist'))
|
||||
if not application_access_token.show_source and not debug:
|
||||
raise AppApiException(500, gettext('Displaying knowledge sources is not enabled'))
|
||||
|
||||
def get_chat_record(self):
|
||||
chat_record_id = self.data.get('chat_record_id')
|
||||
chat_id = self.data.get('chat_id')
|
||||
chat_info: ChatInfo = ChatInfo.get_cache(chat_id)
|
||||
if chat_info is not None:
|
||||
chat_record_list = [chat_record for chat_record in chat_info.chat_record_list if
|
||||
str(chat_record.id) == str(chat_record_id)]
|
||||
if chat_record_list is not None and len(chat_record_list):
|
||||
return chat_record_list[-1]
|
||||
return QuerySet(ChatRecord).filter(id=chat_record_id, chat_id=chat_id).first()
|
||||
|
||||
def one(self, debug):
|
||||
self.is_valid(debug=debug, raise_exception=True)
|
||||
chat_record = self.get_chat_record()
|
||||
if chat_record is None:
|
||||
raise AppApiException(500, gettext("Conversation does not exist"))
|
||||
return ApplicationChatRecordQuerySerializers.reset_chat_record(chat_record)
|
||||
|
||||
|
||||
class ApplicationChatRecordQuerySerializers(serializers.Serializer):
|
||||
application_id = serializers.UUIDField(required=True, label=_("Application ID"))
|
||||
chat_id = serializers.UUIDField(required=True, label=_("Chat ID"))
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ urlpatterns = [
|
|||
path(
|
||||
'workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record',
|
||||
views.ApplicationChatRecord.as_view()),
|
||||
path(
|
||||
'workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record/<str:chat_record_id>',
|
||||
views.ApplicationChatRecordOperateAPI.as_view()),
|
||||
path(
|
||||
'workspace/<str:workspace_id>/application/<str:application_id>/chat/<str:chat_id>/chat_record/<int:current_page>/<int:page_size>',
|
||||
views.ApplicationChatRecord.Page.as_view()),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ from rest_framework.views import APIView
|
|||
from application.api.application_chat_record import ApplicationChatRecordQueryAPI, \
|
||||
ApplicationChatRecordImproveParagraphAPI, ApplicationChatRecordAddKnowledgeAPI
|
||||
from application.serializers.application_chat_record import ApplicationChatRecordQuerySerializers, \
|
||||
ApplicationChatRecordImproveSerializer, ChatRecordImproveSerializer, ApplicationChatRecordAddKnowledgeSerializer
|
||||
ApplicationChatRecordImproveSerializer, ChatRecordImproveSerializer, ApplicationChatRecordAddKnowledgeSerializer, \
|
||||
ChatRecordOperateSerializer
|
||||
from common import result
|
||||
from common.auth import TokenAuth
|
||||
from common.auth.authentication import has_permissions
|
||||
|
|
@ -67,6 +68,30 @@ class ApplicationChatRecord(APIView):
|
|||
page_size=page_size))
|
||||
|
||||
|
||||
class ApplicationChatRecordOperateAPI(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
@extend_schema(
|
||||
methods=['GET'],
|
||||
description=_("Get conversation record details"),
|
||||
summary=_("Get conversation record details"),
|
||||
operation_id=_("Get conversation record details"), # type: ignore
|
||||
request=ApplicationChatRecordQueryAPI.get_request(),
|
||||
parameters=ApplicationChatRecordQueryAPI.get_parameters(),
|
||||
responses=ApplicationChatRecordQueryAPI.get_response(),
|
||||
tags=[_("Application/Conversation Log")] # type: ignore
|
||||
)
|
||||
@has_permissions(PermissionConstants.APPLICATION_CHAT_LOG.get_workspace_application_permission(),
|
||||
RoleConstants.WORKSPACE_MANAGE.get_workspace_role())
|
||||
def get(self, request: Request, workspace_id: str, application_id: str, chat_id: str, chat_record_id: str):
|
||||
return result.success(ChatRecordOperateSerializer(
|
||||
data={
|
||||
'workspace_id': workspace_id,
|
||||
'application_id': application_id,
|
||||
'chat_id': chat_id,
|
||||
'chat_record_id': chat_record_id}).one(True))
|
||||
|
||||
|
||||
class ApplicationChatRecordAddKnowledge(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ class DebugChatSerializers(serializers.Serializer):
|
|||
self.is_valid(raise_exception=True)
|
||||
chat_id = self.data.get('chat_id')
|
||||
chat_info: ChatInfo = ChatInfo.get_cache(chat_id)
|
||||
application = QuerySet(Application).filter(id=chat_info.application_id).first()
|
||||
chat_info.application = application
|
||||
return ChatSerializers(data={
|
||||
'chat_id': chat_id, "chat_user_id": chat_info.chat_user_id,
|
||||
"chat_user_type": chat_info.chat_user_type,
|
||||
|
|
|
|||
|
|
@ -140,6 +140,27 @@ const getStatistics: (
|
|||
) => Promise<Result<any>> = (application_id, data, loading) => {
|
||||
return get(`${prefix}/${application_id}/application_stats`, data, loading)
|
||||
}
|
||||
/**
|
||||
* 打开调试对话id
|
||||
* @param application_id 应用id
|
||||
* @param loading 加载器
|
||||
* @returns
|
||||
*/
|
||||
const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<string>> = (
|
||||
application_id,
|
||||
loading,
|
||||
) => {
|
||||
return get(`${prefix}/${application_id}/open`, {}, loading)
|
||||
}
|
||||
/**
|
||||
* 对话
|
||||
* @param 参数
|
||||
* chat_id: string
|
||||
* data
|
||||
*/
|
||||
const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => {
|
||||
return postStream(`/api/chat_message/${chat_id}`, data)
|
||||
}
|
||||
|
||||
export default {
|
||||
getAllApplication,
|
||||
|
|
@ -153,4 +174,6 @@ export default {
|
|||
exportApplication,
|
||||
importApplication,
|
||||
getStatistics,
|
||||
open,
|
||||
chat,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,18 @@ const postExportChatLog: (
|
|||
loading,
|
||||
)
|
||||
}
|
||||
|
||||
const getChatRecordDetails: (
|
||||
application_id: string,
|
||||
chat_id: string,
|
||||
chat_record_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<any> = (application_id, chat_id, chat_record_id, loading) => {
|
||||
return get(
|
||||
`${prefix}/${application_id}/chat/${chat_id}/chat_record/${chat_record_id}`,
|
||||
{},
|
||||
loading,
|
||||
)
|
||||
}
|
||||
export default {
|
||||
postChatLogAddKnowledge,
|
||||
getChatLog,
|
||||
|
|
@ -197,4 +208,5 @@ export default {
|
|||
putChatRecordLog,
|
||||
delMarkChatRecord,
|
||||
postExportChatLog,
|
||||
getChatRecordDetails,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import {Result} from '@/request/Result'
|
||||
import {get, post, del, put} from '@/request/index'
|
||||
import {type Ref} from 'vue'
|
||||
import { Result } from '@/request/Result'
|
||||
import { get, post, del, put } from '@/request/index'
|
||||
import { type Ref } from 'vue'
|
||||
import type {
|
||||
ListModelRequest,
|
||||
Model,
|
||||
CreateModelRequest,
|
||||
EditModelRequest,
|
||||
} from '@/api/type/model'
|
||||
import type {FormField} from '@/components/dynamics-form/type'
|
||||
import type { FormField } from '@/components/dynamics-form/type'
|
||||
|
||||
const prefix = '/workspace/' + localStorage.getItem('workspace_id')
|
||||
|
||||
|
|
@ -21,7 +21,61 @@ const getModel: (
|
|||
) => Promise<Result<Array<Model>>> = (data, loading) => {
|
||||
return get(`${prefix}/model`, data, loading)
|
||||
}
|
||||
/**
|
||||
* 获取当前用户可使用的模型列表
|
||||
* @param application_id
|
||||
* @param loading
|
||||
* @query { query_text: string, top_number: number, similarity: number }
|
||||
* @returns
|
||||
*/
|
||||
const getApplicationRerankerModel: (
|
||||
application_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (application_id, loading) => {
|
||||
return get(`${prefix}/model`, { model_type: 'RERANKER' }, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户可使用的模型列表
|
||||
* @param application_id
|
||||
* @param loading
|
||||
* @query { query_text: string, top_number: number, similarity: number }
|
||||
* @returns
|
||||
*/
|
||||
const getApplicationSTTModel: (
|
||||
application_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (application_id, loading) => {
|
||||
return get(`${prefix}/model`, { model_type: 'STT' }, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户可使用的模型列表
|
||||
* @param application_id
|
||||
* @param loading
|
||||
* @query { query_text: string, top_number: number, similarity: number }
|
||||
* @returns
|
||||
*/
|
||||
const getApplicationTTSModel: (
|
||||
application_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (application_id, loading) => {
|
||||
return get(`${prefix}/model`, { model_type: 'TTS' }, loading)
|
||||
}
|
||||
|
||||
const getApplicationImageModel: (
|
||||
application_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (application_id, loading) => {
|
||||
return get(`${prefix}/model`, { model_type: 'IMAGE' }, loading)
|
||||
}
|
||||
|
||||
const getApplicationTTIModel: (
|
||||
application_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Array<any>>> = (application_id, loading) => {
|
||||
return get(`${prefix}/model`, { model_type: 'TTI' }, loading)
|
||||
}
|
||||
/**
|
||||
* 获取模型参数表单
|
||||
* @param model_id 模型id
|
||||
|
|
@ -82,10 +136,10 @@ const updateModelParamsForm: (
|
|||
* @param loading 加载器
|
||||
* @returns
|
||||
*/
|
||||
const getModelById: (
|
||||
model_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Model>> = (model_id, loading) => {
|
||||
const getModelById: (model_id: string, loading?: Ref<boolean>) => Promise<Result<Model>> = (
|
||||
model_id,
|
||||
loading,
|
||||
) => {
|
||||
return get(`${prefix}/model/${model_id}`, {}, loading)
|
||||
}
|
||||
/**
|
||||
|
|
@ -94,10 +148,10 @@ const getModelById: (
|
|||
* @param loading 加载器
|
||||
* @returns
|
||||
*/
|
||||
const getModelMetaById: (
|
||||
model_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<Model>> = (model_id, loading) => {
|
||||
const getModelMetaById: (model_id: string, loading?: Ref<boolean>) => Promise<Result<Model>> = (
|
||||
model_id,
|
||||
loading,
|
||||
) => {
|
||||
return get(`${prefix}/model/${model_id}/meta`, {}, loading)
|
||||
}
|
||||
/**
|
||||
|
|
@ -106,16 +160,16 @@ const getModelMetaById: (
|
|||
* @param loading 加载器
|
||||
* @returns
|
||||
*/
|
||||
const pauseDownload: (
|
||||
model_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<boolean>> = (model_id, loading) => {
|
||||
const pauseDownload: (model_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
|
||||
model_id,
|
||||
loading,
|
||||
) => {
|
||||
return put(`${prefix}/model/${model_id}/pause_download`, undefined, {}, loading)
|
||||
}
|
||||
const deleteModel: (
|
||||
model_id: string,
|
||||
loading?: Ref<boolean>,
|
||||
) => Promise<Result<boolean>> = (model_id, loading) => {
|
||||
const deleteModel: (model_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
|
||||
model_id,
|
||||
loading,
|
||||
) => {
|
||||
return del(`${prefix}/model/${model_id}`, undefined, {}, loading)
|
||||
}
|
||||
export default {
|
||||
|
|
@ -128,4 +182,9 @@ export default {
|
|||
pauseDownload,
|
||||
getModelParamsForm,
|
||||
updateModelParamsForm,
|
||||
getApplicationRerankerModel,
|
||||
getApplicationSTTModel,
|
||||
getApplicationTTSModel,
|
||||
getApplicationImageModel,
|
||||
getApplicationTTIModel,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
:class="type"
|
||||
:style="{
|
||||
height: firsUserInput ? '100%' : undefined,
|
||||
paddingBottom: applicationDetails.disclaimer ? '20px' : 0
|
||||
paddingBottom: applicationDetails.disclaimer ? '20px' : 0,
|
||||
}"
|
||||
>
|
||||
<div
|
||||
|
|
@ -120,7 +120,7 @@ defineOptions({ name: 'AiChat' })
|
|||
const route = useRoute()
|
||||
const {
|
||||
params: { accessToken, id },
|
||||
query: { mode }
|
||||
query: { mode },
|
||||
} = route as any
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
|
|
@ -134,8 +134,8 @@ const props = withDefaults(
|
|||
{
|
||||
applicationDetails: () => ({}),
|
||||
available: true,
|
||||
type: 'ai-chat'
|
||||
}
|
||||
type: 'ai-chat',
|
||||
},
|
||||
)
|
||||
const emit = defineEmits(['refresh', 'scroll'])
|
||||
const { application, common } = useStore()
|
||||
|
|
@ -163,13 +163,13 @@ const initialApiFormData = ref({})
|
|||
const isUserInput = computed(
|
||||
() =>
|
||||
props.applicationDetails.work_flow?.nodes?.filter((v: any) => v.id === 'base-node')[0]
|
||||
.properties.user_input_field_list.length > 0
|
||||
.properties.user_input_field_list.length > 0,
|
||||
)
|
||||
const isAPIInput = computed(
|
||||
() =>
|
||||
props.type === 'debug-ai-chat' &&
|
||||
props.applicationDetails.work_flow?.nodes?.filter((v: any) => v.id === 'base-node')[0]
|
||||
.properties.api_input_field_list.length > 0
|
||||
.properties.api_input_field_list.length > 0,
|
||||
)
|
||||
const showUserInputContent = computed(() => {
|
||||
return (
|
||||
|
|
@ -192,7 +192,7 @@ watch(
|
|||
}
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
{ deep: true, immediate: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
|
|
@ -200,7 +200,7 @@ watch(
|
|||
() => {
|
||||
chartOpenId.value = ''
|
||||
},
|
||||
{ deep: true }
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
|
|
@ -209,8 +209,8 @@ watch(
|
|||
chatList.value = value ? value : []
|
||||
},
|
||||
{
|
||||
immediate: true
|
||||
}
|
||||
immediate: true,
|
||||
},
|
||||
)
|
||||
|
||||
const toggleUserInput = () => {
|
||||
|
|
@ -292,9 +292,9 @@ const handleDebounceClick = debounce((val, other_params_data?: any, chat?: chatT
|
|||
*/
|
||||
const openChatId: () => Promise<string> = () => {
|
||||
const obj = props.applicationDetails
|
||||
if (props.appId) {
|
||||
if (props.type === 'debug-ai-chat') {
|
||||
return applicationApi
|
||||
.getChatOpen(props.appId)
|
||||
.open(obj.id)
|
||||
.then((res) => {
|
||||
chartOpenId.value = res.data
|
||||
return res.data
|
||||
|
|
@ -308,21 +308,7 @@ const openChatId: () => Promise<string> = () => {
|
|||
return Promise.reject(res)
|
||||
})
|
||||
} else {
|
||||
if (isWorkFlow(obj.type)) {
|
||||
const submitObj = {
|
||||
work_flow: obj.work_flow,
|
||||
user_id: obj.user
|
||||
}
|
||||
return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
|
||||
chartOpenId.value = res.data
|
||||
return res.data
|
||||
})
|
||||
} else {
|
||||
return applicationApi.postChatOpen(obj).then((res) => {
|
||||
chartOpenId.value = res.data
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
return Promise.reject('暂不支持')
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -447,8 +433,8 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para
|
|||
audio_list:
|
||||
other_params_data && other_params_data.audio_list ? other_params_data.audio_list : [],
|
||||
other_list:
|
||||
other_params_data && other_params_data.other_list ? other_params_data.other_list : []
|
||||
}
|
||||
other_params_data && other_params_data.other_list ? other_params_data.other_list : [],
|
||||
},
|
||||
})
|
||||
chatList.value.push(chat)
|
||||
ChatManagement.addChatRecord(chat, 50, loading)
|
||||
|
|
@ -470,16 +456,17 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para
|
|||
} else {
|
||||
const obj = {
|
||||
message: chat.problem_text,
|
||||
stream: true,
|
||||
re_chat: re_chat || false,
|
||||
...other_params_data,
|
||||
form_data: {
|
||||
...form_data.value,
|
||||
...api_form_data.value
|
||||
}
|
||||
...api_form_data.value,
|
||||
},
|
||||
}
|
||||
// 对话
|
||||
applicationApi
|
||||
.postChatMessage(chartOpenId.value, obj)
|
||||
.chat(chartOpenId.value, obj)
|
||||
.then((response) => {
|
||||
if (response.status === 401) {
|
||||
application
|
||||
|
|
@ -504,7 +491,7 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para
|
|||
const write = getWrite(
|
||||
chat,
|
||||
reader,
|
||||
response.headers.get('Content-Type') !== 'application/json'
|
||||
response.headers.get('Content-Type') !== 'application/json',
|
||||
)
|
||||
return reader.read().then(write)
|
||||
}
|
||||
|
|
@ -530,14 +517,16 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para
|
|||
*/
|
||||
function getSourceDetail(row: any) {
|
||||
if (row.record_id) {
|
||||
chatLogApi.getRecordDetail(id || props.appId, row.chat_id, row.record_id, loading).then((res) => {
|
||||
const exclude_keys = ['answer_text', 'id', 'answer_text_list']
|
||||
Object.keys(res.data).forEach((key) => {
|
||||
if (!exclude_keys.includes(key)) {
|
||||
row[key] = res.data[key]
|
||||
}
|
||||
chatLogApi
|
||||
.getChatRecordDetails(id || props.appId, row.chat_id, row.record_id, loading)
|
||||
.then((res) => {
|
||||
const exclude_keys = ['answer_text', 'id', 'answer_text_list']
|
||||
Object.keys(res.data).forEach((key) => {
|
||||
if (!exclude_keys.includes(key)) {
|
||||
row[key] = res.data[key]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -617,11 +606,11 @@ watch(
|
|||
() => {
|
||||
handleScroll()
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
{ deep: true, immediate: true },
|
||||
)
|
||||
|
||||
defineExpose({
|
||||
setScrollBottom
|
||||
setScrollBottom,
|
||||
})
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ const modelValue = computed({
|
|||
},
|
||||
get: () => {
|
||||
return props.modelValue
|
||||
}
|
||||
},
|
||||
})
|
||||
const { model } = useStore()
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ export const postStream: (url: string, data?: unknown) => Promise<Result<any> |
|
|||
const language = user.getLanguage()
|
||||
const headers: HeadersInit = { 'Content-Type': 'application/json' }
|
||||
if (token) {
|
||||
headers['AUTHORIZATION'] = `${token}`
|
||||
headers['AUTHORIZATION'] = `Bearer ${token}`
|
||||
}
|
||||
headers['Accept-Language'] = `${language}`
|
||||
return fetch(url, {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import applicationApi from '@/api/application/application'
|
||||
import knowledgeAPI from '@/api/knowledge/knowledge.ts'
|
||||
import applicationXpackApi from '@/api/application/application-xpack'
|
||||
import { type Ref } from 'vue'
|
||||
import { getBrowserLang } from '@/locales/index'
|
||||
|
|
@ -37,8 +38,8 @@ const useApplicationStore = defineStore('application', {
|
|||
|
||||
async asyncGetApplicationKnowledge(id: string, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
applicationApi
|
||||
.getApplicationDataset(id, loading)
|
||||
knowledgeAPI
|
||||
.getAllKnowledge(loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -465,6 +465,7 @@ import ParamSettingDialog from './component/ParamSettingDialog.vue'
|
|||
import AddKnowledgeDialog from './component/AddKnowledgeDialog.vue'
|
||||
import EditAvatarDialog from '@/views/application-overview/component/EditAvatarDialog.vue'
|
||||
import applicationApi from '@/api/application/application'
|
||||
import modelAPI from '@/api/model/model.ts'
|
||||
import { isAppIcon } from '@/utils/common'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import type { ApplicationFormType } from '@/api/type/application'
|
||||
|
|
@ -671,8 +672,8 @@ function getKnowledge() {
|
|||
|
||||
function getModel() {
|
||||
loading.value = true
|
||||
applicationApi
|
||||
.getApplicationModel(id)
|
||||
modelAPI
|
||||
.getModel({})
|
||||
.then((res: any) => {
|
||||
modelOptions.value = groupBy(res?.data, 'provider')
|
||||
loading.value = false
|
||||
|
|
@ -684,7 +685,7 @@ function getModel() {
|
|||
|
||||
function getSTTModel() {
|
||||
loading.value = true
|
||||
applicationApi
|
||||
modelAPI
|
||||
.getApplicationSTTModel(id)
|
||||
.then((res: any) => {
|
||||
sttModelOptions.value = groupBy(res?.data, 'provider')
|
||||
|
|
@ -697,7 +698,7 @@ function getSTTModel() {
|
|||
|
||||
function getTTSModel() {
|
||||
loading.value = true
|
||||
applicationApi
|
||||
modelAPI
|
||||
.getApplicationTTSModel(id)
|
||||
.then((res: any) => {
|
||||
ttsModelOptions.value = groupBy(res?.data, 'provider')
|
||||
|
|
@ -718,14 +719,14 @@ function ttsModelChange() {
|
|||
|
||||
function ttsModelEnableChange() {
|
||||
if (!applicationForm.value.tts_model_enable) {
|
||||
applicationForm.value.tts_model_id = ''
|
||||
applicationForm.value.tts_model_id = undefined
|
||||
applicationForm.value.tts_type = 'BROWSER'
|
||||
}
|
||||
}
|
||||
|
||||
function sttModelEnableChange() {
|
||||
if (!applicationForm.value.stt_model_enable) {
|
||||
applicationForm.value.stt_model_id = ''
|
||||
applicationForm.value.stt_model_id = undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -741,11 +742,12 @@ function refresh() {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
// getModel()
|
||||
getModel()
|
||||
// todo
|
||||
// getKnowledge()
|
||||
// getDetail()
|
||||
// getSTTModel()
|
||||
// getTTSModel()
|
||||
getDetail()
|
||||
getSTTModel()
|
||||
getTTSModel()
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ const form_data = ref<any>({})
|
|||
const dialogVisible = ref(false)
|
||||
const loading = ref(false)
|
||||
const getApi = (model_id: string, application_id?: string) => {
|
||||
return application_id
|
||||
? applicationApi.getModelParamsForm(application_id, model_id, loading)
|
||||
: modelAPi.getModelParamsForm(model_id, loading)
|
||||
return modelAPi.getModelParamsForm(model_id, loading)
|
||||
}
|
||||
const open = (model_id: string, application_id?: string, model_setting_data?: any) => {
|
||||
form_data.value = {}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<el-form label-position="top" ref="paramFormRef" :model="form" v-loading="loading">
|
||||
<el-form-item :label="$t('views.application.dialog.selectSearchMode')">
|
||||
<el-radio-group
|
||||
v-model="form.dataset_setting.search_mode"
|
||||
v-model="form.knowledge_setting.search_mode"
|
||||
class="card__radio"
|
||||
@change="changeHandle"
|
||||
>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
<el-card
|
||||
shadow="never"
|
||||
class="mb-16"
|
||||
:class="form.dataset_setting.search_mode === 'keywords' ? 'active' : ''"
|
||||
:class="form.knowledge_setting.search_mode === 'keywords' ? 'active' : ''"
|
||||
>
|
||||
<el-radio value="keywords" size="large">
|
||||
<p class="mb-4">
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
</el-card>
|
||||
<el-card
|
||||
shadow="never"
|
||||
:class="form.dataset_setting.search_mode === 'blend' ? 'active' : ''"
|
||||
:class="form.knowledge_setting.search_mode === 'blend' ? 'active' : ''"
|
||||
>
|
||||
<el-radio value="blend" size="large">
|
||||
<p class="mb-4">
|
||||
|
|
@ -79,9 +79,9 @@
|
|||
</div>
|
||||
</template>
|
||||
<el-input-number
|
||||
v-model="form.dataset_setting.similarity"
|
||||
v-model="form.knowledge_setting.similarity"
|
||||
:min="0"
|
||||
:max="form.dataset_setting.search_mode === 'blend' ? 2 : 1"
|
||||
:max="form.knowledge_setting.search_mode === 'blend' ? 2 : 1"
|
||||
:precision="3"
|
||||
:step="0.1"
|
||||
:value-on-clear="0"
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
<el-col :span="12">
|
||||
<el-form-item :label="$t('views.application.dialog.topReferences')">
|
||||
<el-input-number
|
||||
v-model="form.dataset_setting.top_n"
|
||||
v-model="form.knowledge_setting.top_n"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:value-on-clear="1"
|
||||
|
|
@ -106,7 +106,7 @@
|
|||
|
||||
<el-form-item :label="$t('views.application.dialog.maxCharacters')">
|
||||
<el-slider
|
||||
v-model="form.dataset_setting.max_paragraph_char_number"
|
||||
v-model="form.knowledge_setting.max_paragraph_char_number"
|
||||
show-input
|
||||
:show-input-controls="false"
|
||||
:min="500"
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
class="w-full"
|
||||
>
|
||||
<el-radio-group
|
||||
v-model="form.dataset_setting.no_references_setting.status"
|
||||
v-model="form.knowledge_setting.no_references_setting.status"
|
||||
class="radio-block-avatar"
|
||||
>
|
||||
<el-radio value="ai_questioning">
|
||||
|
|
@ -140,7 +140,9 @@
|
|||
<el-radio value="designated_answer">
|
||||
<p>{{ $t('views.application.dialog.provideAnswer') }}</p>
|
||||
<el-form-item
|
||||
v-if="form.dataset_setting.no_references_setting.status === 'designated_answer'"
|
||||
v-if="
|
||||
form.knowledge_setting.no_references_setting.status === 'designated_answer'
|
||||
"
|
||||
prop="designated_answer"
|
||||
>
|
||||
<el-input
|
||||
|
|
@ -205,34 +207,34 @@ const noReferencesformRef = ref()
|
|||
const defaultValue = {
|
||||
ai_questioning: '{question}',
|
||||
// @ts-ignore
|
||||
designated_answer: t('views.application.dialog.designated_answer')
|
||||
designated_answer: t('views.application.dialog.designated_answer'),
|
||||
}
|
||||
|
||||
const defaultPrompt =
|
||||
t('views.application.dialog.defaultPrompt1', {
|
||||
question: '{question}'
|
||||
question: '{question}',
|
||||
}) +
|
||||
'<data></data>' +
|
||||
t('views.application.dialog.defaultPrompt2')
|
||||
|
||||
const form = ref<any>({
|
||||
dataset_setting: {
|
||||
knowledge_setting: {
|
||||
search_mode: 'embedding',
|
||||
top_n: 3,
|
||||
similarity: 0.6,
|
||||
max_paragraph_char_number: 5000,
|
||||
no_references_setting: {
|
||||
status: 'ai_questioning',
|
||||
value: '{question}'
|
||||
}
|
||||
value: '{question}',
|
||||
},
|
||||
},
|
||||
problem_optimization: false,
|
||||
problem_optimization_prompt: defaultPrompt
|
||||
problem_optimization_prompt: defaultPrompt,
|
||||
})
|
||||
|
||||
const noReferencesform = ref<any>({
|
||||
ai_questioning: defaultValue['ai_questioning'],
|
||||
designated_answer: defaultValue['designated_answer']
|
||||
designated_answer: defaultValue['designated_answer'],
|
||||
})
|
||||
|
||||
const noReferencesRules = reactive<FormRules<any>>({
|
||||
|
|
@ -240,16 +242,16 @@ const noReferencesRules = reactive<FormRules<any>>({
|
|||
{
|
||||
required: true,
|
||||
message: t('views.application.form.aiModel.placeholder'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
designated_answer: [
|
||||
{
|
||||
required: true,
|
||||
message: t('views.application.form.prompt.requiredMessage'),
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
|
@ -260,7 +262,7 @@ const isWorkflowType = ref(false)
|
|||
watch(dialogVisible, (bool) => {
|
||||
if (!bool) {
|
||||
// form.value = {
|
||||
// dataset_setting: {
|
||||
// knowledge_setting: {
|
||||
// search_mode: 'embedding',
|
||||
// top_n: 3,
|
||||
// similarity: 0.6,
|
||||
|
|
@ -275,7 +277,7 @@ watch(dialogVisible, (bool) => {
|
|||
// }
|
||||
noReferencesform.value = {
|
||||
ai_questioning: defaultValue['ai_questioning'],
|
||||
designated_answer: defaultValue['designated_answer']
|
||||
designated_answer: defaultValue['designated_answer'],
|
||||
}
|
||||
noReferencesformRef.value?.clearValidate()
|
||||
}
|
||||
|
|
@ -284,13 +286,13 @@ watch(dialogVisible, (bool) => {
|
|||
const open = (data: any, type?: string) => {
|
||||
isWorkflowType.value = isWorkFlow(type)
|
||||
form.value = {
|
||||
dataset_setting: { ...data.dataset_setting },
|
||||
knowledge_setting: { ...data.knowledge_setting },
|
||||
problem_optimization: data.problem_optimization,
|
||||
problem_optimization_prompt: data.problem_optimization_prompt
|
||||
problem_optimization_prompt: data.problem_optimization_prompt,
|
||||
}
|
||||
if (!isWorkflowType.value) {
|
||||
noReferencesform.value[form.value.dataset_setting.no_references_setting.status] =
|
||||
form.value.dataset_setting.no_references_setting.value
|
||||
noReferencesform.value[form.value.knowledge_setting.no_references_setting.status] =
|
||||
form.value.knowledge_setting.no_references_setting.value
|
||||
}
|
||||
|
||||
dialogVisible.value = true
|
||||
|
|
@ -305,8 +307,8 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||
if (!formEl) return
|
||||
await formEl.validate((valid, fields) => {
|
||||
if (valid) {
|
||||
form.value.dataset_setting.no_references_setting.value =
|
||||
noReferencesform.value[form.value.dataset_setting.no_references_setting.status]
|
||||
form.value.knowledge_setting.no_references_setting.value =
|
||||
noReferencesform.value[form.value.knowledge_setting.no_references_setting.status]
|
||||
emit('refresh', form.value)
|
||||
dialogVisible.value = false
|
||||
}
|
||||
|
|
@ -316,9 +318,9 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||
|
||||
function changeHandle(val: string) {
|
||||
if (val === 'keywords') {
|
||||
form.value.dataset_setting.similarity = 0
|
||||
form.value.knowledge_setting.similarity = 0
|
||||
} else {
|
||||
form.value.dataset_setting.similarity = 0.6
|
||||
form.value.knowledge_setting.similarity = 0.6
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue