@@ -4,7 +4,7 @@ import * as dotenv from 'dotenv'
4
4
import { ObjectId } from 'mongodb'
5
5
import type { RequestProps } from './types'
6
6
import type { ChatContext , ChatMessage } from './chatgpt'
7
- import { chatConfig , chatReplyProcess , containsSensitiveWords , getRandomApiKey , initAuditService } from './chatgpt'
7
+ import { abortChatProcess , chatConfig , chatReplyProcess , containsSensitiveWords , getRandomApiKey , initAuditService } from './chatgpt'
8
8
import { auth , getUserId } from './middleware/auth'
9
9
import { clearApiKeyCache , clearConfigCache , getApiKeys , getCacheApiKeys , getCacheConfig , getOriginConfig } from './storage/config'
10
10
import type { AuditConfig , CHATMODEL , ChatInfo , ChatOptions , Config , KeyConfig , MailConfig , SiteConfig , UsageResponse , UserInfo } from './storage/model'
@@ -431,6 +431,8 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
431
431
top_p,
432
432
chatModel : user . config . chatModel ,
433
433
key : await getRandomApiKey ( user , user . config . chatModel ) ,
434
+ userId,
435
+ messageId : message . _id . toString ( ) ,
434
436
} )
435
437
// return the whole response including usage
436
438
res . write ( `\n${ JSON . stringify ( result . data ) } ` )
@@ -457,13 +459,15 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
457
459
await updateChat ( message . _id as unknown as string ,
458
460
result . data . text ,
459
461
result . data . id ,
462
+ result . data . conversationId ,
460
463
result . data . detail ?. usage as UsageResponse ,
461
464
previousResponse as [ ] )
462
465
}
463
466
else {
464
467
await updateChat ( message . _id as unknown as string ,
465
468
result . data . text ,
466
469
result . data . id ,
470
+ result . data . conversationId ,
467
471
result . data . detail ?. usage as UsageResponse )
468
472
}
469
473
@@ -481,6 +485,23 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
481
485
}
482
486
} )
483
487
488
+ router . post ( '/chat-abort' , [ auth , limiter ] , async ( req , res ) => {
489
+ try {
490
+ const userId = req . headers . userId . toString ( )
491
+ const { text, messageId, conversationId } = req . body as { text : string ; messageId : string ; conversationId : string }
492
+ const msgId = await abortChatProcess ( userId )
493
+ await updateChat ( msgId ,
494
+ text ,
495
+ messageId ,
496
+ conversationId ,
497
+ null )
498
+ res . send ( { status : 'Success' , message : 'OK' , data : null } )
499
+ }
500
+ catch ( error ) {
501
+ res . send ( { status : 'Fail' , message : '重置邮件已发送 | Reset email has been sent' , data : null } )
502
+ }
503
+ } )
504
+
484
505
router . post ( '/user-register' , async ( req , res ) => {
485
506
try {
486
507
const { username, password } = req . body as { username : string ; password : string }
0 commit comments