Skip to content

Commit

Permalink
Version 0.0.6 Base (#199)
Browse files Browse the repository at this point in the history
* Update azure-deploy-prod_maht.yml

Updated version numbers

* Update azure-deploy-prod_maht.yml

updated azure/webapps-deploy to v3

* Version 0.0.6 Release (#198)

* 20240429 @Mookse
- assets

* 20240429 @Mookse
wip stable

* 20240429 @Mookse
- assets

Signed-off-by: Erik Jespersen <mookse@gmail.com>

* 20240429 @Mookse
wip stable

Signed-off-by: Erik Jespersen <mookse@gmail.com>

* 20240507 @Mookse
- `Globals` improvement
- select help type
- submit help
- receive reponse
- cosmetic update of @module in ESDocs

* 20240511 @Mookse
- display chat/request response bubbles
- begin breakout of animations.css
- llm conectivity
- await css

* 20240512 @Mookse
- help chat refresh

* 20240512 @Mookse
- availableExperiences()
- launch tutorial button
- launchExperience event

* 20240513 @Mookse
- popup-container css

* 20240513 @Mookse
- env defaults to gpt-4o

* 20240513 @Mookse
- gpt updates
- improved message parsing
- cosmetic

---------

Signed-off-by: Erik Jespersen <mookse@gmail.com>

---------

Signed-off-by: Erik Jespersen <mookse@gmail.com>
  • Loading branch information
Mookse authored May 14, 2024
1 parent 90fa7e1 commit 9740264
Show file tree
Hide file tree
Showing 30 changed files with 1,211 additions and 311 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/azure-deploy-prod_maht.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Node.js version
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: 20
cache: 'npm'

- name: Install dependencies
Expand All @@ -29,7 +29,7 @@ jobs:
npm run test --if-present
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4.3.3
with:
name: node-app
path: .
Expand All @@ -43,13 +43,13 @@ jobs:

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4.1.7
with:
name: node-app

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
uses: azure/webapps-deploy@v3
with:
app-name: 'maht'
slot-name: 'Production'
Expand Down
8 changes: 4 additions & 4 deletions inc/js/agents/system/asset-assistant.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import fs from 'fs'
import mime from 'mime-types'
import FormData from 'form-data'
import axios from 'axios'
// modular constants
// module constants
const { MYLIFE_EMBEDDING_SERVER_BEARER_TOKEN, MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT, MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT_ADMIN, MYLIFE_SERVER_MBR_ID: mylifeMbrId, } = process.env
const bearerToken = MYLIFE_EMBEDDING_SERVER_BEARER_TOKEN
const fileSizeLimit = parseInt(MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT) || 1048576
const fileSizeLimitAdmin = parseInt(MYLIFE_EMBEDDING_SERVER_FILESIZE_LIMIT_ADMIN) || 10485760
// modular variables
// module variables
let AgentFactory
let Globals
// modular class definition
// module class definition
class oAIAssetAssistant {
// pseudo-constructor
#ctx // @todo: only useful if assistant only exists for duration of request
Expand All @@ -21,7 +21,7 @@ class oAIAssetAssistant {
// primary direct assignment
this.#ctx = _ctx
this.#mbr_id = this.#ctx.state.member.mbr_id
// modular direct assignment
// module direct assignment
if(!AgentFactory) AgentFactory = this.#ctx.AgentFactory
if(!Globals) Globals = this.#ctx.Globals
// secondary direct assignment
Expand Down
20 changes: 10 additions & 10 deletions inc/js/agents/system/evolution-assistant.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// imports
import { _ } from 'ajv'
import { EventEmitter } from 'events'
/* modular constants */
/* module constants */
const _phases = [
'create',
'init',
Expand Down Expand Up @@ -123,10 +123,10 @@ export class EvolutionAssistant extends EventEmitter {
}
}
}
/* modular functions */
/* module functions */
/**
* Advance the phase of the Evolution Assistant. Logic is encapsulated to ensure that the phase is advanced only when appropriate, ergo, not every request _to_ advancePhase() will actually _do_ so. Isolates and privatizes logic to propose _advance_ to next phase.
* @modular
* @module
* @emits {evo-agent-phase-change} - Emitted when the phase advances.
* @param {EvolutionAssistant} _evoAgent - `this` Evolution Assistant.
* @returns {string} The determined phase.
Expand All @@ -148,7 +148,7 @@ async function mAdvancePhase(_evoAgent){ // **note**: treat parameter `_evoAge
const contributionsPromises = mAssessData(_evoAgent)
.map(_category => mGetContribution(_evoAgent, _category, _formalPhase)) // Returns array of promises
_proposal.contributions = await Promise.all(contributionsPromises) }
// alterations sent as proposal to be adopted (or not, albeit no current mechanism to reject) by instantiated evo-agent [only viable caller by modular design]
// alterations sent as proposal to be adopted (or not, albeit no current mechanism to reject) by instantiated evo-agent [only viable caller by module design]
_proposal.phase = (mEvolutionPhaseComplete(_evoAgent,_formalPhase))
? 'init'
: 'develop'
Expand All @@ -168,7 +168,7 @@ async function mAdvancePhase(_evoAgent){ // **note**: treat parameter `_evoAge
}
/**
* Reviews properties of avatar and returns an array of three categories most in need of member Contributions.
* @modular
* @module
* @param {EvolutionAssistant} _evoAgent - The avatar evoAgent whose data requires assessment.
* @param {number} _numCategories - The number of categories to return. Defaults to 5. minimum 1, maximum 9.
* @returns {Array} The top number categories requiring Contributions.
Expand Down Expand Up @@ -228,7 +228,7 @@ function mAssignContributionListeners(_evoAgent, _contribution) {
}
/**
* Determines whether the given phase is complete.
* @modular
* @module
* @param {EvolutionAssistant} _evoAgent - `this` Evolution Assistant.
* @param {string} _phase - The phase to check for completion.
*/
Expand All @@ -243,7 +243,7 @@ function mEvolutionPhaseComplete(_evoAgent,_phase) {
}
/**
* Formats a category string to a format consistent with Cosmos key structure: all lowercase, underscores for spaces, limit of 64-characters.
* @modular
* @module
* @param {string} _category - The category to format.
* @returns {string} The formatted category.
*/
Expand All @@ -256,7 +256,7 @@ function mFormatCategory(_category) {
}
/**
* Digest a request to generate a new Contribution.
* @modular
* @module
* @emits {on-contribution-new} - Emitted when a new Contribution is generated.
* @param {EvolutionAssistant} _evoAgent - `this` Evolution Assistant.
* @param {string} _category - The category to process.
Expand Down Expand Up @@ -287,7 +287,7 @@ async function mGetContribution(_evoAgent, _category, _phase) {
}
/**
* Log an object to the console and emit it to the parent.
* @modular
* @module
* @emits {_emit_text} - Emitted when an object is logged.
* @param {string} _emit_text - The text to emit.
* @param {EvolutionAssistant} _evoAgent - `this` Evolution Assistant.
Expand All @@ -298,7 +298,7 @@ function mLog(_emit_text,_evoAgent,_object) {
}
/**
* Process a Contribution. First update the Contribution object, determining if the Contribution stage is updated. Then evaluate Evolution phase for completeness and advancement.
* @modular
* @module
* @param {EvolutionAssistant} _evoAgent - `this` Evolution Assistant.
* @param {Array} _contributions - The contributions array.
* @param {object} _current - Contribution object { category, contributionId, message }
Expand Down
22 changes: 16 additions & 6 deletions inc/js/api-functions.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import chalk from "chalk"
/* variables */
const mBotSecrets = JSON.parse(process.env.OPENAI_JWT_SECRETS)
/* public modular functions */
/* public module functions */
/**
* Returns all publicly-available experiences.
* @param {Koa} ctx - Koa Context object.
* @returns {Object[]} - Array of Experience Objects.
*/
async function availableExperiences(ctx){
ctx.body = await ctx.MyLife.availableExperiences()
console.log(chalk.yellowBright('availableExperiences()', ctx.body))
}
// @todo implement builder functionality, allowing for interface creation of experiences by members
// @todo implement access to exposed member experiences using `mbr_key` as parameter to `factory.getItem()`
async function experienceBuilder(ctx){
Expand Down Expand Up @@ -127,7 +136,7 @@ async function keyValidation(ctx){ // from openAI
}
/**
* All functionality related to a library. Note: Had to be consolidated, as openai GPT would only POST.
* @modular
* @module
* @public
* @param {Koa} ctx - Koa Context object
* @returns {Koa} Koa Context object
Expand All @@ -151,7 +160,7 @@ async function library(ctx){
}
/**
* Login function for member. Requires mid in params.
* @modular
* @module
* @public
* @param {Koa} ctx - Koa Context object
* @returns {Koa} Koa Context object
Expand Down Expand Up @@ -244,7 +253,7 @@ async function storyLibrary(ctx){
}
/**
* Validates api token
* @modular
* @module
* @public
* @param {object} ctx Koa context object
* @param {function} next Koa next function
Expand Down Expand Up @@ -278,10 +287,10 @@ async function tokenValidation(ctx, next) {
return
}
}
/* "private" modular functions */
/* "private" module functions */
/**
* Validates key and sets `ctx.state` and `ctx.session` properties. `ctx.state`: [ assistantType, isValidated, mbr_id, ]. `ctx.session`: [ isAPIValidated, APIMemberKey, ].
* @modular
* @module
* @private
* @async
* @param {Koa} ctx - Koa Context object.
Expand Down Expand Up @@ -328,6 +337,7 @@ function mTokenValidation(_token){
}
/* exports */
export {
availableExperiences,
experience,
experienceCast,
experienceEnd,
Expand Down
17 changes: 17 additions & 0 deletions inc/js/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ class MyLife extends Organization { // form=server
constructor(factory){ // no session presumed to exist
super(factory)
}
/**
* Retrieves all public experiences (i.e., owned by MyLife).
* @returns {Object[]} - An array of the currently available public experiences.
*/
async availableExperiences(){
const experiences = ( await this.factory.availableExperiences() )
.map(experience=>{ // map to display versions [from `mylife-avatar.mjs`]
const { autoplay=false, description, id, name, purpose, skippable=true, } = experience
return {
description,
id,
name,
purpose,
}
})
return experiences
}
async datacore(_mbr_id){
if(!_mbr_id || _mbr_id===this.mbr_id) throw new Error('datacore cannot be accessed')
return await this.factory.datacore(_mbr_id)
Expand Down
10 changes: 5 additions & 5 deletions inc/js/factory-class-extenders/class-contribution-functions.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* variables */
const { MYLIFE_ALLOW_INTELLIGENT_QUESTIONS } = process.env
const allowLLMQuestions = JSON.parse(MYLIFE_ALLOW_INTELLIGENT_QUESTIONS ?? 'false')
/* contribution modular functions */
/* contribution module functions */
/**
* Gets questions from Cosmos, but could request from openAI.
* @param {Contribution} _contribution Contribution object
Expand All @@ -25,7 +25,7 @@ async function mGetQuestions(_contribution, _openai){
return ['What is the meaning of life?']
/* @todo: refactor for gpt's
const _response = await _evoAgent.openai.completions.create({
model: 'gpt-3.5-turbo-instruct',
model: 'gpt-4o',
prompt: 'give a list of 3 questions (markdown bullets) used to ' + (
(!this.request.content)
? `get more information about a ${this.request.impersonation} regarding its ${this.request.category}`
Expand All @@ -48,7 +48,7 @@ async function mGetQuestions(_contribution, _openai){
}
/**
* Updates contribution object with incoming contribution data.
* @modular
* @module
* @param {Contribution} _contribution - Contribution object
* @param {object} _obj - Contribution data { category, contributionId, content??question??message }
* @returns {void}
Expand All @@ -63,10 +63,10 @@ function mUpdateContribution(_contribution, _obj){
}
mEvaluateStatus(_contribution) // evaluates readiness for next stage of Contribution
}
/* contribution "private" modular functions [unexported] */
/* contribution "private" module functions [unexported] */
/**
* Evaluates Contribution and may update `status` property.
* @modular
* @module
* @param {Contribution} _contribution - Contribution object
* @returns {void}
*/
Expand Down
8 changes: 4 additions & 4 deletions inc/js/factory-class-extenders/class-experience-functions.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* experience modular constants */
/* experience module constants */
const mAvailableEventActionMap = {
appear: {
effects: ['fade', 'spotlight'],
Expand All @@ -9,14 +9,14 @@ const mAvailableEventActionMap = {
},
input: {},
}
/* experience modular functions */
/* experience module functions */
function mAppear(event){
const { id, type, data: eventData } = event
return
}
/**
* From an event, returns a `synthetic` Dialog data package, see JSDoc properties.
* @modular
* @module
* @public
* @param {Experience} _experience - Experience class instance.
* @param {number} iteration - Iteration number, defaults to first (array zero format).
Expand Down Expand Up @@ -90,7 +90,7 @@ function mGetEvent(scenes, eventId){
}
/**
* From an event, returns a `synthetic` Dialog data package, above and an .
* @modular
* @module
* @public
* @param {ExperienceEvent} event - Experience class instance.
* @param {number} iteration - Iteration number, defaults to first (array zero format).
Expand Down
5 changes: 3 additions & 2 deletions inc/js/factory-class-extenders/class-extenders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ function extendClass_conversation(originClass, referencesObject) {
* @returns {Object[]} - The updated messages array.
*/
addMessage(message){
if(this.messages.find(_message=>_message.id===message.id))
const { id, } = message
if(this.messages.find(message=>message.id===id))
return this.messages
if(!(message instanceof this.#factory.message)){
if(typeof message!=='object')
Expand Down Expand Up @@ -401,7 +402,7 @@ function extendClass_message(originClass, referencesObject) {
*/
class Message extends originClass {
#content
constructor(obj) {
constructor(obj){
const { content, ..._obj } = obj
super(_obj)
try{
Expand Down
10 changes: 5 additions & 5 deletions inc/js/factory-class-extenders/class-message-functions.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* public modular functions */
/* public module functions */
/**
* Assigns content (from _message.message) to message object.
* @modular
* @module
* @public
* @param {any} obj - Element to assign to `content` property
* @returns {string} - message text content
Expand Down Expand Up @@ -47,10 +47,10 @@ function mAssignContent(obj){
return `${obj}`
}
}
/* private modular functions */
/* private module functions */
/**
* When incoming text is too large for a single message, generate dynamic text file and attach/submit.
* @modular
* @module
* @private
* @param {string} _file - The file to construct.
* @returns
Expand All @@ -71,7 +71,7 @@ async function mConstructFile(_file){
}
/**
* Checks if content is a non-empty string.
* @modular
* @module
* @private - not exposed via export
* @param {string} content - message content
* @returns {boolean} - true if content is a non-empty string
Expand Down
Loading

0 comments on commit 9740264

Please sign in to comment.