@@ -37,6 +37,7 @@ import {
3737 type LLMModelsManager ,
3838 type ModelVersion
3939} from './utils/llmModelsManager'
40+ import { conversationManager } from './utils/conversationManager'
4041
4142export abstract class LlmsBase implements PayableBot {
4243 public module : string
@@ -205,7 +206,8 @@ export abstract class LlmsBase implements PayableBot {
205206 id : ctx . message ?. message_id ,
206207 model,
207208 content : await preparePrompt ( ctx , prompt as string ) ,
208- numSubAgents : 0
209+ numSubAgents : 0 ,
210+ timestamp : Date . now ( )
209211 } )
210212 if ( ! session . isProcessingQueue ) {
211213 session . isProcessingQueue = true
@@ -218,7 +220,8 @@ export abstract class LlmsBase implements PayableBot {
218220 id : ctx . message ?. message_id ?? ctx . message ?. message_thread_id ?? 0 ,
219221 model,
220222 content : prompt as string ?? '' , // await preparePrompt(ctx, prompt as string),
221- numSubAgents : supportedAgents
223+ numSubAgents : supportedAgents ,
224+ timestamp : Date . now ( )
222225 }
223226 await this . runSubagents ( ctx , msg , stream , usesTools ) // prompt as string)
224227 }
@@ -230,6 +233,8 @@ export abstract class LlmsBase implements PayableBot {
230233
231234 async onChatRequestHandler ( ctx : OnMessageContext | OnCallBackQueryData , stream : boolean , usesTools : boolean ) : Promise < void > {
232235 const session = this . getSession ( ctx )
236+ session . chatConversation = conversationManager . manageConversationWindow ( session . chatConversation )
237+
233238 while ( session . requestQueue . length > 0 ) {
234239 try {
235240 const msg = session . requestQueue . shift ( )
@@ -272,7 +277,8 @@ export abstract class LlmsBase implements PayableBot {
272277 const chat : ChatConversation = {
273278 content : enhancedPrompt || prompt ,
274279 role : 'user' ,
275- model : modelVersion
280+ model : modelVersion ,
281+ timestamp : Date . now ( )
276282 }
277283 chatConversation . push ( chat )
278284 const payload = {
@@ -358,7 +364,8 @@ export abstract class LlmsBase implements PayableBot {
358364 conversation . push ( {
359365 role : 'assistant' ,
360366 content : completion . completion ?. content ?? '' ,
361- model
367+ model,
368+ timestamp : Date . now ( )
362369 } )
363370 return {
364371 price : price . price ,
@@ -371,7 +378,8 @@ export abstract class LlmsBase implements PayableBot {
371378 conversation . push ( {
372379 role : 'assistant' ,
373380 content : response . completion ?. content ?? '' ,
374- model
381+ model,
382+ timestamp : Date . now ( )
375383 } )
376384 return {
377385 price : response . price ,
0 commit comments