Skip to content

Commit 7f77040

Browse files
authored
feat: PDF Preview (#3502)
1 parent b52c972 commit 7f77040

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

apps/application/sql/list_knowledge_paragraph_by_paragraph_id.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SELECT
33
knowledge."name" AS "knowledge_name",
44
knowledge."type" AS "knowledge_type",
55
"document"."name" AS "document_name",
6-
"document"."meta" AS "meta",
6+
"document"."meta"::json AS "meta",
77
"document"."hit_handling_method" AS "hit_handling_method",
88
"document"."directly_return_similarity" as "directly_return_similarity"
99
FROM

apps/knowledge/serializers/document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ def get_paragraph_model(document_model, paragraph_list: List):
817817

818818
@staticmethod
819819
def get_document_paragraph_model(knowledge_id, instance: Dict):
820+
source_meta = {'source_file_id': instance.get('source_file_id')} if instance.get('source_file_id') else {}
820821
document_model = Document(
821822
**{
822823
'knowledge_id': knowledge_id,
@@ -826,7 +827,8 @@ def get_document_paragraph_model(knowledge_id, instance: Dict):
826827
lambda x, y: x + y,
827828
[len(p.get('content')) for p in instance.get('paragraphs', [])],
828829
0),
829-
'meta': instance.get('meta') if instance.get('meta') is not None else {},
830+
'meta': {**instance.get('meta'), **source_meta} if instance.get(
831+
'meta') is not None else source_meta,
830832
'type': instance.get('type') if instance.get('type') is not None else KnowledgeType.BASE
831833
})
832834

ui/src/components/ai-chat/component/answer-content/index.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class="content"
1010
@mouseup="openControl"
1111
:style="{
12-
'padding-right': showUserAvatar ? 'var(--padding-left)' : '0'
12+
'padding-right': showUserAvatar ? 'var(--padding-left)' : '0',
1313
}"
1414
>
1515
<el-card shadow="always" class="mb-8 border-r-8" style="--el-card-padding: 6px 16px">
@@ -46,7 +46,7 @@
4646
:executionIsRightPanel="props.executionIsRightPanel"
4747
@open-execution-detail="emit('openExecutionDetail')"
4848
@openParagraph="emit('openParagraph')"
49-
@openParagraphDocument="(val: string)=>emit('openParagraphDocument', val)"
49+
@openParagraphDocument="(val: string) => emit('openParagraphDocument', val)"
5050
v-if="showSource(chatRecord) && index === chatRecord.answer_text_list.length - 1"
5151
/>
5252
</el-card>
@@ -56,7 +56,7 @@
5656
class="content"
5757
:style="{
5858
'padding-left': showAvatar ? 'var(--padding-left)' : '0',
59-
'padding-right': showUserAvatar ? 'var(--padding-left)' : '0'
59+
'padding-right': showUserAvatar ? 'var(--padding-left)' : '0',
6060
}"
6161
>
6262
<OperationButton
@@ -92,7 +92,12 @@ const props = defineProps<{
9292
9393
const { user } = useStore()
9494
95-
const emit = defineEmits(['update:chatRecord', 'openExecutionDetail', 'openParagraph','openParagraphDocument'])
95+
const emit = defineEmits([
96+
'update:chatRecord',
97+
'openExecutionDetail',
98+
'openParagraph',
99+
'openParagraphDocument',
100+
])
96101
97102
const showAvatar = computed(() => {
98103
return user.isEnterprise() ? props.application.show_avatar : true
@@ -130,8 +135,8 @@ const answer_text_list = computed(() => {
130135
chat_record_id: undefined,
131136
child_node: undefined,
132137
runtime_node_id: undefined,
133-
reasoning_content: undefined
134-
}
138+
reasoning_content: undefined,
139+
},
135140
]
136141
} else if (item instanceof Array) {
137142
return item
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<template>
2-
<div>
3-
TODO 内容
2+
<div style="width: 100%; height: 100%">
3+
<embed v-if="is_pdf" style="width: 100%; height: 100%" :src="pdfSrc" />
44
</div>
55
</template>
66

7-
<script setup lang="ts"></script>
7+
<script setup lang="ts">
8+
import { computed } from 'vue'
9+
const props = defineProps<{
10+
detail?: any
11+
}>()
12+
const is_pdf = computed(() => {
13+
return props.detail?.meta?.source_file_id
14+
})
15+
const pdfSrc = computed(() => {
16+
return `${window.MaxKB.prefix}/oss/file/${props.detail?.meta?.source_file_id}`
17+
})
18+
</script>

ui/src/components/ai-chat/component/knowledge-source-component/index.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
<div class="flex-between">
1818
<div class="flex align-center">
1919
<img :src="getImgUrl(item && item?.document_name)" alt="" width="24" />
20-
<div class="ml-4 ellipsis-1" :title="item?.document_name" v-if="!item.source_url" @click="openParagraphDocument(item)">
20+
<div
21+
class="ml-4 ellipsis-1"
22+
:title="item?.document_name"
23+
v-if="!item.source_url"
24+
@click="openParagraphDocument(item)"
25+
>
2126
<p>{{ item && item?.document_name }}</p>
2227
</div>
2328
<div class="ml-8" v-else>
@@ -101,7 +106,7 @@ const props = defineProps({
101106
},
102107
})
103108
104-
const emit = defineEmits(['openExecutionDetail', 'openParagraph','openParagraphDocument'])
109+
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
105110
106111
const dialogVisible = ref(false)
107112
const dialogTitle = ref('')
@@ -134,9 +139,10 @@ function openExecutionDetail(row: any) {
134139
}
135140
function openParagraphDocument(row: any) {
136141
if (props.executionIsRightPanel) {
137-
emit('openParagraphDocument',row)
142+
emit('openParagraphDocument', row)
138143
return
139144
}
145+
140146
currentComponent.value = ParagraphDocumentContent
141147
dialogTitle.value = row.document_name
142148
currentChatDetail.value = row

ui/src/views/chat/pc/index.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<h4 v-show="!isPcCollapse">{{ applicationDetail?.name }}</h4>
3434
</div>
3535
<el-button
36-
size="large"
36+
size="large"
3737
type="primary"
3838
plain
3939
v-show="!isPcCollapse"
@@ -301,7 +301,7 @@
301301
:detail="executionDetail"
302302
:type="applicationDetail?.type"
303303
/>
304-
<ParagraphDocumentContent v-else />
304+
<ParagraphDocumentContent :detail="rightPanelDetail" v-else />
305305
</div>
306306
</el-splitter-panel>
307307
</el-splitter>
@@ -609,6 +609,7 @@ function openParagraphDocument(detail: any, row: any) {
609609
rightPanelTitle.value = row.document_name
610610
rightPanelType.value = 'paragraphDocument'
611611
rightPanelSize.value = 400
612+
rightPanelDetail.value = row
612613
}
613614
614615
function closeExecutionDetail() {
@@ -716,11 +717,11 @@ function closeExecutionDetail() {
716717
717718
.add-button {
718719
border: 1px solid var(--el-color-primary);
719-
background-color: #3370FF1A;
720-
color: #3370FF;
720+
background-color: #3370ff1a;
721+
color: #3370ff;
721722
font-weight: 500;
722723
&:hover {
723-
background-color: #3370FF33;
724+
background-color: #3370ff33;
724725
}
725726
}
726727
@@ -799,12 +800,13 @@ function closeExecutionDetail() {
799800
}
800801
801802
.chat-pc-popper {
802-
background: linear-gradient(187.61deg, rgba(235, 241, 255, 0.5) 39.6%, rgba(231, 249, 255, 0.5) 94.3%),
803-
#eef1f4 !important;
803+
background:
804+
linear-gradient(187.61deg, rgba(235, 241, 255, 0.5) 39.6%, rgba(231, 249, 255, 0.5) 94.3%),
805+
#eef1f4 !important;
804806
.el-menu {
805807
background: transparent;
806808
}
807-
.el-menu-item-group__title {
809+
.el-menu-item-group__title {
808810
padding-bottom: 16px;
809811
font-weight: 500;
810812
color: var(--app-text-color-secondary);
@@ -820,7 +822,7 @@ function closeExecutionDetail() {
820822
}
821823
&.is-active {
822824
background-color: #ffffff;
823-
825+
824826
color: var(--el-text-color-primary);
825827
& > div {
826828
font-weight: 500;

0 commit comments

Comments
 (0)