Skip to content

Commit

Permalink
20241111 @Mookse
Browse files Browse the repository at this point in the history
- halt LLM call on functions for updateSummary and changeTitle
- frontend console.log fixes
- backend console.log fixes
  • Loading branch information
Mookse committed Nov 12, 2024
1 parent 5cb4697 commit 5ae0e7a
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 113 deletions.
1 change: 0 additions & 1 deletion inc/js/agents/system/asset-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class AssetAgent {
uploadFiles.push(this.#extractFile(file))
})
if(uploadFiles.length){ // only upload new files
console.log('upload::uploadFiles', uploadFiles)
const fileStreams = uploadFiles.map(file=>fs.createReadStream(file.filepath))
const dataRecord = await this.#llm.upload(this.#vectorstoreId, fileStreams, this.mbr_id)
const { response, success } = dataRecord
Expand Down
3 changes: 0 additions & 3 deletions inc/js/agents/system/bot-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Bot {
#llm
#type
constructor(botData, llm, factory){
console.log(`bot pre-created`, this.feedback)
this.#factory = factory
this.#llm = llm
const { feedback=[], greeting=mDefaultGreeting, greetings=mDefaultGreetings, type=mDefaultBotType, ..._botData } = botData
Expand Down Expand Up @@ -141,7 +140,6 @@ class Bot {
const { bot_id: _llm_id, id, type, } = this
let { llm_id=_llm_id, thread_id, } = this // @stub - deprecate bot_id
this.#conversation = await mConversationStart('chat', type, id, thread_id, llm_id, this.#llm, this.#factory, message)
console.log(`getConversation::thread_id`, thread_id, this.#conversation.thread_id)
if(!thread_id?.length){
thread_id = this.#conversation.thread_id
this.update({
Expand Down Expand Up @@ -1042,7 +1040,6 @@ async function mConversationDelete(Conversation, factory, llm){
})
await factory.deleteItem(Conversation.id) /* delete conversation from Cosmos */
await llm.deleteThread(thread_id) /* delete thread from LLM */
console.log('mDeleteConversation', Conversation.id, thread_id)
return true
}
/**
Expand Down
1 change: 0 additions & 1 deletion inc/js/agents/system/evolution-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ function mSetContribution(evoAgent, _current, _proposed) {
/* @todo: verify that categories are changing */
const _currentContribution = evoAgent.contributions
.find(_contribution => _contribution.id === _current.contributionId)
console.log('evolution-assistant:mSetContribution():320', _currentContribution.inspect(true))
if(_currentContribution.stage === 'prepared'){ // ready to process
// join array and submit for gpt-summarization
mSubmitContribution(evoAgent, _contributions.responses.join('\n'))
Expand Down
5 changes: 0 additions & 5 deletions inc/js/api-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ async function entry(ctx){
const { assistantType, mbr_id } = ctx.state
if(!ctx.request.body?.summary?.length)
throw new Error('No entry summary provided. Use `summary` field.')
console.log(chalk.yellowBright('entry()::entry attempted:'), ctx.request.body)
const summary = {
...ctx.request.body,
assistantType,
mbr_id,
}
const entry = await ctx.MyLife.entry(summary)
console.log(chalk.yellowBright('entry()::entry submitted:'), entry, summary)
ctx.status = 200
ctx.body = {
id: entry.id,
Expand All @@ -48,7 +46,6 @@ async function experienceBuilder(ctx){
const { assistantType, mbr_id } = ctx.state
const { eid, sid } = ctx.params
const { experience } = ctx.request.body?.experience
console.log(chalk.yellowBright('experienceBuilder()'), { assistantType, mbr_id, eid, sid, experience })
if(!experience)
ctx.throw(400, 'No experience provided for builder. Use `experience` field.')
}
Expand Down Expand Up @@ -231,14 +228,12 @@ async function memory(ctx){
const { assistantType, mbr_id } = ctx.state
if(!ctx.request.body?.summary?.length)
throw new Error('No memory summary provided. Use `summary` field.')
console.log(chalk.yellowBright('memory()::memory attempted:'), ctx.request.body)
const summary = {
...ctx.request.body,
assistantType,
mbr_id,
}
const memory = await ctx.MyLife.memory(summary)
console.log(chalk.yellowBright('memory()::memory submitted:'), memory, summary)
ctx.status = 200
ctx.body = {
id: memory.id,
Expand Down
3 changes: 1 addition & 2 deletions inc/js/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Member extends EventEmitter {
async testEmitters(){
// test emitters with callbacks
this.emit('testEmitter',_response=>{
console.log('callback emitters enabled:',_response)

})
}
}
Expand Down Expand Up @@ -335,7 +335,6 @@ class MyLife extends Organization { // form=server
let isValidated = false
if(isHosted)
isValidated = await this.testPartitionKey(memberId)
console.log('isMemberHosted:', isHosted, isValidated, memberId)
return isValidated
}
/**
Expand Down
5 changes: 1 addition & 4 deletions inc/js/factory-class-extenders/class-extenders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ function extendClass_message(originClass, referencesObject) {
try{
this.#content = assignContent(content ?? obj)
} catch(e){
console.log('Message::constructor::ERROR', e)
this.#content = ''
}
}
Expand All @@ -443,9 +442,7 @@ function extendClass_message(originClass, referencesObject) {
set content(_content){
try{
this.#content = assignContent(_content)
} catch(e){
console.log('Message::content::ERROR', e)
}
} catch(e){}
}
get message(){
return this
Expand Down
3 changes: 0 additions & 3 deletions inc/js/mylife-avatar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,6 @@ class Q extends Avatar {
if(!this.globals.isValidGuid(key) || key!==this.hosting_key)
throw new Error('Invalid key for hosted members.')
if(!this.#hostedMembers.length){ // on-demand creation
console.log('hostedMembers', this.#hostedMembers)
const hostedMembers = await this.#factory.hostedMembers()
if(!hostedMembers.length)
throw new Error('No hosted members found.')
Expand Down Expand Up @@ -2020,7 +2019,6 @@ async function mExperienceStart(avatar, factory, experienceId, avatarExperienceV
if(id!==experienceId)
throw new Error('Experience failure, unexpected id mismatch.')
experience.cast = await mCast(factory, experience.cast) // hydrates cast data
console.log('mExperienceStart::experience', experience.cast[0].inspect(true))
experience.events = []
experience.location = {
experienceId: experience.id,
Expand Down Expand Up @@ -2312,7 +2310,6 @@ function mValidateMode(_requestedMode, _currentMode){
throw new Error('Invalid interface mode request. Mode not altered.')
switch(_requestedMode){
case 'admin':
console.log('Admin interface not currently implemented. Mode not altered.')
return _currentMode
case 'experience':
case 'standard':
Expand Down
1 change: 0 additions & 1 deletion inc/js/mylife-datamanager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Datamanager {
this.#partitionId
)
.read()
console.log(chalk.yellowBright('database, container, core initialized:',chalk.bgYellowBright(`${this.#containers['members'].id} :: ${this.database.id} :: ${this.#core.resource.id}`) ))
return this
}
/* public functions */
Expand Down
7 changes: 2 additions & 5 deletions inc/js/mylife-dataservices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class Dataservices {
throw new Error('`core` must be a pre-formed object with id and mbr_id')
const extantCore = await this.getItem(id, undefined, mbr_id)
if(extantCore){
console.log(`core already exists for ${mbr_id} with id ${id}`) // `core` already exists
return { core: extantCore, success: false, } // no alterations, failure
}
core = { // enforce core data structure
Expand Down Expand Up @@ -519,10 +518,8 @@ class Dataservices {
populateQuotaInfo: false, // set this to true to include quota information in the response headers
},
)
}
catch(_error){
console.log('mylife-data-service::getItems() error')
console.log(_error, being, query, paramsArray, container_id,)
} catch(_error){
console.log('mylife-data-service::getItems() error', _error, being, query, paramsArray, container_id,)
}
}
/**
Expand Down
4 changes: 0 additions & 4 deletions inc/js/mylife-factory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ class BotFactory extends EventEmitter{
throw new Error('MyLife server cannot be accessed as a BotFactory alone')
else if(mIsMyLife(this.mbr_id))
this.#dataservices = mDataservices
else if(directHydration)
console.log(chalk.blueBright('BotFactory class instance for hydration request'), chalk.bgRed(this.mbr_id))
}
/* public functions */
/**
Expand Down Expand Up @@ -996,8 +994,6 @@ function mExtractClassesFromSchema(_schema){
function mExtendClass(_class) {
const _className = _class.name.toLowerCase()
if (typeof mExtensionFunctions?.[`extendClass_${_className}`]==='function'){
console.log(`Extension function found for ${_className}`)
// add extension decorations
const _references = { openai: mLLMServices }
_class = mExtensionFunctions[`extendClass_${_className}`](_class, _references)
}
Expand Down
91 changes: 55 additions & 36 deletions inc/js/mylife-llm-services.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class LLMServices {
try{
if(error.status==400){
const cancelRun = await mRunCancel(this.openai, thread_id, llm_id)
console.log('LLMServices::getLLMResponse()::cancelRun', cancelRun)
if(!!cancelRun)
await mAssignRequestToThread(this.openai, thread_id, prompt)
else {
Expand Down Expand Up @@ -333,8 +332,10 @@ async function mRunFinish(llmServices, run, factory, avatar){
const checkInterval = setInterval(async ()=>{
try {
const functionRun = await mRunStatus(llmServices, run, factory, avatar)
if(functionRun?.status ?? functionRun ?? false){
console.log('mRunFinish::functionRun()', functionRun.status)
const functionRunStatus = functionRun?.status
?? functionRun
?? false
if(functionRunStatus){
clearInterval(checkInterval)
resolve(functionRun)
}
Expand Down Expand Up @@ -385,34 +386,35 @@ async function mRunFunctions(openai, run, factory, avatar){
if(typeof toolArguments==='string')
toolArguments = await JSON.parse(toolArguments)
?? {}
toolArguments.thread_id = thread_id
toolArguments.thread_id = thread_id // deprecate?
const { itemId, } = toolArguments
switch(name.toLowerCase()){
case 'changetitle':
case 'change_title':
case 'change title':
const { title, } = toolArguments
console.log('mRunFunctions()::changeTitle::begin', itemId, title)
if(!itemId?.length || !title?.length)
if(!itemId?.length || !title?.length){
action = 'apologize for lack of clarity - member should click on the collection item (like a memory, story, etc) to make it active so I can use the `changeTitle` tool'
else {
let item = { id: itemId, title, }
await avatar.item(item, 'put')
action = `Title change successful: "${ title }"`
avatar.frontendInstruction = {
command: 'updateItemTitle',
itemId,
title,
}
success = true
avatar.backupResponse = {
message: `I was able to change the title to: "${ title }"`,
type: 'system',
}
confirmation.output = JSON.stringify({ action, success, })
return confirmation
}
item = { id: itemId, title, }
await avatar.item(item, 'put')
avatar.frontendInstruction = {
command: 'updateItemTitle',
itemId,
title,
}
success = true
avatar.backupResponse = {
message: `I was able to change our title to: ${ title }`,
type: 'system',
}
confirmation.output = JSON.stringify({ action, itemId, success, })

console.log('mRunFunctions()::changeTitle::end', success, itemId, title.substring(0, 32))
return confirmation
await mRunCancel(openai, thread_id, runId)
throw new Error('changeTitle successful, and aborted')
case 'confirmregistration':
case 'confirm_registration':
case 'confirm registration':
Expand Down Expand Up @@ -529,15 +531,28 @@ async function mRunFunctions(openai, run, factory, avatar){
}
const updateSummaryResponse = await avatar.item(update, 'PUT')
success = updateSummaryResponse?.success
action = success
? `Summary update was successful`
: `Error updating ${ itemId }, halt any other processing and tell member to ensure the right memory is active and try again`
confirmation.output = JSON.stringify({
action,
success,
})
console.log('mRunFunctions()::updatesummary::end', success, action.substring(0, 32))
return confirmation
if(!success || !updateSummaryResponse?.item){
action = `Error updating ${ itemId }, halt processing to tell member to ensure the correct memory is active and then try again`
confirmation.output = JSON.stringify({
action,
success,
})
console.log('mRunFunctions()::updatesummary::fail', success, action.substring(0, 32))
return confirmation
}
item = updateSummaryResponse.item
avatar.frontendInstruction = {
command: 'updateItem',
item,
itemId,
}
avatar.backupResponse = {
message: `I made the requested update to: ${ item.title }`,
type: 'system',
}
await mRunCancel(openai, thread_id, runId)
console.log('mRunFunctions()::updatesummary::end', success, runId, item.title.substring(0, 32))
throw new Error('updateSummary successful, and aborted')
default:
console.log(`ERROR::mRunFunctions()::toolFunction not found: ${ name }`, toolFunction)
action = `toolFunction not found: ${ name }, apologize for the error and continue on with the conversation; system notified to fix`
Expand All @@ -553,10 +568,10 @@ async function mRunFunctions(openai, run, factory, avatar){
)
return finalOutput /* undefined indicates to ping again */
}
}
catch(error){
console.log('mRunFunctions()::error::canceling-run', error.message, error.stack)
rethrow(error)
} catch(error){
console.log('mRunFunctions()::error', error.message.substring(0, 64))
if(error.status!==400)
throw error
}
}
/**
Expand Down Expand Up @@ -589,8 +604,12 @@ async function mRunStatus(openai, run, factory, avatar){
)
switch(run.status){
case 'requires_action':
const completedRun = await mRunFunctions(openai, run, factory, avatar)
return completedRun /* if undefined, will ping again */
try {
const completedRun = await mRunFunctions(openai, run, factory, avatar)
return completedRun /* if undefined, will ping again */
} catch(error){
return run
}
case 'completed':
return run // run
case 'failed':
Expand Down
14 changes: 2 additions & 12 deletions inc/js/session.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class MylifeMemberSession extends EventEmitter {
super()
this.#factory = factory
this.#mbr_id = this.isMyLife ? this.factory.mbr_id : false
console.log(
chalk.bgGray('MylifeMemberSession:constructor(factory):generic-mbr_id::end'),
chalk.bgYellowBright(this.factory.mbr_id),
)
}
/**
* Initializes the member session. If `isMyLife`, then session requires chat thread unique to visitor; session has singleton System Avatar who maintains all running Conversations.
Expand Down Expand Up @@ -73,7 +69,6 @@ class MylifeMemberSession extends EventEmitter {
events = eventSequence
}
} catch (error){
console.log(chalk.redBright('experience() error'), error, avatar.experience)
const { experience } = avatar
if(experience){ // embed error in experience
experience.errors = experience.errors ?? []
Expand All @@ -89,10 +84,8 @@ class MylifeMemberSession extends EventEmitter {
title,
}
this.#experienceLocked = false
if(events.find(event=>{ return event.action==='end' && event.type==='experience' })){
if(!this.experienceEnd(experienceId))
console.log(chalk.redBright('experienceEnd() failed'))
}
if(events.find(event=>{ return event.action==='end' && event.type==='experience' }))
this.experienceEnd(experienceId)
return frontendExperience
}
/**
Expand Down Expand Up @@ -152,7 +145,6 @@ class MylifeMemberSession extends EventEmitter {
const _object_id = ctx.request.header?.referer?.split('/').pop()
// not guid, not consent request, no blocking
if(!this.globals.isValidGuid(_object_id)) return true
console.log('session.requestConsent()', 'mbr_id', this.mbr_id)
// ultimately, applying a disposable agent of intelligence to consent request might be the answer
let _consent = this.consents
.filter(_=>{ return _.id==_object_id })
Expand All @@ -178,7 +170,6 @@ class MylifeMemberSession extends EventEmitter {
_consent = (_consent_id)
? {} // retrieve from Cosmos
: new (this.schemas.consent)(_request, this) // generate new consent
console.log('_consent', _consent)
// manipulate session through ctx (although won't exist in initial test case)
await (this.ctx.session.MemberSession.consents = _consent) // will add consent to session list
return _consent
Expand All @@ -191,7 +182,6 @@ class MylifeMemberSession extends EventEmitter {
* @param {boolean} outcome - The challenge outcome; `true` was successful
*/
set challengeOutcome(outcome){
console.log('challengeOutcome', outcome)
if(outcome)
this.#sessionLocked = false
}
Expand Down
Loading

0 comments on commit 5ae0e7a

Please sign in to comment.