Modified the prompt part Modified the minapp data part

This commit is contained in:
Aimer 2024-09-13 22:57:09 +08:00 committed by kangfenmao
parent 66210d1d2e
commit cb068d71ca
5 changed files with 75 additions and 11 deletions

View File

@ -29,5 +29,6 @@
}, },
"[markdown]": { "[markdown]": {
"files.trimTrailingWhitespace": false "files.trimTrailingWhitespace": false
} },
"i18n-ally.localesPaths": ["src/renderer/src/i18n"]
} }

View File

@ -90,7 +90,7 @@
"remark-math": "^6.0.0", "remark-math": "^6.0.0",
"sass": "^1.77.2", "sass": "^1.77.2",
"styled-components": "^6.1.11", "styled-components": "^6.1.11",
"typescript": "^5.3.3", "typescript": "^5.6.2",
"uuid": "^10.0.0", "uuid": "^10.0.0",
"vite": "^5.0.12" "vite": "^5.0.12"
}, },

View File

@ -40,6 +40,7 @@ export function createMainWindow() {
} }
}) })
mainWindow.webContents.openDevTools()
mainWindowState.manage(mainWindow) mainWindowState.manage(mainWindow)
mainWindow.webContents.on('context-menu', () => { mainWindow.webContents.on('context-menu', () => {

View File

@ -1,8 +1,10 @@
import 'emoji-picker-element' import 'emoji-picker-element'
import { LoadingOutlined, ThunderboltOutlined } from '@ant-design/icons'
import EmojiPicker from '@renderer/components/EmojiPicker' import EmojiPicker from '@renderer/components/EmojiPicker'
import { TopView } from '@renderer/components/TopView' import { TopView } from '@renderer/components/TopView'
import { useAgents } from '@renderer/hooks/useAgents' import { useAgents } from '@renderer/hooks/useAgents'
import { fetchGenerate } from '@renderer/services/api'
import { syncAgentToAssistant } from '@renderer/services/assistant' import { syncAgentToAssistant } from '@renderer/services/assistant'
import { Agent } from '@renderer/types' import { Agent } from '@renderer/types'
import { getLeadingEmoji, uuid } from '@renderer/utils' import { getLeadingEmoji, uuid } from '@renderer/utils'
@ -29,6 +31,8 @@ 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 onFinish = (values: FieldType) => { const onFinish = (values: FieldType) => {
const _emoji = emoji || getLeadingEmoji(values.name) const _emoji = emoji || getLeadingEmoji(values.name)
@ -81,6 +85,20 @@ const PopupContainer: React.FC<Props> = ({ agent, resolve }) => {
} }
}, [agent, form]) }, [agent, form])
const handleButtonClick = async () => {
const prompt = `你是一个专业的prompt优化助手我会给你一段prompt你需要帮我优化它仅回复优化后的prompt不要添加任何解释使用[CRISPE提示框架]回复。`
setLoading(true)
try {
const prefixedContent = `请帮我优化下面这段prompt使用CRISPE提示框架请使用Markdown格式回复: ${content}`
const generatedText = await fetchGenerate({ prompt, content: prefixedContent })
setContent(generatedText)
} catch (error) {
console.error('Error fetching data:', error)
} finally {
setLoading(false)
}
}
return ( return (
<Modal <Modal
title={agent ? t('agents.edit.title') : t('agents.add.title')} title={agent ? t('agents.edit.title') : t('agents.add.title')}
@ -108,7 +126,24 @@ const PopupContainer: React.FC<Props> = ({ agent, resolve }) => {
<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 }]}> <Form.Item name="prompt" label={t('agents.add.prompt')} rules={[{ required: true }]}>
<TextArea placeholder={t('agents.add.prompt.placeholder')} spellCheck={false} rows={10} /> <div style={{ position: 'relative' }}>
<TextArea
placeholder={t('agents.add.prompt.placeholder')}
spellCheck={false}
rows={10}
value={content}
onChange={(e) => setContent(e.target.value)}
/>
<Button
icon={loading ? <LoadingOutlined /> : <ThunderboltOutlined />}
style={{
position: 'absolute',
top: 8,
right: 8
}}
onClick={handleButtonClick}
disabled={loading}></Button>
</div>
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>

View File

@ -4,23 +4,50 @@ import { Center } from '@renderer/components/Layout'
import { getAllMinApps } from '@renderer/config/minapp' import { getAllMinApps } from '@renderer/config/minapp'
import { Empty, Input } from 'antd' import { Empty, Input } from 'antd'
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import { FC, useState } from 'react' import { FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
import App from './App' import App from './App'
const list = getAllMinApps() // 定义应用的类型
interface AppType {
id: string // 确保 id 是 string 类型
name: string
url: string
logo: string
sortOrder?: number // 可选属性
}
const AppsPage: FC = () => { const AppsPage: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const [search, setSearch] = useState('') const [search, setSearch] = useState('')
const [apps, setApps] = useState<AppType[]>([]) // 使用定义的类型
const apps = search useEffect(() => {
? list.filter( const list = getAllMinApps()
const processedList: AppType[] = list.map((app, index) => {
// 为每个应用添加 id 和排序编号
const id = app.id ? String(app.id) : app.name.toLowerCase() // 确保 id 是字符串
return {
...app,
id,
sortOrder: index + 1 // 排序编号从 1 开始
}
})
// 存储到本地存储
localStorage.setItem('minApps', JSON.stringify(processedList))
// 更新状态
setApps(processedList)
}, [])
const filteredApps = search
? apps.filter(
(app) => app.name.toLowerCase().includes(search.toLowerCase()) || app.url.includes(search.toLowerCase()) (app) => app.name.toLowerCase().includes(search.toLowerCase()) || app.url.includes(search.toLowerCase())
) )
: list : apps
return ( return (
<Container> <Container>
@ -42,10 +69,10 @@ const AppsPage: FC = () => {
</Navbar> </Navbar>
<ContentContainer> <ContentContainer>
<AppsContainer> <AppsContainer>
{apps.map((app) => ( {filteredApps.map((app) => (
<App key={app.name} app={app} /> <App key={app.id} app={app} />
))} ))}
{isEmpty(apps) && ( {isEmpty(filteredApps) && (
<Center style={{ flex: 1 }}> <Center style={{ flex: 1 }}>
<Empty /> <Empty />
</Center> </Center>