Skip to content

Commit

Permalink
fix: open api error
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Nov 16, 2023
1 parent 026fc44 commit a0324ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/components/stateless/ReMarkdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import 'highlight.js/styles/github.css'
import styles from './index.module.less'

const PreCode = (props) => {
console.log('props.children', props.children)
const ref = useRef(null)
const refText = ref.current?.innerText
console.log('refText', refText)
const [mermaidCode, setMermaidCode] = useState('')

const renderMermaid = useDebouncedCallback(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/stateless/ReMarkdown/index.module.less
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.markdownBody {
background: #282c34;
padding: 10px;
padding: 5px;
color: #fff;
border-radius: 5px;
}

.copyBtn {
margin: 10px 10px 5px;
margin: 5px 10px;
text-align: right;
cursor: pointer;
}
Expand Down
23 changes: 14 additions & 9 deletions src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ const Home = () => {
const contentType = response.headers.get('content-type')

if (!response.ok || !contentType?.startsWith('text/event-stream') || response.status !== 200) {
if (contentType?.startsWith('text/plain')) {
setAiText(response.clone().text())
}
try {
if (contentType?.startsWith('text/html')) {
const textPlain = response.clone().text()
textPlain.then((plainText) => {
setAiText(plainText.toString())
})
} else if (contentType?.startsWith('text/plain')) {
const textPlain = response.clone().text()
textPlain.then((plainText) => {
setAiText(plainText.toString())
})
} else if (contentType?.startsWith('application/json')) {
const resJson = response.clone().json()
resJson.then((res) => {
setAiText(res.error.message)
setAiText(`${JSON.stringify(res)}`)
})
} catch (error) {
setAiText(error.message)
}
} else {
const reader = response?.body?.getReader()
Expand Down Expand Up @@ -99,7 +104,7 @@ const Home = () => {
const delta = json.choices[0]?.delta?.content ?? ''
lastText += delta
aiTextRef.current = lastText
setAiText(aiTextRef.current)
setAiText(aiTextRef.current.toString())
} catch (error) {
console.log(error)
}
Expand Down Expand Up @@ -147,7 +152,7 @@ const Home = () => {
</Flex>
</section>
{aiText ? (
<section style={{ background: '#282c34', color: '#fff', borderRadius: 4, padding: 10 }}>
<section style={{ background: '#282c34', color: '#fff', borderRadius: 4, padding: 5 }}>
{loading ? 'AI思考中...' : <ReMarkdown markdownText={aiText} />}
</section>
) : null}
Expand Down

1 comment on commit a0324ef

@vercel
Copy link

@vercel vercel bot commented on a0324ef Nov 16, 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.vercel.app
pro-react-admin-wkylin.vercel.app
pro-react-admin-git-main-wkylin.vercel.app

Please sign in to comment.