From 9842aae78aa84378f3a186ad132ff777af6f4eb7 Mon Sep 17 00:00:00 2001 From: Erik Jespersen Date: Wed, 17 Jul 2024 02:03:11 -0400 Subject: [PATCH] 20240717 @Mookse - avatar update --- inc/js/mylife-avatar.mjs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/inc/js/mylife-avatar.mjs b/inc/js/mylife-avatar.mjs index f7f58a4..fc3d0c9 100644 --- a/inc/js/mylife-avatar.mjs +++ b/inc/js/mylife-avatar.mjs @@ -68,6 +68,13 @@ class Avatar extends EventEmitter { : this.activeBot.bot_id return this } + /** + * Add a conversation to session memory. + * @param {Conversation} conversation - The conversation object. + */ + addConversation(conversation){ + this.#conversations.push(conversation) + } /** * Get a bot. * @public @@ -185,7 +192,6 @@ class Avatar extends EventEmitter { */ async createConversation(type='chat', threadId, botId=this.activeBotId, saveToConversations=true){ const bot = await this.bot(botId) - console.log('createConversation::bot', botId, bot.bot_name, bot.type) const thread = await this.#llmServices.thread(threadId) const conversation = new (this.#factory.conversation)({ mbr_id: this.mbr_id, type, }, this.#factory, thread, botId) bot.thread_id = conversation.thread_id @@ -197,7 +203,7 @@ class Avatar extends EventEmitter { thread_id, }) if(saveToConversations) - this.#conversations.push(conversation) + this.addConversation(conversation) return conversation } /** @@ -1125,7 +1131,7 @@ class Q extends Avatar { throw new Error('factory parameter must be an instance of MyLifeFactory') super(factory, llmServices) this.#factory = factory - this.llmServices = llmServices + this.#llmServices = llmServices } /* overloaded methods */ /** @@ -1147,7 +1153,6 @@ class Q extends Avatar { ?? this.activeBot.bot_id conversation = await this.createConversation('system', undefined, activeBotId, true) // pushes to this.#conversations in Avatar threadId = conversation.thread_id - console.log('chatRequest::NEW-CONVERSATION', this.conversations, threadId) } if(this.isValidating) // trigger confirmation until session (or vld) ends chatMessage = `CONFIRM REGISTRATION PHASE: registrationId=${ this.registrationId }\n${ chatMessage }` @@ -1155,6 +1160,23 @@ class Q extends Avatar { chatMessage = `CREATE ACCOUNT PHASE: ${ chatMessage }` return super.chatRequest(activeBotId, threadId, chatMessage, conversation, processStartTime) } + /** + * Create a new conversation. + * @async + * @public + * @param {string} type - Type of conversation: chat, experience, dialog, inter-system, etc.; defaults to `chat`. + * @param {string} threadId - The openai thread id. + * @param {string} botId - The bot id. + * @param {boolean} saveToConversations - Whether to save the conversation to local memory; certain system and memory actions will be saved in their own threads. + * @returns {Conversation} - The conversation object. + */ + async createConversation(type='system', botId=this.activeBotId, saveToConversations=true){ + const thread = await this.#llmServices.thread(undefined) + const conversation = new (this.#factory.conversation)({ mbr_id: this.mbr_id, type, }, this.#factory, thread, botId) + if(saveToConversations) + this.addConversation(conversation) + return conversation + } /* public methods */ /** * Add a member to the hosted members list.