Skip to content

Commit 40f2e18

Browse files
committed
refactor: optimze text
1 parent 61aa7ab commit 40f2e18

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

components/SpringFestivalCouplets.vue

+1
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,6 @@ async function shareLink() {
155155
padding: 1.5rem 0.4rem 1.4rem 0.4rem;
156156
// 文字 gap
157157
letter-spacing: 1rem;
158+
white-space: nowrap;
158159
}
159160
</style>

packages/ai/src/api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export async function getCouplets(couplet: string) {
2424
'请根据我的提示生成一组春联,包含上联、下联各一句,每句字数在五到十三字之间,并附上一个恰当的横批。',
2525
'并给出一个字总结。',
2626
'不需要标点符号,尽量不要使用生僻字。',
27-
'以下述 JSON 给出:',
28-
`export interface SprintFestivalCouplets {
27+
'以可以被 JSON.parse 解析的字符串格式给出,务必不要生成多余文本。',
28+
`参考 TS 类型:export interface SprintFestivalCouplets {
2929
上联: string
3030
下联: string
3131
横批: string

server/api/generate.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ export default defineEventHandler(async (event) => {
77
const { content } = data
88

99
const unwrapperContent = (content || '{}')?.replace('```json\n', '').replace('```', '')
10-
const coupletData = JSON.parse(unwrapperContent) as SprintFestivalCouplets
10+
let coupletData: SprintFestivalCouplets | undefined
11+
try {
12+
coupletData = JSON.parse(unwrapperContent) as SprintFestivalCouplets
13+
}
14+
catch (e) {
15+
// eslint-disable-next-line no-console
16+
console.log(content)
17+
console.error(e)
18+
}
1119

1220
return coupletData
1321
})

0 commit comments

Comments
 (0)