Skip to content

Commit

Permalink
refactor: optimze text
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 4, 2024
1 parent 61aa7ab commit 40f2e18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/SpringFestivalCouplets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ async function shareLink() {
padding: 1.5rem 0.4rem 1.4rem 0.4rem;
// 文字 gap
letter-spacing: 1rem;
white-space: nowrap;
}
</style>
4 changes: 2 additions & 2 deletions packages/ai/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export async function getCouplets(couplet: string) {
'请根据我的提示生成一组春联,包含上联、下联各一句,每句字数在五到十三字之间,并附上一个恰当的横批。',
'并给出一个字总结。',
'不需要标点符号,尽量不要使用生僻字。',
'以下述 JSON 给出:',
`export interface SprintFestivalCouplets {
'以可以被 JSON.parse 解析的字符串格式给出,务必不要生成多余文本。',
`参考 TS 类型:export interface SprintFestivalCouplets {
上联: string
下联: string
横批: string
Expand Down
10 changes: 9 additions & 1 deletion server/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ export default defineEventHandler(async (event) => {
const { content } = data

const unwrapperContent = (content || '{}')?.replace('```json\n', '').replace('```', '')
const coupletData = JSON.parse(unwrapperContent) as SprintFestivalCouplets
let coupletData: SprintFestivalCouplets | undefined
try {
coupletData = JSON.parse(unwrapperContent) as SprintFestivalCouplets
}
catch (e) {
// eslint-disable-next-line no-console
console.log(content)
console.error(e)
}

return coupletData
})

0 comments on commit 40f2e18

Please sign in to comment.