Skip to content

Commit

Permalink
Merge branch 'feature/parse'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Mar 2, 2023
2 parents 3605c34 + a5b702c commit fed782f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"@unocss/reset": "^0.50.1",
"astro": "^2.0.15",
"eventsource-parser": "^0.1.0",
"highlight.js": "^11.7.0",
"katex": "^0.6.0",
"markdown-it": "^13.0.1",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-katex": "^2.0.3",
"solid-js": "^1.6.11"
},
"devDependencies": {
Expand Down
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/components/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export default () => {
continue
}
if (char) {
const textWithoutNewline = char.replace(/^\n+/, '')
setCurrentAssistantMessage(currentAssistantMessage() + textWithoutNewline)
setCurrentAssistantMessage(currentAssistantMessage() + char)
}
}
done = readerDone
Expand Down
6 changes: 4 additions & 2 deletions src/components/MessageItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Accessor } from 'solid-js'
import type { ChatMessage } from '../types'
import MarkdownIt from 'markdown-it'
// import Shiki from 'markdown-it-shiki'
// @ts-ignore
import mdKatex from 'markdown-it-katex'
import mdHighlight from 'markdown-it-highlightjs'

interface Props {
role: ChatMessage['role']
Expand All @@ -15,7 +17,7 @@ export default ({ role, message }: Props) => {
assistant: 'bg-gradient-to-r from-yellow-200 via-green-200 to-green-300',
}
const htmlString = () => {
const md = MarkdownIt()
const md = MarkdownIt().use(mdKatex).use(mdHighlight)

if (typeof message === 'function') {
return md.render(message())
Expand Down
2 changes: 0 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
import '../message.css'
export interface Props {
title: string;
}
Expand Down
5 changes: 5 additions & 0 deletions src/message.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.message pre {
background-color: #64748b10;
font-size: 0.8rem;
padding: 0.4rem 1rem;
}

.message .hljs {
background-color: transparent;
}

.message table {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Layout from '../layouts/Layout.astro'
import Header from '../components/Header.astro'
import Footer from '../components/Footer.astro'
import Generator from '../components/Generator'
import '../message.css'
import 'katex/dist/katex.min.css'
import 'highlight.js/styles/atom-one-dark.css'
---

<Layout title="ChatGPT API Demo">
Expand Down

0 comments on commit fed782f

Please sign in to comment.