@@ -318,8 +318,14 @@ class BotFactory extends EventEmitter{
318
318
async collections ( type ) {
319
319
return await this . dataservices . collections ( type )
320
320
}
321
- async createBot ( assistantData = { type : mDefaultBotType } ) {
322
- const bot = await mCreateBot ( this . #llmServices, this , assistantData )
321
+ /**
322
+ *
323
+ * @param {object } assistantData - The assistant data.
324
+ * @param {string } vectorstoreId - The vectorstore id.
325
+ * @returns {object } - The created bot.
326
+ */
327
+ async createBot ( assistantData = { type : mDefaultBotType } , vectorstoreId ) {
328
+ const bot = await mCreateBot ( this . #llmServices, this , assistantData , vectorstoreId )
323
329
if ( ! bot )
324
330
throw new Error ( 'bot creation failed' )
325
331
return bot
@@ -492,10 +498,10 @@ class BotFactory extends EventEmitter{
492
498
* Adds or updates a bot data in MyLife database. Note that when creating, pre-fill id.
493
499
* @public
494
500
* @param {object } bot - The bot data.
495
- * @param {object } options - Function options: `{ instructions: boolean, model: boolean, tools: boolean }`. Meant to express whether or not these elements should be refreshed. Useful during updates .
496
- * @returns {object } - The Cosmos bot.
501
+ * @param {object } options - Function options: `{ instructions: boolean, model: boolean, tools: boolean, vectorstoreId: string, }` .
502
+ * @returns {object } - The Cosmos bot version .
497
503
*/
498
- async updateBot ( bot , options ) {
504
+ async updateBot ( bot , options = { } ) {
499
505
return await mUpdateBot ( this , this . #llmServices, bot , options )
500
506
}
501
507
/* getters/setters */
@@ -928,32 +934,15 @@ class AgentFactory extends BotFactory {
928
934
get urlEmbeddingServer ( ) {
929
935
return process . env . MYLIFE_EMBEDDING_SERVER_URL + ':' + process . env . MYLIFE_EMBEDDING_SERVER_PORT
930
936
}
931
- get vectorstoreId ( ) {
932
- return this . core . vectorstoreId
933
- }
934
- set vectorstoreId ( vectorstoreId ) {
935
- /* validate vectorstoreId */
936
- if ( ! vectorstoreId ?. length )
937
- throw new Error ( 'vectorstoreId required' )
938
- this . dataservices . patch ( this . core . id , { vectorstoreId, } ) /* no await */
939
- this . core . vectorstoreId = vectorstoreId /* update local */
940
- }
941
937
}
942
938
class MyLifeFactory extends AgentFactory {
943
- #accountCreation
944
939
#dataservices = mDataservices
945
940
#llmServices = mLLMServices
946
941
#registrationData
947
942
constructor ( ) {
948
943
super ( mPartitionId )
949
944
} // no init() for MyLife server
950
945
/* public functions */
951
- async addMember ( mbr_id ) {
952
- if ( ! this . globals . isValidGuid ( mbr_id ) )
953
- return
954
- // Me! Q! I do it! I do it! I do it!
955
- /* but because Q needs to do it, how do I get up one level to avatar? */
956
- }
957
946
/**
958
947
* Compares registration email against supplied email to confirm `true`. **Note**: does not care if user enters an improper email, it will only fail the encounter, as email structure _is_ confirmed upon initial data write.
959
948
* @param {string } email - The supplied email to confirm registration.
@@ -1088,7 +1077,7 @@ class MyLifeFactory extends AgentFactory {
1088
1077
}
1089
1078
} catch ( error ) {
1090
1079
this . #registrationData = null
1091
- console . log ( chalk . blueBright ( `validateRegistration(${ registrationId } )::error` ) )
1080
+ console . log ( chalk . blueBright ( `validateRegistration(${ registrationId } )::error` ) , error . message )
1092
1081
}
1093
1082
return this . #registrationData
1094
1083
}
@@ -1210,7 +1199,7 @@ async function mCreateBotLLM(llm, assistantData){
1210
1199
* @param {object } bot - Bot object, must include `type` property.
1211
1200
* @returns {object } - Bot object
1212
1201
*/
1213
- async function mCreateBot ( llm , factory , bot ) {
1202
+ async function mCreateBot ( llm , factory , bot , vectorstoreId ) {
1214
1203
/* initial deconstructions */
1215
1204
const { bot_name : botName , description : botDescription , name : botDbName , type, } = bot
1216
1205
const { avatarId, } = factory
@@ -1228,15 +1217,18 @@ async function mCreateBot(llm, factory, bot){
1228
1217
?? 'gpt-4o'
1229
1218
const name = botDbName
1230
1219
?? `bot_${ type } _${ avatarId } `
1231
- const { tools, tool_resources, } = mGetAIFunctions ( type , factory . globals , factory . vectorstoreId )
1220
+ const { tools, tool_resources, } = mGetAIFunctions ( type , factory . globals , vectorstoreId )
1232
1221
const id = factory . newGuid
1233
1222
const assistantData = {
1234
1223
being : 'bot' ,
1235
1224
bot_name,
1236
1225
description,
1237
1226
id,
1238
1227
instructions,
1239
- metadata : { externalId : id , } ,
1228
+ metadata : {
1229
+ externalId : id ,
1230
+ version : version . toString ( ) ,
1231
+ } ,
1240
1232
model,
1241
1233
name,
1242
1234
object_id : avatarId ,
@@ -1254,7 +1246,7 @@ async function mCreateBot(llm, factory, bot){
1254
1246
/* create in MyLife datastore */
1255
1247
assistantData . bot_id = botId
1256
1248
const assistant = await factory . dataservices . createBot ( assistantData )
1257
- console . log ( chalk . green ( `bot created::${ type } ` ) , assistant )
1249
+ console . log ( chalk . green ( `bot created::${ type } ` ) , assistant . id , assistant . bot_id , assistant . bot_name , )
1258
1250
return assistant
1259
1251
}
1260
1252
/**
@@ -1805,13 +1797,13 @@ function mSanitizeSchemaValue(_value) {
1805
1797
* @param {AgentFactory } factory - Factory object
1806
1798
* @param {LLMServices } llm - LLMServices object
1807
1799
* @param {object } bot - Bot object, winnow via mBot in `mylife-avatar.mjs` to only updated fields
1808
- * @param {object } options - Options object: { instructions: boolean, model: boolean, tools: boolean }
1800
+ * @param {object } options - Options object: { instructions: boolean, model: boolean, tools: boolean, vectorstoreId: string, }
1809
1801
* @returns
1810
1802
*/
1811
1803
async function mUpdateBot ( factory , llm , bot , options = { } ) {
1812
1804
/* constants */
1813
1805
const {
1814
- id, // no modifications; see below
1806
+ id, // no modifications
1815
1807
instructions : removeInstructions ,
1816
1808
tools : removeTools ,
1817
1809
tool_resources : removeResources ,
@@ -1822,30 +1814,34 @@ async function mUpdateBot(factory, llm, bot, options={}){
1822
1814
instructions : updateInstructions = false ,
1823
1815
model : updateModel = false ,
1824
1816
tools : updateTools = false ,
1817
+ vectorstoreId,
1825
1818
} = options
1826
1819
if ( ! factory . globals . isValidGuid ( id ) )
1827
1820
throw new Error ( 'bot `id` required in bot argument: `{ id: guid }`' )
1828
1821
if ( updateInstructions ) {
1829
1822
const { instructions, version= 1.0 , } = mCreateBotInstructions ( factory , bot )
1830
1823
botData . instructions = instructions
1824
+ botData . metadata = botData . metadata ?? { }
1825
+ botData . metadata . version = version . toString ( )
1831
1826
botData . version = version /* omitted from llm, but appears on updateBot */
1832
1827
}
1833
1828
if ( updateTools ) {
1834
- const { tools, tool_resources, } = mGetAIFunctions ( type , factory . globals , factory . vectorstoreId )
1829
+ console . log ( 'mUpdateBot' , vectorstoreId )
1830
+ const { tools, tool_resources, } = mGetAIFunctions ( type , factory . globals , vectorstoreId )
1835
1831
botData . tools = tools
1836
1832
botData . tool_resources = tool_resources
1837
1833
}
1838
1834
if ( updateModel )
1839
1835
botData . model = factory . globals . currentOpenAIBotModel
1840
1836
botData . id = id // validated
1841
1837
/* LLM updates */
1842
- const { bot_id, bot_name : name , instructions, metadata , tools, } = botData
1843
- if ( bot_id ?. length && ( instructions || metadata || name || tools ) ) {
1838
+ const { bot_id, bot_name : name , instructions, tools, } = botData
1839
+ if ( bot_id ?. length && ( instructions || name || tools ) ) {
1844
1840
botData . model = factory . globals . currentOpenAIBotModel // not dynamic
1845
1841
await llm . updateBot ( botData )
1846
1842
const updatedLLMFields = Object . keys ( botData )
1847
1843
. filter ( key => key !== 'id' && key !== 'bot_id' ) // strip mechanicals
1848
- console . log ( chalk . green ( 'mUpdateBot()::update in LLM ' ) , bot_id , id , updatedLLMFields )
1844
+ console . log ( chalk . green ( 'mUpdateBot()::update in OpenAI ' ) , id , bot_id , updatedLLMFields )
1849
1845
}
1850
1846
const updatedBot = await factory . dataservices . updateBot ( botData )
1851
1847
return updatedBot
0 commit comments