Skip to content

Commit

Permalink
feat: sse options
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Oct 25, 2023
1 parent 5677813 commit 541c66b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/pages/chatgpt/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ChatGpt = () => {
if (e.data !== '[DONE]') {
const payload = JSON.parse(e.data)
const {
delta: { content }
delta: { content },
} = payload.choices[0]
if (content) {
apiResultRef.current += content
Expand Down Expand Up @@ -125,7 +125,7 @@ const ChatGpt = () => {
if (e.data !== '[DONE]') {
const payload = JSON.parse(e.data)
const {
delta: { content }
delta: { content },
} = payload.choices[0]
if (content) {
structureResultRef.current += content
Expand All @@ -151,36 +151,36 @@ const ChatGpt = () => {
<section style={{ width: 600 }}>
<Form
form={form}
layout='vertical'
layout="vertical"
initialValues={{
apiKey: '',
text: '作为产品经理,帮我生成一份PRD文档,功能是公园入园人数大屏展示功能,采用 markdown 格式区分标题和正文,标题加上序号'
text: '作为产品经理,帮我生成一份PRD文档,功能是公园入园人数大屏展示功能,采用 markdown 格式区分标题和正文,标题加上序号',
}}
onFinish={onFinish}
requiredMark={false}
autoComplete='off'
autoComplete="off"
>
<Form.Item name='apiKey' label='OPEN AI KEY' rules={[{ required: true, message: '请输入open ai key' }]}>
<Form.Item name="apiKey" label="OPEN AI KEY" rules={[{ required: true, message: '请输入open ai key' }]}>
<Input.TextArea
onChange={onChange}
rows={1}
style={{ resize: 'none', padding: 2 }}
placeholder='open ai key'
placeholder="open ai key"
/>
</Form.Item>
<Form.Item name='text' label='您的输入' rules={[{ required: true, message: '请输您的需求' }]}>
<Form.Item name="text" label="您的输入" rules={[{ required: true, message: '请输您的需求' }]}>
<Input.TextArea
rows={4}
showCount
maxLength={1000}
style={{ resize: 'none', padding: 2 }}
placeholder=''
placeholder=""
onPressEnter={onFinish}
/>
</Form.Item>

<Form.Item wrapperCol={{ offset: 4, span: 16 }}>
<Button block type='primary' htmlType='submit' disabled={[0, 1].includes(readyState)}>
<Button block type="primary" htmlType="submit" disabled={[0, 1].includes(readyState)}>
{apiResult && readyState === 2 ? '再来一次' : 'ChatGPT'}
</Button>
</Form.Item>
Expand All @@ -198,15 +198,15 @@ const ChatGpt = () => {
items: [
{
key: '1',
label: '复制文本'
label: '复制文本',
},
{
key: '2',
label: '复制Markdown'
}
]
label: '复制Markdown',
},
],
}}
placement='bottom'
placement="bottom"
arrow
>
<Button>
Expand All @@ -228,7 +228,7 @@ const ChatGpt = () => {
<section>
{apiResult && readyState === 2 && (
<Space>
<Button type='primary' disabled={[0, 1].includes(structureReadyState)} onClick={buildStructure}>
<Button type="primary" disabled={[0, 1].includes(structureReadyState)} onClick={buildStructure}>
{structureResult && structureReadyState === 2 ? '重新生成' : '生成页面结构'}
</Button>

Expand All @@ -241,18 +241,18 @@ const ChatGpt = () => {
items: [
{
key: '1',
label: '导出png格式'
label: '导出png格式',
},
{
key: '2',
label: '导出svg格式'
}
]
label: '导出svg格式',
},
],
}}
placement='bottom'
placement="bottom"
arrow
>
<Button type='primary'>
<Button type="primary">
<DownloadOutlined />
导出
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/pages/chatgpt/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const initSSE = (apiKey, apiContent) => {
Authorization: `Bearer ${apiKey}`,
},
method: 'POST',
start: false,
payload: JSON.stringify({
model: 'gpt-3.5-turbo',
stream: true,
Expand Down

1 comment on commit 541c66b

@vercel
Copy link

@vercel vercel bot commented on 541c66b Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pro-react-admin – ./

pro-react-admin-git-main-wkylin.vercel.app
pro-react-admin.vercel.app
pro-react-admin-wkylin.vercel.app

Please sign in to comment.