feat: 统一服务端返回参数
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user