fix: 增强知识图谱结果判断逻辑
- 在 `ToolResultRenderer.vue` 中,改进知识图谱结果的判断逻辑,增加对数据格式的验证,确保返回有效的三元组。 - 在 `agent.js` 中,添加用户权限检查,确保只有管理员可以加载智能体配置。
This commit is contained in:
parent
92710097ba
commit
cb2a57b2a1
@ -74,7 +74,7 @@ const parsedData = computed(() => {
|
||||
if (typeof props.resultContent === 'string') {
|
||||
try {
|
||||
return JSON.parse(props.resultContent)
|
||||
} catch {
|
||||
} catch (error) {
|
||||
return props.resultContent
|
||||
}
|
||||
}
|
||||
@ -138,15 +138,39 @@ const isImageResult = computed(() => {
|
||||
// 判断是否为知识图谱查询结果
|
||||
const isKnowledgeGraphResult = computed(() => {
|
||||
const toolNameLower = props.toolName.toLowerCase()
|
||||
const isGraphTool = toolNameLower.includes('graph') ||
|
||||
toolNameLower.includes('kg') ||
|
||||
toolNameLower.includes('query_knowledge_graph')
|
||||
|
||||
if (!isGraphTool) return false
|
||||
// 工具名称初步筛选 - 支持中英文关键词
|
||||
const hasGraphKeyword = toolNameLower.includes('graph') ||
|
||||
toolNameLower.includes('图谱') ||
|
||||
toolNameLower.includes('kg')
|
||||
|
||||
const data = parsedData.value
|
||||
// 支持新格式:包含nodes、edges、triples的对象
|
||||
return data && typeof data === 'object' && 'triples' in data && Array.isArray(data.triples)
|
||||
|
||||
// 数据格式验证 - 核心判断依据
|
||||
const hasBasicStructure = data && typeof data === 'object'
|
||||
const hasTriples = hasBasicStructure && 'triples' in data
|
||||
const triplesIsArray = hasTriples && Array.isArray(data.triples)
|
||||
const triplesHasContent = triplesIsArray && data.triples.length > 0
|
||||
|
||||
// 进一步验证triples数组的内容格式
|
||||
let triplesHasValidFormat = false
|
||||
if (triplesHasContent) {
|
||||
// 检查是否至少有一个有效的三元组
|
||||
triplesHasValidFormat = data.triples.some(triple => {
|
||||
return Array.isArray(triple) &&
|
||||
triple.length >= 3 &&
|
||||
triple.every(item => typeof item === 'string' && item.trim() !== '')
|
||||
})
|
||||
}
|
||||
|
||||
// 最终判断:数据格式符合规范优先,工具名称作为辅助判断
|
||||
// 1. 如果数据格式完全符合规范,直接认为是知识图谱结果
|
||||
if (hasBasicStructure && triplesIsArray && triplesHasContent && triplesHasValidFormat) {
|
||||
return true
|
||||
}
|
||||
|
||||
// 2. 如果数据格式基本符合且有相关关键词,也认为是知识图谱结果
|
||||
return hasTriples && triplesIsArray && hasGraphKeyword
|
||||
})
|
||||
|
||||
// 判断是否为计算器结果
|
||||
|
||||
@ -2,8 +2,10 @@ import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { agentApi } from '@/apis/agent_api'
|
||||
import { handleChatError } from '@/utils/errorHandler'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
export const useAgentStore = defineStore('agent', () => {
|
||||
const userStore = useUserStore()
|
||||
// ==================== 状态定义 ====================
|
||||
// 智能体相关状态
|
||||
const agents = ref([])
|
||||
@ -84,7 +86,9 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
}
|
||||
|
||||
if (selectedAgentId.value) {
|
||||
await loadAgentConfig()
|
||||
if (userStore.isAdmin) {
|
||||
await loadAgentConfig()
|
||||
}
|
||||
await fetchTools()
|
||||
}
|
||||
|
||||
@ -161,6 +165,8 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
* 加载智能体配置
|
||||
*/
|
||||
async function loadAgentConfig(agentId = null) {
|
||||
if (!userStore.isAdmin) return
|
||||
|
||||
const targetAgentId = agentId || selectedAgentId.value
|
||||
if (!targetAgentId) return
|
||||
|
||||
@ -308,4 +314,4 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
storage: localStorage,
|
||||
paths: ['selectedAgentId', 'defaultAgentId']
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user