File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export class ChatResolver {
27
27
if ( chunk ) {
28
28
await this . chatService . saveMessage (
29
29
input . id ,
30
+ chunk . id ,
30
31
chunk . choices [ 0 ] . delta . content ,
31
32
) ;
32
33
yield chunk ;
@@ -38,6 +39,13 @@ export class ChatResolver {
38
39
}
39
40
}
40
41
42
+ @Query ( ( ) => Message , { nullable : true } )
43
+ async getMessageDetail (
44
+ @Args ( 'messageId' ) messageId : string ,
45
+ ) : Promise < Message > {
46
+ return this . chatService . getMessageById ( messageId ) ;
47
+ }
48
+
41
49
@Query ( ( ) => [ Message ] )
42
50
async getChatHistory ( @Args ( 'chatId' ) chatId : string ) : Promise < Message [ ] > {
43
51
return this . chatService . getChatHistory ( chatId ) ;
Original file line number Diff line number Diff line change @@ -158,6 +158,12 @@ export class ChatService {
158
158
return chat ? chat . messages : [ ] ;
159
159
}
160
160
161
+ async getMessageById ( messageId : string ) : Promise < Message > {
162
+ return await this . messageRepository . findOne ( {
163
+ where : { id : messageId } ,
164
+ } ) ;
165
+ }
166
+
161
167
async getChatDetails ( chatId : string ) : Promise < Chat > {
162
168
return this . chatRepository . findOne ( {
163
169
where : { id : chatId } ,
@@ -208,13 +214,18 @@ export class ChatService {
208
214
return null ;
209
215
}
210
216
211
- async saveMessage ( chatId : string , messageContent : string ) : Promise < Message > {
217
+ async saveMessage (
218
+ chatId : string ,
219
+ chunkId : string ,
220
+ messageContent : string ,
221
+ ) : Promise < Message > {
212
222
// Find the chat instance
213
223
const chat = await this . chatRepository . findOne ( { where : { id : chatId } } ) ;
214
224
if ( ! chat ) throw new Error ( 'Chat not found' ) ;
215
225
216
226
// Create a new message associated with the chat
217
227
const message = this . messageRepository . create ( {
228
+ id : chunkId ,
218
229
content : messageContent ,
219
230
role : Role . Model ,
220
231
chat,
You can’t perform that action at this time.
0 commit comments