@@ -135,7 +135,7 @@ router.post('/room-delete', auth, async (req, res) => {
135
135
}
136
136
} )
137
137
138
- router . get ( '/chat-hisroty ' , auth , async ( req , res ) => {
138
+ router . get ( '/chat-history ' , auth , async ( req , res ) => {
139
139
try {
140
140
const userId = req . headers . userId as string
141
141
const roomId = + req . query . roomId
@@ -179,6 +179,7 @@ router.get('/chat-hisroty', auth, async (req, res) => {
179
179
inversion : false ,
180
180
error : false ,
181
181
loading : false ,
182
+ responseCount : ( c . previousResponse ?. length ?? 0 ) + 1 ,
182
183
conversationOptions : {
183
184
parentMessageId : c . options . messageId ,
184
185
conversationId : c . options . conversationId ,
@@ -204,6 +205,66 @@ router.get('/chat-hisroty', auth, async (req, res) => {
204
205
}
205
206
} )
206
207
208
+ router . get ( '/chat-response-history' , auth , async ( req , res ) => {
209
+ try {
210
+ const userId = req . headers . userId as string
211
+ const roomId = + req . query . roomId
212
+ const uuid = + req . query . uuid
213
+ const index = + req . query . index
214
+ if ( ! roomId || ! await existsChatRoom ( userId , roomId ) ) {
215
+ res . send ( { status : 'Success' , message : null , data : [ ] } )
216
+ // res.send({ status: 'Fail', message: 'Unknow room', data: null })
217
+ return
218
+ }
219
+ const chat = await getChat ( roomId , uuid )
220
+ if ( chat . previousResponse === undefined || chat . previousResponse . length < index ) {
221
+ res . send ( { status : 'Fail' , message : 'Error' , data : [ ] } )
222
+ return
223
+ }
224
+ const response = index >= chat . previousResponse . length
225
+ ? chat
226
+ : chat . previousResponse [ index ]
227
+ const usage = response . options . completion_tokens
228
+ ? {
229
+ completion_tokens : response . options . completion_tokens || null ,
230
+ prompt_tokens : response . options . prompt_tokens || null ,
231
+ total_tokens : response . options . total_tokens || null ,
232
+ estimated : response . options . estimated || null ,
233
+ }
234
+ : undefined
235
+ res . send ( {
236
+ status : 'Success' ,
237
+ message : null ,
238
+ data : {
239
+ uuid : chat . uuid ,
240
+ dateTime : new Date ( chat . dateTime ) . toLocaleString ( ) ,
241
+ text : response . response ,
242
+ inversion : false ,
243
+ error : false ,
244
+ loading : false ,
245
+ responseCount : ( chat . previousResponse ?. length ?? 0 ) + 1 ,
246
+ conversationOptions : {
247
+ parentMessageId : response . options . messageId ,
248
+ conversationId : response . options . conversationId ,
249
+ } ,
250
+ requestOptions : {
251
+ prompt : chat . prompt ,
252
+ parentMessageId : response . options . parentMessageId ,
253
+ options : {
254
+ parentMessageId : response . options . messageId ,
255
+ conversationId : response . options . conversationId ,
256
+ } ,
257
+ } ,
258
+ usage,
259
+ } ,
260
+ } )
261
+ }
262
+ catch ( error ) {
263
+ console . error ( error )
264
+ res . send ( { status : 'Fail' , message : 'Load error' , data : null } )
265
+ }
266
+ } )
267
+
207
268
router . post ( '/chat-delete' , auth , async ( req , res ) => {
208
269
try {
209
270
const userId = req . headers . userId as string
@@ -296,9 +357,10 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
296
357
let { roomId, uuid, regenerate, prompt, options = { } , systemMessage, temperature, top_p } = req . body as RequestProps
297
358
const userId = req . headers . userId as string
298
359
const room = await getChatRoom ( userId , roomId )
360
+ if ( room == null )
361
+ global . console . error ( `Unable to get chat room \t ${ userId } \t ${ roomId } ` )
299
362
if ( room != null && isNotEmptyString ( room . prompt ) )
300
363
systemMessage = room . prompt
301
-
302
364
let lastResponse
303
365
let result
304
366
let message : ChatInfo
0 commit comments