Skip to content

Commit cb2a57b

Browse files
committed
fix: 增强知识图谱结果判断逻辑
- 在 `ToolResultRenderer.vue` 中,改进知识图谱结果的判断逻辑,增加对数据格式的验证,确保返回有效的三元组。 - 在 `agent.js` 中,添加用户权限检查,确保只有管理员可以加载智能体配置。
1 parent 9271009 commit cb2a57b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

web/src/components/ToolCallingResult/ToolResultRenderer.vue

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const parsedData = computed(() => {
7474
if (typeof props.resultContent === 'string') {
7575
try {
7676
return JSON.parse(props.resultContent)
77-
} catch {
77+
} catch (error) {
7878
return props.resultContent
7979
}
8080
}
@@ -138,15 +138,39 @@ const isImageResult = computed(() => {
138138
// 判断是否为知识图谱查询结果
139139
const isKnowledgeGraphResult = computed(() => {
140140
const toolNameLower = props.toolName.toLowerCase()
141-
const isGraphTool = toolNameLower.includes('graph') ||
142-
toolNameLower.includes('kg') ||
143-
toolNameLower.includes('query_knowledge_graph')
144141
145-
if (!isGraphTool) return false
142+
// 工具名称初步筛选 - 支持中英文关键词
143+
const hasGraphKeyword = toolNameLower.includes('graph') ||
144+
toolNameLower.includes('图谱') ||
145+
toolNameLower.includes('kg')
146146
147147
const data = parsedData.value
148-
// 支持新格式:包含nodes、edges、triples的对象
149-
return data && typeof data === 'object' && 'triples' in data && Array.isArray(data.triples)
148+
149+
// 数据格式验证 - 核心判断依据
150+
const hasBasicStructure = data && typeof data === 'object'
151+
const hasTriples = hasBasicStructure && 'triples' in data
152+
const triplesIsArray = hasTriples && Array.isArray(data.triples)
153+
const triplesHasContent = triplesIsArray && data.triples.length > 0
154+
155+
// 进一步验证triples数组的内容格式
156+
let triplesHasValidFormat = false
157+
if (triplesHasContent) {
158+
// 检查是否至少有一个有效的三元组
159+
triplesHasValidFormat = data.triples.some(triple => {
160+
return Array.isArray(triple) &&
161+
triple.length >= 3 &&
162+
triple.every(item => typeof item === 'string' && item.trim() !== '')
163+
})
164+
}
165+
166+
// 最终判断:数据格式符合规范优先,工具名称作为辅助判断
167+
// 1. 如果数据格式完全符合规范,直接认为是知识图谱结果
168+
if (hasBasicStructure && triplesIsArray && triplesHasContent && triplesHasValidFormat) {
169+
return true
170+
}
171+
172+
// 2. 如果数据格式基本符合且有相关关键词,也认为是知识图谱结果
173+
return hasTriples && triplesIsArray && hasGraphKeyword
150174
})
151175
152176
// 判断是否为计算器结果

web/src/stores/agent.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { defineStore } from 'pinia'
22
import { ref, computed } from 'vue'
33
import { agentApi } from '@/apis/agent_api'
44
import { handleChatError } from '@/utils/errorHandler'
5+
import { useUserStore } from '@/stores/user'
56

67
export const useAgentStore = defineStore('agent', () => {
8+
const userStore = useUserStore()
79
// ==================== 状态定义 ====================
810
// 智能体相关状态
911
const agents = ref([])
@@ -84,7 +86,9 @@ export const useAgentStore = defineStore('agent', () => {
8486
}
8587

8688
if (selectedAgentId.value) {
87-
await loadAgentConfig()
89+
if (userStore.isAdmin) {
90+
await loadAgentConfig()
91+
}
8892
await fetchTools()
8993
}
9094

@@ -161,6 +165,8 @@ export const useAgentStore = defineStore('agent', () => {
161165
* 加载智能体配置
162166
*/
163167
async function loadAgentConfig(agentId = null) {
168+
if (!userStore.isAdmin) return
169+
164170
const targetAgentId = agentId || selectedAgentId.value
165171
if (!targetAgentId) return
166172

@@ -308,4 +314,4 @@ export const useAgentStore = defineStore('agent', () => {
308314
storage: localStorage,
309315
paths: ['selectedAgentId', 'defaultAgentId']
310316
}
311-
})
317+
})

0 commit comments

Comments
 (0)