Skip to content

Commit 9842aae

Browse files
committed
20240717 @Mookse
- avatar update
1 parent 2923766 commit 9842aae

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

inc/js/mylife-avatar.mjs

+26-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class Avatar extends EventEmitter {
6868
: this.activeBot.bot_id
6969
return this
7070
}
71+
/**
72+
* Add a conversation to session memory.
73+
* @param {Conversation} conversation - The conversation object.
74+
*/
75+
addConversation(conversation){
76+
this.#conversations.push(conversation)
77+
}
7178
/**
7279
* Get a bot.
7380
* @public
@@ -185,7 +192,6 @@ class Avatar extends EventEmitter {
185192
*/
186193
async createConversation(type='chat', threadId, botId=this.activeBotId, saveToConversations=true){
187194
const bot = await this.bot(botId)
188-
console.log('createConversation::bot', botId, bot.bot_name, bot.type)
189195
const thread = await this.#llmServices.thread(threadId)
190196
const conversation = new (this.#factory.conversation)({ mbr_id: this.mbr_id, type, }, this.#factory, thread, botId)
191197
bot.thread_id = conversation.thread_id
@@ -197,7 +203,7 @@ class Avatar extends EventEmitter {
197203
thread_id,
198204
})
199205
if(saveToConversations)
200-
this.#conversations.push(conversation)
206+
this.addConversation(conversation)
201207
return conversation
202208
}
203209
/**
@@ -1125,7 +1131,7 @@ class Q extends Avatar {
11251131
throw new Error('factory parameter must be an instance of MyLifeFactory')
11261132
super(factory, llmServices)
11271133
this.#factory = factory
1128-
this.llmServices = llmServices
1134+
this.#llmServices = llmServices
11291135
}
11301136
/* overloaded methods */
11311137
/**
@@ -1147,14 +1153,30 @@ class Q extends Avatar {
11471153
?? this.activeBot.bot_id
11481154
conversation = await this.createConversation('system', undefined, activeBotId, true) // pushes to this.#conversations in Avatar
11491155
threadId = conversation.thread_id
1150-
console.log('chatRequest::NEW-CONVERSATION', this.conversations, threadId)
11511156
}
11521157
if(this.isValidating) // trigger confirmation until session (or vld) ends
11531158
chatMessage = `CONFIRM REGISTRATION PHASE: registrationId=${ this.registrationId }\n${ chatMessage }`
11541159
if(this.isCreatingAccount)
11551160
chatMessage = `CREATE ACCOUNT PHASE: ${ chatMessage }`
11561161
return super.chatRequest(activeBotId, threadId, chatMessage, conversation, processStartTime)
11571162
}
1163+
/**
1164+
* Create a new conversation.
1165+
* @async
1166+
* @public
1167+
* @param {string} type - Type of conversation: chat, experience, dialog, inter-system, etc.; defaults to `chat`.
1168+
* @param {string} threadId - The openai thread id.
1169+
* @param {string} botId - The bot id.
1170+
* @param {boolean} saveToConversations - Whether to save the conversation to local memory; certain system and memory actions will be saved in their own threads.
1171+
* @returns {Conversation} - The conversation object.
1172+
*/
1173+
async createConversation(type='system', botId=this.activeBotId, saveToConversations=true){
1174+
const thread = await this.#llmServices.thread(undefined)
1175+
const conversation = new (this.#factory.conversation)({ mbr_id: this.mbr_id, type, }, this.#factory, thread, botId)
1176+
if(saveToConversations)
1177+
this.addConversation(conversation)
1178+
return conversation
1179+
}
11581180
/* public methods */
11591181
/**
11601182
* Add a member to the hosted members list.

0 commit comments

Comments
 (0)