@@ -135,7 +135,7 @@ router.post('/room-delete', auth, async (req, res) => {
135135 }
136136} )
137137
138- router . get ( '/chat-hisroty ' , auth , async ( req , res ) => {
138+ router . get ( '/chat-history ' , auth , async ( req , res ) => {
139139 try {
140140 const userId = req . headers . userId as string
141141 const roomId = + req . query . roomId
@@ -179,6 +179,7 @@ router.get('/chat-hisroty', auth, async (req, res) => {
179179 inversion : false ,
180180 error : false ,
181181 loading : false ,
182+ responseCount : ( c . previousResponse ?. length ?? 0 ) + 1 ,
182183 conversationOptions : {
183184 parentMessageId : c . options . messageId ,
184185 conversationId : c . options . conversationId ,
@@ -204,6 +205,66 @@ router.get('/chat-hisroty', auth, async (req, res) => {
204205 }
205206} )
206207
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+
207268router . post ( '/chat-delete' , auth , async ( req , res ) => {
208269 try {
209270 const userId = req . headers . userId as string
@@ -296,9 +357,10 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
296357 let { roomId, uuid, regenerate, prompt, options = { } , systemMessage, temperature, top_p } = req . body as RequestProps
297358 const userId = req . headers . userId as string
298359 const room = await getChatRoom ( userId , roomId )
360+ if ( room == null )
361+ global . console . error ( `Unable to get chat room \t ${ userId } \t ${ roomId } ` )
299362 if ( room != null && isNotEmptyString ( room . prompt ) )
300363 systemMessage = room . prompt
301-
302364 let lastResponse
303365 let result
304366 let message : ChatInfo
0 commit comments