2026-01-16 19:10:21 +08:00
|
|
|
|
<!--
|
|
|
|
|
|
FewShotDemo.vue
|
|
|
|
|
|
Few-shot 速懂:不给示例 vs 给示例,AI 的“风格”会不会稳定?
|
|
|
|
|
|
|
|
|
|
|
|
交互:
|
|
|
|
|
|
- 选择目标风格(随意/正式)
|
|
|
|
|
|
- 选择是否提供示例
|
|
|
|
|
|
- 看提示词和输出如何变化
|
|
|
|
|
|
-->
|
2026-01-15 20:10:19 +08:00
|
|
|
|
<template>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<el-card
|
|
|
|
|
|
class="few-shot-card"
|
|
|
|
|
|
shadow="hover"
|
|
|
|
|
|
>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<template #header>
|
|
|
|
|
|
<div class="card-header">
|
|
|
|
|
|
<div>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<h3 class="title">
|
|
|
|
|
|
示例的力量:让风格“跟你走”
|
|
|
|
|
|
</h3>
|
|
|
|
|
|
<p class="subtitle">
|
|
|
|
|
|
你不是让 AI 更聪明,而是让它更像你要的样子。
|
|
|
|
|
|
</p>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="controls">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<el-select
|
|
|
|
|
|
v-model="tone"
|
|
|
|
|
|
style="width: 140px"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
label="随意口语"
|
|
|
|
|
|
value="casual"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
label="正式书面"
|
|
|
|
|
|
value="formal"
|
|
|
|
|
|
/>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
<el-switch
|
|
|
|
|
|
v-model="withExamples"
|
|
|
|
|
|
active-text="提供示例"
|
|
|
|
|
|
inactive-text="无示例"
|
|
|
|
|
|
inline-prompt
|
|
|
|
|
|
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2026-01-16 19:10:21 +08:00
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</template>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<div class="grid-layout">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<el-card
|
|
|
|
|
|
shadow="never"
|
|
|
|
|
|
class="panel"
|
|
|
|
|
|
>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<template #header>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div class="panel-header">
|
|
|
|
|
|
提示词 / Prompt
|
|
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<div class="code-block">
|
|
|
|
|
|
<pre><code>{{ prompt }}</code></pre>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<el-card
|
|
|
|
|
|
shadow="never"
|
|
|
|
|
|
class="panel"
|
|
|
|
|
|
>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<template #header>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div class="panel-header">
|
|
|
|
|
|
AI 输出(示意)
|
|
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</template>
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div class="output-content">
|
|
|
|
|
|
{{ output }}
|
|
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<el-alert
|
|
|
|
|
|
:title="hint"
|
|
|
|
|
|
:type="withExamples ? 'success' : 'warning'"
|
|
|
|
|
|
show-icon
|
|
|
|
|
|
:closable="false"
|
|
|
|
|
|
style="margin-top: 16px;"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-card>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="withExamples"
|
|
|
|
|
|
class="examples-section"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-divider content-position="left">
|
|
|
|
|
|
示例(AI 会“照着学”)
|
|
|
|
|
|
</el-divider>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
<el-row :gutter="12">
|
2026-02-18 17:38:10 +08:00
|
|
|
|
<el-col
|
|
|
|
|
|
v-for="e in examples"
|
|
|
|
|
|
:key="e.in"
|
|
|
|
|
|
:span="8"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-card
|
|
|
|
|
|
shadow="hover"
|
|
|
|
|
|
class="example-item"
|
|
|
|
|
|
:body-style="{ padding: '12px' }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="ex-in">
|
|
|
|
|
|
输入:{{ e.in }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="ex-out">
|
|
|
|
|
|
输出:{{ e.out }}
|
|
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
</el-card>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-16 19:10:21 +08:00
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
const tone = ref('casual')
|
|
|
|
|
|
const withExamples = ref(true)
|
|
|
|
|
|
|
|
|
|
|
|
const examples = computed(() => {
|
|
|
|
|
|
if (tone.value === 'casual') {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ in: '你好', out: 'Hi~' },
|
|
|
|
|
|
{ in: '谢谢', out: '谢啦!' },
|
|
|
|
|
|
{ in: '再见', out: '拜拜~' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ in: '你好', out: '您好。' },
|
|
|
|
|
|
{ in: '谢谢', out: '非常感谢。' },
|
|
|
|
|
|
{ in: '再见', out: '再见,祝您一切顺利。' }
|
|
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const prompt = computed(() => {
|
|
|
|
|
|
const base = '将中文翻译成英文。'
|
|
|
|
|
|
const task = '输入:我很好'
|
|
|
|
|
|
if (!withExamples.value) return `${base}\n${task}`
|
|
|
|
|
|
const lines = [base, '示例:']
|
|
|
|
|
|
for (const e of examples.value) {
|
|
|
|
|
|
lines.push(`- ${e.in} -> ${e.out}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
lines.push(task)
|
|
|
|
|
|
return lines.join('\n')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const output = computed(() => {
|
|
|
|
|
|
if (!withExamples.value) {
|
|
|
|
|
|
return tone.value === 'casual' ? "I'm fine." : 'I am fine.'
|
|
|
|
|
|
}
|
|
|
|
|
|
return tone.value === 'casual' ? "I'm good!" : 'I am doing well.'
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const hint = computed(() => {
|
|
|
|
|
|
if (!withExamples.value) return '没有示例:AI 可能随便选一种语气。'
|
|
|
|
|
|
return '有示例:AI 更容易“保持同一种语气”。'
|
|
|
|
|
|
})
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-02-01 23:42:12 +08:00
|
|
|
|
.few-shot-card {
|
|
|
|
|
|
margin: 16px 0;
|
2026-01-16 19:10:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-01 23:42:12 +08:00
|
|
|
|
.card-header {
|
2026-01-18 12:21:49 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
align-items: flex-start;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
flex-wrap: wrap;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
gap: 16px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
2026-01-18 12:21:49 +08:00
|
|
|
|
.title {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
line-height: 1.4;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
2026-01-18 12:21:49 +08:00
|
|
|
|
.subtitle {
|
2026-02-01 23:42:12 +08:00
|
|
|
|
margin: 4px 0 0;
|
|
|
|
|
|
font-size: 14px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
2026-01-18 12:21:49 +08:00
|
|
|
|
.controls {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
gap: 16px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-01-16 19:10:21 +08:00
|
|
|
|
|
2026-02-01 23:42:12 +08:00
|
|
|
|
.grid-layout {
|
2026-01-18 12:21:49 +08:00
|
|
|
|
display: grid;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
|
|
gap: 20px;
|
|
|
|
|
|
margin-bottom: 24px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
.panel-header {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
font-size: 15px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
.code-block {
|
|
|
|
|
|
background-color: var(--vp-c-bg-alt);
|
|
|
|
|
|
border-radius: 4px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
padding: 12px;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
font-family: monospace;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
white-space: pre-wrap;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
.output-content {
|
|
|
|
|
|
background-color: var(--vp-c-bg-soft);
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
min-height: 60px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
white-space: pre-wrap;
|
2026-02-01 23:42:12 +08:00
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-01-16 19:10:21 +08:00
|
|
|
|
|
2026-02-01 23:42:12 +08:00
|
|
|
|
.example-item {
|
|
|
|
|
|
font-size: 13px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
.ex-in {
|
2026-01-18 12:21:49 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-01 23:42:12 +08:00
|
|
|
|
margin-bottom: 4px;
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-02-01 23:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
.ex-out {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
color: var(--vp-c-brand);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
|
.grid-layout {
|
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-header {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.controls {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
}
|
2026-01-18 12:21:49 +08:00
|
|
|
|
}
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</style>
|