-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathindex.vue
More file actions
243 lines (238 loc) · 7.64 KB
/
index.vue
File metadata and controls
243 lines (238 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<template>
<div class="chat-knowledge-source">
<div
class="flex align-center mt-16"
v-if="type === 'log' || type === 'debug-ai-chat' ? true : application.show_source"
>
<span class="mr-4 color-secondary">{{ $t('chat.KnowledgeSource.title') }}</span>
<el-divider direction="vertical" />
<el-button type="primary" class="mr-8" link @click="openParagraph(data)">
<AppIcon iconName="app-reference-outlined" class="mr-4"></AppIcon>
{{ $t('chat.KnowledgeSource.referenceParagraph') }}
{{ data.paragraph_list?.length || 0 }}</el-button
>
</div>
<div
class="mt-8"
v-if="type === 'log' || type === 'debug-ai-chat' ? true : application.show_source"
>
<el-row :gutter="8" v-if="uniqueParagraphList?.length">
<template v-for="(item, index) in uniqueParagraphList" :key="index">
<el-col :span="12" class="mb-8">
<el-card shadow="never" style="--el-card-padding: 8px">
<div class="flex-between">
<div class="flex align-center">
<img :src="getImgUrl(item && item?.document_name)" alt="" width="24" />
<div
class="ml-4 ellipsis-1"
:title="item?.document_name"
v-if="showPDF(item)"
@click="openParagraphDocument(item)"
>
<p>{{ item && item?.document_name }}</p>
</div>
<div
class="ml-4"
v-else-if="item?.meta?.source_file_id || item?.meta?.source_url"
>
<a
:href="getFileUrl(item?.meta?.source_file_id) || item?.meta?.source_url"
target="_blank"
class="ellipsis-1"
:title="item?.document_name?.trim()"
>
<span :title="item?.document_name?.trim()">{{ item?.document_name }}</span>
</a>
</div>
<div v-else @click="infoMessage(item)">
<span class="ellipsis-1 break-all" :title="item?.document_name?.trim()">
{{ item?.document_name?.trim() }}
</span>
</div>
</div>
</div>
</el-card>
</el-col>
</template>
</el-row>
</div>
<div
v-if="type === 'log' || type === 'debug-ai-chat' ? true : application.show_exec"
class="execution-details border-t color-secondary flex-between mt-12"
style="padding-top: 12px; padding-bottom: 8px"
>
<div>
<span class="mr-8">
{{ $t('chat.KnowledgeSource.consume') }}: {{ data?.message_tokens + data?.answer_tokens }}
</span>
<span>
{{ $t('chat.KnowledgeSource.consumeTime') }}: {{ data?.run_time?.toFixed(2) }} s</span
>
</div>
<el-button
type="primary"
link
@click="openExecutionDetail(data.execution_details)"
style="padding: 0"
>
<el-icon class="mr-4"><Document /></el-icon>
{{ $t('chat.executionDetails.title') }}</el-button
>
</div>
<!-- 知识库引用/执行详情 dialog -->
<el-dialog
class="scrollbar-dialog"
:title="dialogTitle"
v-model="dialogVisible"
destroy-on-close
append-to-body
align-center
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<template #header="{ titleId, titleClass }">
<div class="flex-between">
<span class="medium ellipsis" :title="dialogTitle" :id="titleId" :class="titleClass">
{{ dialogTitle }}
</span>
<!-- <div class="flex align-center mr-8" v-if="dialogType === 'pdfDocument'">
<span class="mr-4">
<el-button text>
<el-icon> <Download /> </el-icon>
</el-button>
</span>
<span>
<el-button text> <app-icon iconName="app-export" size="20" /></el-button>
</span>
<el-divider direction="vertical" />
</div> -->
</div>
</template>
<div class="mb-8">
<component
:is="currentComponent"
:detail="currentChatDetail"
:appType="appType"
></component>
</div>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { computed, ref, shallowRef } from 'vue'
import { cloneDeep } from 'lodash'
import ExecutionDetailContent from './ExecutionDetailContent.vue'
import ParagraphDocumentContent from './ParagraphDocumentContent.vue'
import ParagraphSourceContent from './ParagraphSourceContent.vue'
import { arraySort } from '@/utils/array'
import { getImgUrl, getFileUrl } from '@/utils/common'
import { t } from '@/locales'
import { MsgInfo } from '@/utils/message'
const props = defineProps({
data: {
type: Object,
default: () => {},
},
type: {
type: String,
default: '',
},
appType: {
type: String,
default: '',
},
executionIsRightPanel: {
type: Boolean,
required: false,
},
application: {
type: Object,
default: () => {},
},
})
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
const showPDF = (item: any) => {
return (
item.document_name.toLocaleLowerCase().endsWith('.pdf') &&
item.meta?.source_file_id &&
props.executionIsRightPanel
)
}
const dialogVisible = ref(false)
const dialogTitle = ref('')
const currentComponent = shallowRef<any>(null)
const currentChatDetail = ref<any>(null)
const dialogType = ref('')
function infoMessage(data: any) {
if (data?.meta?.allow_download === false) {
MsgInfo(t('chat.noPermissionDownload'))
} else {
MsgInfo(t('chat.noDocument'))
}
}
function openParagraph(row: any, id?: string) {
dialogTitle.value = t('chat.KnowledgeSource.title')
const obj = cloneDeep(row)
obj.paragraph_list = id
? obj.paragraph_list.filter((v: any) => v.knowledge_id === id)
: obj.paragraph_list
obj.paragraph_list = arraySort(obj.paragraph_list, 'similarity', true)
if (props.executionIsRightPanel) {
emit('openParagraph')
return
}
dialogType.value = ''
currentComponent.value = ParagraphSourceContent
currentChatDetail.value = obj
dialogVisible.value = true
}
function openExecutionDetail(row: any) {
dialogTitle.value = t('chat.executionDetails.title')
if (props.executionIsRightPanel) {
emit('openExecutionDetail')
return
}
dialogType.value = ''
currentComponent.value = ExecutionDetailContent
currentChatDetail.value = row
dialogVisible.value = true
}
function openParagraphDocument(row: any) {
if (props.executionIsRightPanel) {
emit('openParagraphDocument', row)
return
}
dialogType.value = 'pdfDocument'
currentComponent.value = ParagraphDocumentContent
dialogTitle.value = row.document_name
currentChatDetail.value = row
dialogVisible.value = true
}
const uniqueParagraphList = computed(() => {
const seen = new Set()
return (
props.data.paragraph_list?.filter((paragraph: any) => {
const key = paragraph.document_name.trim()
if (seen.has(key)) {
return false
}
seen.add(key)
// 判断如果 meta 属性不是 {} 需要json解析 转对象
if (paragraph.meta && typeof paragraph.meta === 'string') {
paragraph.meta = JSON.parse(paragraph.meta)
paragraph.source_url = paragraph.meta.source_url
}
return true
}) || []
)
})
</script>
<style lang="scss" scoped>
@media only screen and (max-width: 420px) {
.chat-knowledge-source {
.execution-details {
display: block;
}
}
}
</style>