Use chatgpt-api (#106)

* feat: use the latest api from chatgpt-api

* feat: use the latest api from chatgpt-api
This commit is contained in:
ikechan8370 2023-02-02 14:33:26 +08:00 committed by GitHub
parent 09e8909b51
commit bdafec9a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 174 additions and 23 deletions

View file

@ -0,0 +1,17 @@
import { remark } from 'remark'
import stripMarkdown from 'strip-markdown'
export function markdownToText (markdown) {
return remark()
.use(stripMarkdown)
.processSync(markdown ?? '')
.toString()
}
export async function upsertMessage (message) {
await redis.set(`CHATGPT:MESSAGE:${message.id}`, JSON.stringify(message))
}
export async function getMessageById (id) {
let messageStr = await redis.get(`CHATGPT:MESSAGE:${id}`)
return JSON.parse(messageStr)
}