-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
197 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { useLastGptResponse } from '@src/utils/chat'; | ||
import { useState } from 'react'; | ||
import { useEffect } from 'react'; | ||
import { useSiloChat } from '@src/utils/chat'; | ||
import HumorExplainer from '@src/services/prompt/humor-explainer.txt?raw'; | ||
import InputControl from '@src/components/InputControl'; | ||
|
||
export default function () { | ||
const { loading, onSubmit, onStop } = useSiloChat(`${HumorExplainer}`); | ||
|
||
const [word, setWord] = useState('周四'); | ||
|
||
useEffect(() => { | ||
onStop(true); | ||
if (word) { | ||
setTimeout(() => { | ||
onSubmit(word); | ||
}, 16); | ||
} | ||
}, [word]); | ||
|
||
const modelResponses = useLastGptResponse(); | ||
const [activeIndex, setActiveIndex] = useState(0); | ||
const optionLength = modelResponses.length; | ||
const handleKeyDown = event => { | ||
setActiveIndex(prev => { | ||
let target = prev; | ||
if (event.key === 'ArrowLeft') { | ||
target--; | ||
} else if (event.key === 'ArrowRight') { | ||
target++; | ||
} | ||
target = Math.max(0, Math.min(target, optionLength - 1)); | ||
return target; | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('keydown', handleKeyDown); | ||
return () => { | ||
window.removeEventListener('keydown', handleKeyDown); | ||
}; | ||
}, [setActiveIndex, optionLength]); | ||
|
||
const content = modelResponses[activeIndex].message; | ||
console.log(content); | ||
const formattedContent = content.slice( | ||
content.indexOf('<'), | ||
content.lastIndexOf('>') | ||
); | ||
|
||
if (!modelResponses.length) return null; | ||
return ( | ||
<div className="flex-1 py-4 flex flex-col h-full w-full pb-[8px]"> | ||
<div className="flex-1 h-0 overflow-auto pb-4 relative text-sm leading-6 flex items-center justify-center"> | ||
{modelResponses[activeIndex] && ( | ||
<div | ||
className="max-w-96 mx-auto rounded overflow-hidden text-center" | ||
dangerouslySetInnerHTML={{ | ||
__html: formattedContent || content, | ||
}} | ||
></div> | ||
)} | ||
</div> | ||
|
||
<div className=" mt-[8px] flex-shrink-0 px-4 items-center flex"> | ||
<div className=" flex items-center relative flex-shrink-0 "> | ||
<div | ||
style={{ | ||
transform: `translateX(${activeIndex * (32 + 8)}px)`, | ||
}} | ||
className="absolute left-0 top-0 h-[32px] w-[32px] transform transition-transform duration-300 opacity-75 outline-primary outline outline-[2px] rounded-[4px]" | ||
></div> | ||
{modelResponses.map((response, index) => ( | ||
<div | ||
key={index} | ||
className={`cursor-pointer mr-[8px] p-[4px] transition-transform duration-300 select-none ${ | ||
activeIndex === index | ||
? ' overflow-hidden shadow-lg scale-105' | ||
: 'scale-100' | ||
}`} | ||
onClick={() => setActiveIndex(index)} | ||
> | ||
<img | ||
src={response.icon} | ||
alt={response.model} | ||
className={ | ||
'w-[24px] h-[24px] rounded-[4px] ' + | ||
(response.loading ? 'animate-pulse' : '') | ||
} | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
<div className="flex-1 relative flex-shrink-0 ml-2"> | ||
<InputControl | ||
placeholder="换个词吧" | ||
enter | ||
onStop={onStop} | ||
onSubmit={setWord} | ||
loading={loading} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 角色: | ||
你是新汉语老师,你年轻,批判现实,思考深刻,语言风趣"。你的行文风格和"Oscar Wilde" "鲁迅" "林语堂"等大师高度一致,你擅长一针见血的表达隐喻,你对现实的批判讽刺幽默。 | ||
|
||
- 作者:云中江树,李继刚 | ||
|
||
## 任务: | ||
用户将给你一个词汇,请将其进行全新角度的解释,你会用一个特殊视角来解释它: | ||
用一句话表达你的词汇解释,抓住用户输入词汇的本质,使用辛辣的讽刺、一针见血的指出本质,使用包含隐喻的金句。 | ||
例如:“委婉”: "刺向他人时, 决定在剑刃上撒上止痛药。" | ||
|
||
## 输出结果: | ||
|
||
1. <strong>请直接输出词语卡片的Html 代码,我将直接渲染它</strong> | ||
2. 不需要额外的解释,不要以任何标记语言包裹,包括 markdown | ||
|
||
- 整体设计合理使用留白,整体排版要有呼吸感 | ||
- 设计原则:干净 简洁 纯色 典雅 | ||
- 配色:下面的色系中随机选择一个[ | ||
"柔和粉彩系", | ||
"深邃宝石系", | ||
"清新自然系", | ||
"高雅灰度系", | ||
"复古怀旧系", | ||
"明亮活力系", | ||
"冷淡极简系", | ||
"海洋湖泊系", | ||
"秋季丰收系", | ||
"莫兰迪色系" | ||
] | ||
- 卡片样式: | ||
(字体 . ("KaiTi, SimKai" "Arial, sans-serif")) | ||
(颜色 . ((背景 "#FAFAFA") (标题 "#333") (副标题 "#555") (正文 "#333"))) | ||
(尺寸 . ((卡片宽度 "auto") (卡片高度 "auto, >宽度") (内边距 "20px"))) | ||
(布局 . (竖版 弹性布局 居中对齐)))) | ||
- 卡片元素: | ||
(标题 "汉语新解") | ||
(分隔线) | ||
(词语 用户输入) | ||
(拼音) | ||
(英文翻译) | ||
(日文翻译) | ||
(解释:(按现代诗排版)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default defineConfig({ | |
plugins: [react()], | ||
resolve: { | ||
alias: { | ||
'@': '/src' | ||
'@src': '/src' | ||
} | ||
} | ||
}) |