IntentPanel.vue
5.48 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
<template>
<el-card class="panel" shadow="never">
<template #header>
<div class="header">
<div class="title">意图与示例</div>
<div class="header-right">
<el-select
v-model="selectedDatasetKey"
size="small"
class="dataset"
:loading="catalog.datasetLoading"
placeholder="选择数据集"
@change="onDatasetChange"
>
<el-option v-for="d in catalog.datasets" :key="d.key" :label="d.label" :value="d.key" />
</el-select>
<el-tag v-if="catalog.loading" type="info" effect="light">loading</el-tag>
<el-tag v-else type="success" effect="light">{{ catalog.intents.length }} intents</el-tag>
</div>
</div>
</template>
<el-tabs v-model="tab">
<el-tab-pane label="意图列表" name="intents">
<el-input v-model="q" placeholder="搜索意图 / 域 / 关键词" clearable />
<div v-if="catalog.error" class="error">{{ catalog.error }}</div>
<div class="intents">
<el-collapse v-model="openDomains">
<el-collapse-item
v-for="d in filteredDomains"
:key="d.domain"
:title="d.domain"
:name="d.domain"
>
<el-menu :default-active="selectedIntentName" class="menu" @select="onSelectIntent">
<el-menu-item v-for="i in d.items" :key="i.name" :index="i.name">
<div class="menu-item">
<span class="name">{{ i.name }}</span>
<span class="count">{{ i.examples.length }}</span>
</div>
</el-menu-item>
</el-menu>
</el-collapse-item>
</el-collapse>
</div>
<el-drawer v-model="detailOpen" size="420px" append-to-body="false">
<IntentDetail v-if="selectedIntent" :intent="selectedIntent" @use-example="onUseExample" />
<div v-else class="empty">选择一个意图查看详情</div>
</el-drawer>
</el-tab-pane>
<el-tab-pane label="用例集" name="cases">
<el-input v-model="caseQ" placeholder="搜索用例文本" clearable />
<el-table :data="filteredCases" size="small" height="520" border>
<el-table-column prop="message" label="message" min-width="220" show-overflow-tooltip />
<el-table-column prop="expected_intent" label="expected" width="160" show-overflow-tooltip />
</el-table>
</el-tab-pane>
</el-tabs>
</el-card>
</template>
<script setup lang="ts">
import { computed, ref, watchEffect } from "vue";
import { useCatalogStore } from "../../stores/catalog";
import IntentDetail from "./IntentDetail.vue";
const emit = defineEmits<{ (e: "use-example", text: string): void }>();
const catalog = useCatalogStore();
const tab = ref<"intents" | "cases">("intents");
const q = ref("");
const caseQ = ref("");
const selectedIntentName = ref<string>("");
const openDomains = ref<string[]>([]);
const detailOpen = ref(false);
const selectedDatasetKey = ref("");
watchEffect(() => {
if (!selectedDatasetKey.value && catalog.datasetKey) {
selectedDatasetKey.value = catalog.datasetKey;
}
if (openDomains.value.length === 0 && catalog.domains.length > 0) {
openDomains.value = catalog.domains.slice(0, 3).map((d) => d.domain);
}
if (!selectedIntentName.value && catalog.intents.length > 0) {
selectedIntentName.value = catalog.intents[0].name;
}
});
watchEffect(() => {
if (catalog.datasets.length === 0 && !catalog.datasetLoading) {
catalog.refreshDatasets();
}
});
function onSelectIntent(name: string): void {
selectedIntentName.value = name;
detailOpen.value = true;
}
async function onDatasetChange(key: string): Promise<void> {
await catalog.switchDataset(key);
openDomains.value = [];
selectedIntentName.value = "";
detailOpen.value = false;
}
const filteredDomains = computed(() => {
const needle = q.value.trim().toLowerCase();
if (!needle) return catalog.domains;
return catalog.domains
.map((d) => ({
domain: d.domain,
items: d.items.filter((i) => {
const hay = `${i.domain} ${i.name} ${i.embed_text} ${i.tree_text}`.toLowerCase();
return hay.includes(needle);
}),
}))
.filter((d) => d.items.length > 0);
});
const selectedIntent = computed(() => catalog.intents.find((i) => i.name === selectedIntentName.value) ?? null);
function onUseExample(text: string): void {
emit("use-example", text);
}
const filteredCases = computed(() => {
const needle = caseQ.value.trim().toLowerCase();
if (!needle) return catalog.cases;
return catalog.cases.filter((c) => c.message.toLowerCase().includes(needle));
});
</script>
<style scoped>
.panel {
height: 100%;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
}
.title {
font-weight: 600;
}
.header-right {
display: flex;
align-items: center;
gap: 8px;
}
.dataset {
width: 180px;
}
.error {
margin-top: 10px;
color: var(--el-color-danger);
}
.intents {
margin-top: 10px;
}
.menu {
border-right: none;
}
.menu-item {
width: 100%;
display: flex;
justify-content: space-between;
gap: 10px;
}
.name {
overflow: hidden;
text-overflow: ellipsis;
}
.count {
color: var(--el-text-color-secondary);
}
.empty {
padding: 14px;
border: 1px dashed var(--el-border-color);
border-radius: 10px;
color: var(--el-text-color-secondary);
}
:deep(.el-drawer__body) {
padding: 0;
}
:deep(.el-drawer__header) {
margin-bottom: 0;
}
</style>