Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/pages/chatgpt/fixSse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { SSE } from './sse'

const initSSE = (apiKey, apiContent) => {
// const source = new SSE(`https://api.openai.com/v1/chat/completions`, {
const source = new SSE(`https://api.zhizengzeng.com/v1/chat/completions`, {
const source = new SSE('https://api.zhizengzeng.com/v1/chat/completions', {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
Authorization: `Bearer ${apiKey}`
},
method: 'POST',
start: false,
Expand All @@ -15,10 +15,10 @@ const initSSE = (apiKey, apiContent) => {
messages: [
{
role: 'assistant',
content: apiContent,
},
],
}),
content: apiContent
}
]
})
})
return source
}
Expand Down
46 changes: 23 additions & 23 deletions src/pages/chatgpt/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ChatGpt = () => {
console.log('NOT DONE')
const payload = JSON.parse(e.data)
const {
delta: { content },
delta: { content }
} = payload?.choices[0] || { delta: { content: '' } }
if (content) {
apiResultRef.current += content
Expand Down Expand Up @@ -142,7 +142,7 @@ const ChatGpt = () => {
if (e.data !== '[DONE]') {
const payload = JSON.parse(e.data)
const {
delta: { content },
delta: { content }
} = payload?.choices[0] || { delta: { content: '' } }
if (content) {
structureResultRef.current += content
Expand All @@ -168,36 +168,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 @@ -215,15 +215,15 @@ const ChatGpt = () => {
items: [
{
key: '1',
label: '复制文本',
label: '复制文本'
},
{
key: '2',
label: '复制Markdown',
},
],
label: '复制Markdown'
}
]
}}
placement="bottom"
placement='bottom'
arrow
>
<Button>
Expand All @@ -241,7 +241,7 @@ const ChatGpt = () => {
minHeight: 150,
border: '1px solid #eee',
borderRadius: 4,
padding: 15,
padding: 15
}}
>
{/* {readyState === 0 && <h3>Loading...</h3>} */}
Expand All @@ -253,7 +253,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 @@ -266,18 +266,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
6 changes: 3 additions & 3 deletions src/pages/chatgpt/scrollBottom.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from 'react'

function AutoScrollSection({ messages }) {
function AutoScrollSection ({ messages }) {
const sectionRef = useRef(null)

useEffect(() => {
Expand All @@ -16,7 +16,7 @@ function AutoScrollSection({ messages }) {
height: 200,
overflowY: 'auto',
border: '1px solid #ccc',
padding: 8,
padding: 8
}}
>
{messages.map((msg, idx) => (
Expand All @@ -27,7 +27,7 @@ function AutoScrollSection({ messages }) {
}

// 使用示例
export default function Demo() {
export default function Demo () {
const [messages, setMessages] = React.useState(['Hello', 'World'])

// 模拟新消息
Expand Down
6 changes: 3 additions & 3 deletions src/pages/chatgpt/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @param {SSEOptions} options
* @return {SSE}
*/
var SSE = function (url, options) {
const SSE = function (url, options) {
if (!(this instanceof SSE)) {
return new SSE(url, options)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ var SSE = function (url, options) {

// consecutive 'data' is concatenated with newlines
if (field === 'data' && e[field] !== null) {
e['data'] += '\n' + value
e.data += '\n' + value
} else {
e[field] = value
}
Expand Down Expand Up @@ -346,7 +346,7 @@ var SSE = function (url, options) {
this.xhr.addEventListener('error', this._onStreamFailure.bind(this))
this.xhr.addEventListener('abort', this._onStreamAbort.bind(this))
this.xhr.open(this.method, this.url)
for (let header in this.headers) {
for (const header in this.headers) {
this.xhr.setRequestHeader(header, this.headers[header])
}
if (this.useLastEventId && this.lastEventId.length > 0) {
Expand Down
26 changes: 13 additions & 13 deletions src/pages/layout/proSecNav/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
QuestionCircleOutlined,
FireOutlined,
GlobalOutlined,
QrcodeOutlined,
QrcodeOutlined
} from '@ant-design/icons'

import styles from './index.module.less'
Expand All @@ -19,7 +19,7 @@ const pathSubmenu = {
'/home': ['home'],
'/coupons/add': ['/sub-act', '/sub-coupons'],
'/coupons/edit': ['/sub-act', '/sub-coupons'],
'/product': ['/sub-act', '/sub-coupons'],
'/product': ['/sub-act', '/sub-coupons']
}

const ProSecNav = () => {
Expand Down Expand Up @@ -103,41 +103,41 @@ const ProSecNav = () => {
icon: <FireOutlined />,
children: [
{ label: 'Vue', key: '/coupons/add' },
{ label: 'Angular', key: '/coupons/edit' },
],
{ label: 'Angular', key: '/coupons/edit' }
]
},
{
label: '后端技术栈',
key: '/product',
icon: <DeploymentUnitOutlined />,
},
],
icon: <DeploymentUnitOutlined />
}
]
},
{
label: '构建工具',
key: '/sub-list',
icon: <ApartmentOutlined />,
children: [
{ label: 'Webpack', key: '/coupons/list' },
{ label: 'Vite', key: '/order/list' },
],
{ label: 'Vite', key: '/order/list' }
]
},
{
label: 'Error',
key: '/sub-error',
icon: <QuestionCircleOutlined />,
children: [{ label: 'ErrorBoundary', key: '/error' }],
},
children: [{ label: 'ErrorBoundary', key: '/error' }]
}
]

return (
<Menu
mode="inline"
mode='inline'
defaultSelectedKeys={selectedKeys}
defaultOpenKeys={openKeys}
selectedKeys={selectedKeys}
openKeys={openKeys}
theme="light"
theme='light'
className={styles.menu}
onOpenChange={onOpenChange}
onSelect={onSelect}
Expand Down
Loading
Loading