feat: 上限文联想改为前端进行

This commit is contained in:
ChenZhaoYu
2023-02-14 10:04:32 +08:00
parent 5d1f8519c2
commit 86fcbbff0b
6 changed files with 69 additions and 110 deletions

View File

@@ -1,35 +1,22 @@
import express from 'express'
import type { ChatContext } from './chatgpt'
import { chatReplayOne, chatReply, clearChatContext } from './chatgpt'
import { chatReply } from './chatgpt'
const app = express()
app.use(express.json())
app.all('*', (req, res, next) => {
app.all('*', (_, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Content-Type')
res.header('Access-Control-Allow-Methods', '*')
next()
})
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
app.post('/chat', async (req, res) => {
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)
const response = await chatReply(prompt, options)
res.send(response)
}
catch (error) {
@@ -37,7 +24,4 @@ app.post('./chatOne', async (req, res) => {
}
})
app.post('/clear', async (req, res) => {
const response = await clearChatContext()
res.send(response)
})
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))