mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 10:00:08 +08:00
style: improved formatting in add agent popup.
- Improved formatting of prompt and fetched generated text in Add Agent Popup.
This commit is contained in:
parent
cb068d71ca
commit
a173a87f29
@ -31,7 +31,6 @@ const PopupContainer: React.FC<Props> = ({ agent, resolve }) => {
|
|||||||
const { addAgent, updateAgent } = useAgents()
|
const { addAgent, updateAgent } = useAgents()
|
||||||
const formRef = useRef<FormInstance>(null)
|
const formRef = useRef<FormInstance>(null)
|
||||||
const [emoji, setEmoji] = useState(agent?.emoji)
|
const [emoji, setEmoji] = useState(agent?.emoji)
|
||||||
const [content, setContent] = useState('')
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
const onFinish = (values: FieldType) => {
|
const onFinish = (values: FieldType) => {
|
||||||
@ -87,16 +86,30 @@ const PopupContainer: React.FC<Props> = ({ agent, resolve }) => {
|
|||||||
|
|
||||||
const handleButtonClick = async () => {
|
const handleButtonClick = async () => {
|
||||||
const prompt = `你是一个专业的 prompt 优化助手,我会给你一段prompt,你需要帮我优化它,仅回复优化后的 prompt 不要添加任何解释,使用 [CRISPE提示框架] 回复。`
|
const prompt = `你是一个专业的 prompt 优化助手,我会给你一段prompt,你需要帮我优化它,仅回复优化后的 prompt 不要添加任何解释,使用 [CRISPE提示框架] 回复。`
|
||||||
|
|
||||||
|
const name = formRef.current?.getFieldValue('name')
|
||||||
|
const content = formRef.current?.getFieldValue('prompt')
|
||||||
|
const promptText = content || name
|
||||||
|
|
||||||
|
if (!promptText) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
navigator.clipboard.writeText(content)
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prefixedContent = `请帮我优化下面这段prompt,使用CRISPE提示框架,请使用Markdown格式回复: ${content}`
|
const prefixedContent = `请帮我优化下面这段 prompt,使用 CRISPE 提示框架,请使用 Markdown 格式回复,不要使用 codeblock: ${promptText}`
|
||||||
const generatedText = await fetchGenerate({ prompt, content: prefixedContent })
|
const generatedText = await fetchGenerate({ prompt, content: prefixedContent })
|
||||||
setContent(generatedText)
|
formRef.current?.setFieldValue('prompt', generatedText)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching data:', error)
|
console.error('Error fetching data:', error)
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -125,26 +138,21 @@ const PopupContainer: React.FC<Props> = ({ agent, resolve }) => {
|
|||||||
<Form.Item name="name" label={t('agents.add.name')} rules={[{ required: true }]}>
|
<Form.Item name="name" label={t('agents.add.name')} rules={[{ required: true }]}>
|
||||||
<Input placeholder={t('agents.add.name.placeholder')} spellCheck={false} allowClear />
|
<Input placeholder={t('agents.add.name.placeholder')} spellCheck={false} allowClear />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="prompt" label={t('agents.add.prompt')} rules={[{ required: true }]}>
|
|
||||||
<div style={{ position: 'relative' }}>
|
<div style={{ position: 'relative' }}>
|
||||||
<TextArea
|
<Form.Item
|
||||||
placeholder={t('agents.add.prompt.placeholder')}
|
name="prompt"
|
||||||
spellCheck={false}
|
label={t('agents.add.prompt')}
|
||||||
rows={10}
|
rules={[{ required: true }]}
|
||||||
value={content}
|
style={{ position: 'relative' }}>
|
||||||
onChange={(e) => setContent(e.target.value)}
|
<TextArea placeholder={t('agents.add.prompt.placeholder')} spellCheck={false} rows={10} />
|
||||||
/>
|
</Form.Item>
|
||||||
<Button
|
<Button
|
||||||
icon={loading ? <LoadingOutlined /> : <ThunderboltOutlined />}
|
icon={loading ? <LoadingOutlined /> : <ThunderboltOutlined />}
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 8,
|
|
||||||
right: 8
|
|
||||||
}}
|
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
disabled={loading}></Button>
|
style={{ position: 'absolute', top: 8, right: 8 }}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user