Skip to content

Commit

Permalink
20240717 @Mookse (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mookse authored Jul 17, 2024
1 parent cbda4ff commit 2923766
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions inc/js/mylife-avatar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ class Avatar extends EventEmitter {
if(!activeBotId)
throw new Error('Parameter `activeBotId` required.')
const { activeBot, factory } = this
const { id: botId, } = activeBot
const { id: botId, thread_id, } = activeBot
if(botId!==activeBotId)
throw new Error(`Invalid bot id: ${ activeBotId }, active bot id: ${ botId }`)
// @stub - clean up conversation alterations - Q is immune
conversation = conversation
?? this.getConversation(threadId)
if(!conversation)
throw new Error('No conversation found for thread id and could not be created.')
?? this.getConversation(threadId ?? thread_id)
?? await this.createConversation('chat', threadId, activeBotId)
conversation.bot_id = activeBot.bot_id // pass in via quickly mutating conversation (or independently if preferred in end), versus llmServices which are global
const messages = await mCallLLM(this.#llmServices, conversation, chatMessage, factory, this)
conversation.addMessages(messages)
Expand Down Expand Up @@ -186,8 +184,18 @@ class Avatar extends EventEmitter {
* @returns {Conversation} - The conversation object.
*/
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
const { bot_id, bot_name, id, thread_id, } = bot
const updatedBot = await this.factory.updateBot({
bot_id, // required?
bot_name, // required?
id,
thread_id,
})
if(saveToConversations)
this.#conversations.push(conversation)
return conversation
Expand Down Expand Up @@ -1278,6 +1286,7 @@ async function mBot(factory, avatar, bot){
/* update/create */
let originBot = bots.find(oBot=>oBot.id===botId)
if(originBot){ /* update bot */
console.log('mBot::UPDATE', bots, originBot)
const options = {}
const updatedBot = Object.keys(bot)
.reduce((diff, key) => {
Expand Down Expand Up @@ -1957,29 +1966,28 @@ async function mInit(factory, avatar, bots){
avatar.nickname = avatar.nickname
?? avatar.names?.[0]
?? `${avatar.memberFirstName ?? 'member'}'s avatar`
/* bots */ // @stub - determine by default or activated team
requiredBotTypes.push('library', 'personal-biographer') // default memory team
/* bots */
requiredBotTypes.push('personal-biographer') // memory team
}
bots.push(...await factory.bots(avatar.id))
await Promise.all(
requiredBotTypes
.map(async botType=>{
if(!bots.some(bot=>bot.type===botType)){ // create required bot
const bot = await mBot(factory, avatar, { type: botType })
bots.push(bot)
}
.map(async botType=>{
if(!bots.some(bot=>bot.type===botType)){ // create required bot
const bot = await mBot(factory, avatar, { type: botType })
bots.push(bot)
}
}
))
avatar.activeBotId = avatar.avatar.id // initially set active bot to personal-avatar
/* conversations */
await Promise.all(
bots.map(async bot=>{
bots.map(async bot=>{
const { thread_id, } = bot
if(thread_id && !avatar.getConversation(thread_id))
avatar.conversations.push(await avatar.createConversation('chat', thread_id))
})
)
// need to create new conversation for Q variant, but also need to ensure that no thread_id is saved for Q
/* evolver */
if(!factory.isMyLife)
avatar.evolver = await (new EvolutionAssistant(avatar))
Expand Down

0 comments on commit 2923766

Please sign in to comment.