ForcePilot/web/src/components/RefsComponent.vue

402 lines
9.2 KiB
Vue
Raw Normal View History

2024-08-25 20:29:24 +08:00
<template>
<div class="refs" v-if="showRefs">
<div class="tags">
<!-- <span class="item btn" @click="likeThisResponse(msg)"><LikeOutlined /></span> -->
<!-- <span class="item btn" @click="dislikeThisResponse(msg)"><DislikeOutlined /></span> -->
2025-02-24 22:56:13 +08:00
<span class="item"><BulbOutlined /> {{ msg.model_name }}</span>
2025-02-23 16:38:56 +08:00
<span class="item btn" @click="copyText(msg.text)"><CopyOutlined /></span>
2024-09-18 21:03:12 +08:00
<span
class="item btn"
@click="openSubGraph(msg)"
v-if="hasSubGraphData(msg)"
>
2025-02-24 22:56:13 +08:00
<DeploymentUnitOutlined /> 关系图
2024-09-18 21:03:12 +08:00
</span>
<span
class="item btn"
@click="showWebResult(msg)"
v-if="msg.refs?.web_search.results.length > 0"
>
<GlobalOutlined /> 网页搜索 {{ msg.refs.web_search?.results.length }}
</span>
2024-09-18 21:03:12 +08:00
<span class="filetag item btn"
v-for="(results, filename) in msg.groupedResults"
2024-08-25 20:29:24 +08:00
:key="filename"
2024-09-06 21:30:49 +08:00
@click="toggleDrawer(filename)"
2024-08-25 20:29:24 +08:00
>
<FileTextOutlined /> {{ filename }}
<a-drawer
2024-09-06 21:30:49 +08:00
v-model:open="openDetail[filename]"
2024-09-18 21:03:12 +08:00
:title="filename"
width="700"
2024-08-25 20:29:24 +08:00
:contentWrapperStyle="{ maxWidth: '100%'}"
placement="right"
class="retrieval-detail"
rootClassName="root"
>
<div class="fileinfo">
2024-09-18 21:03:12 +08:00
<p><FileOutlined /> {{ results[0].file.type }}</p>
<p><ClockCircleOutlined /> {{ formatDate(results[0].file.created_at) }}</p>
2024-08-25 20:29:24 +08:00
</div>
2024-09-18 21:03:12 +08:00
<div class="results-list">
<div v-for="res in results" :key="res.id" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相似度</strong>
<a-progress :percent="getPercent(res.distance)"/>
</span>
<span v-if="res.rerank_score">
<strong>重排序</strong>
<a-progress :percent="getPercent(res.rerank_score)"/>
</span>
</div>
<div class="result-id">ID: #{{ res.id }}</div>
2024-08-25 20:29:24 +08:00
</div>
2024-09-18 21:03:12 +08:00
<div class="result-text">{{ res.entity.text }}</div>
</div>
2024-08-25 20:29:24 +08:00
</div>
</a-drawer>
</span>
</div>
2024-09-18 21:03:12 +08:00
<a-modal
v-model:open="subGraphVisible"
title="相关实体与关系"
:width="800"
:footer="null"
>
<GraphContainer :graphData="subGraphData" />
</a-modal>
<a-drawer
v-model:open="webResultVisible"
title="网页搜索结果"
width="700"
:contentWrapperStyle="{ maxWidth: '100%'}"
placement="right"
class="web-result-detail"
rootClassName="root"
>
<div class="results-list">
<div v-for="result in webResults" :key="result.url" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相关度</strong>
<a-progress :percent="getPercent(result.score)"/>
</span>
</div>
<div class="result-url">
<a :href="result.url" target="_blank">{{ result.url }}</a>
</div>
</div>
<div class="result-content">
<h3 class="result-title">{{ result.title }}</h3>
<div class="result-text">{{ result.content }}</div>
</div>
</div>
</div>
</a-drawer>
2024-08-25 20:29:24 +08:00
</div>
</template>
<script setup>
2024-09-06 21:30:49 +08:00
import { ref, computed, reactive } from 'vue'
2024-09-18 21:03:12 +08:00
import { useClipboard } from '@vueuse/core'
import { message } from 'ant-design-vue'
2024-08-25 20:29:24 +08:00
import {
GlobalOutlined,
FileTextOutlined,
2024-09-18 21:03:12 +08:00
CopyOutlined,
LikeOutlined,
DislikeOutlined,
2025-02-24 22:56:13 +08:00
DeploymentUnitOutlined,
BulbOutlined,
2024-09-18 21:03:12 +08:00
FileOutlined,
ClockCircleOutlined
2024-08-25 20:29:24 +08:00
} from '@ant-design/icons-vue'
2024-09-18 21:03:12 +08:00
import GraphContainer from './GraphContainer.vue' // 导入 GraphContainer 组件
2024-08-25 20:29:24 +08:00
const props = defineProps({
message: Object,
})
2024-09-18 21:03:12 +08:00
const msg = ref(props.message)
// 使用 useClipboard 实现复制功能
const { copy, isSupported } = useClipboard()
// 定义 copy 方法
const copyText = async (text) => {
if (isSupported) {
try {
await copy(text)
message.success('文本已复制到剪贴板')
} catch (error) {
console.error('复制失败:', error)
message.error('复制失败,请手动复制')
}
} else {
console.warn('浏览器不支持自动复制')
message.warning('浏览器不支持自动复制,请手动复制')
}
}
// 其他方法
const likeThisResponse = (msg) => {
console.log('Like this response:', msg)
}
const dislikeThisResponse = (msg) => {
console.log('Dislike this response:', msg)
}
2024-08-25 20:29:24 +08:00
2024-09-06 21:30:49 +08:00
// 使用 reactive 创建一个响应式对象来存储每个文件的抽屉状态
const openDetail = reactive({})
// 初始化 openDetail 对象
2024-09-18 21:03:12 +08:00
for (const filename in msg.value.groupedResults) {
2024-09-06 21:30:49 +08:00
openDetail[filename] = false
}
const toggleDrawer = (filename) => {
openDetail[filename] = !openDetail[filename]
}
2024-09-18 21:03:12 +08:00
const showRefs = computed(() => msg.value.role=='received' && msg.value.status=='finished')
const subGraphVisible = ref(false)
const subGraphData = ref(null)
const openSubGraph = (msg) => {
if (hasSubGraphData(msg)) {
subGraphData.value = msg.refs.graph_base.results
subGraphVisible.value = true
} else {
console.error('无法获取子图数据')
}
}
const closeSubGraph = () => {
subGraphVisible.value = false
}
// 添加网页搜索结果相关变量
const webResultVisible = ref(false)
const webResults = ref(null)
// 添加显示网页搜索结果的方法
const showWebResult = (msg) => {
if (msg.refs?.web_search) {
webResults.value = msg.refs?.web_search.results
webResultVisible.value = true
} else {
console.error('无法获取网页搜索结果')
}
}
2024-09-18 21:03:12 +08:00
const hasSubGraphData = (msg) => {
return msg.refs &&
msg.refs.graph_base &&
msg.refs.graph_base.results.nodes.length > 0;
}
// 添加日期格式化函数
const formatDate = (timestamp) => {
return new Date(timestamp * 1000).toLocaleString()
}
// 添加百分比计算函数
const getPercent = (value) => {
return parseFloat((value * 100).toFixed(2))
}
2024-08-25 20:29:24 +08:00
</script>
<style lang="less" scoped>
.refs {
display: flex;
margin-bottom: 20px;
2024-09-28 00:41:02 +08:00
color: var(--gray-500);
2025-02-23 16:38:56 +08:00
font-size: 13px;
2024-08-25 20:29:24 +08:00
gap: 10px;
.item {
2024-09-28 00:41:02 +08:00
background: var(--gray-100);
2025-02-23 16:38:56 +08:00
color: var(--gray-700);
2024-08-25 20:29:24 +08:00
padding: 2px 8px;
border-radius: 8px;
2025-02-23 16:38:56 +08:00
font-size: 13px;
2024-09-28 00:41:02 +08:00
user-select: none;
2024-09-18 21:03:12 +08:00
&.btn {
cursor: pointer;
&:hover {
2024-09-28 00:41:02 +08:00
background: var(--gray-200);
2024-09-18 21:03:12 +08:00
}
&:active {
2024-09-28 00:41:02 +08:00
background: var(--gray-300);
2024-09-18 21:03:12 +08:00
}
}
2024-08-25 20:29:24 +08:00
}
.tags {
display: flex;
2024-09-06 12:54:17 +08:00
flex-wrap: wrap;
2024-08-25 20:29:24 +08:00
gap: 10px;
.filetag {
display: flex;
align-items: center;
gap: 5px;
}
}
}
.retrieval-detail {
.fileinfo {
2024-09-18 21:03:12 +08:00
display: flex;
justify-content: space-between;
padding: 12px 16px;
background-color: #f5f5f5;
border-radius: 4px;
margin-bottom: 16px;
2024-08-25 20:29:24 +08:00
p {
2024-09-18 21:03:12 +08:00
margin: 0;
color: #666;
2024-08-25 20:29:24 +08:00
}
}
2024-09-18 21:03:12 +08:00
.score-info {
display: flex;
flex-wrap: wrap;
gap: 2rem;
margin-bottom: 8px;
2024-08-25 20:29:24 +08:00
2024-09-18 21:03:12 +08:00
span {
display: flex;
align-items: center;
2024-08-25 20:29:24 +08:00
2024-09-18 21:03:12 +08:00
strong {
margin-right: 8px;
white-space: nowrap;
color: #666;
}
.ant-progress {
width: 170px;
margin-bottom: 0;
margin-inline: 10px;
2024-08-25 20:29:24 +08:00
2024-09-18 21:03:12 +08:00
.ant-progress-bg {
background-color: #666;
}
2024-08-25 20:29:24 +08:00
}
}
}
2024-09-18 21:03:12 +08:00
.result-id {
font-size: 12px;
color: #999;
margin-bottom: 8px;
}
.result-text {
font-size: 14px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
background-color: #f9f9f9;
padding: 12px;
border-radius: 4px;
border: 1px solid #e8e8e8;
}
}
.results-list {
.result-item {
border-bottom: 1px solid #f0f0f0;
padding: 16px 0;
&:last-child {
border-bottom: none;
}
}
.result-meta {
margin-bottom: 12px;
}
2024-08-25 20:29:24 +08:00
}
.web-result-detail {
.results-list {
.result-item {
border-bottom: 1px solid #f0f0f0;
padding: 16px 0;
&:last-child {
border-bottom: none;
}
}
.result-meta {
margin-bottom: 12px;
.score-info {
display: flex;
flex-wrap: wrap;
gap: 2rem;
margin-bottom: 8px;
span {
display: flex;
align-items: center;
strong {
margin-right: 8px;
white-space: nowrap;
color: #666;
}
.ant-progress {
width: 170px;
margin-bottom: 0;
margin-inline: 10px;
.ant-progress-bg {
background-color: #666;
}
}
}
}
.result-url {
font-size: 12px;
color: #1677FF;
margin-bottom: 8px;
word-break: break-all;
}
}
.result-content {
.result-title {
font-size: 16px;
font-weight: bold;
margin-bottom: 8px;
color: #333;
}
.result-text {
font-size: 14px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
background-color: #f9f9f9;
padding: 12px;
border-radius: 4px;
border: 1px solid #e8e8e8;
}
}
}
}
2024-09-18 21:03:12 +08:00
</style>