feat: 统一服务端返回参数

This commit is contained in:
ChenZhaoYu
2023-02-13 15:08:55 +08:00
parent 73c9ac4d8f
commit dd522eb404
3 changed files with 87 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
import express from 'express'
import { chatReply, clearChatContext } from './chatgpt'
import type { ChatContext } from './chatgpt'
import { chatReplayOne, chatReply, clearChatContext } from './chatgpt'
const app = express()
@@ -15,9 +16,25 @@ app.all('*', (req, res, next) => {
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
app.post('/chat', async (req, res) => {
const { message } = req.body
const response = await chatReply(message)
res.send(response)
try {
const { prompt } = req.body as { prompt: string }
const response = await chatReply(prompt)
res.send(response)
}
catch (error) {
res.send(error)
}
})
app.post('./chatOne', async (req, res) => {
try {
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
const response = await chatReplayOne(prompt, options)
res.send(response)
}
catch (error) {
res.send(error)
}
})
app.post('/clear', async (req, res) => {