The storeResponse function stores user interactions, analyzing the content, emotions, and context, and returns an object containing metadata about the interaction. It selects a model, checks for existing conversation files, and updates the conversation data in memory and the file system, generating a summary and keywords for the interaction.
npm run import -- "store llm response"const path = require('path')
const fs = require('fs')
const selectModel = importer.import("select llm")
const {askLlamaAboutEmotions} = importer.import("ask llm about emotions")
const {ACTIVE_CONVERSATIONS, PROJECT_PATH, DEFAULT_MODEL} = importer.import("general chit chat")
async function storeResponse(user, session, content, context, otr) {
let promptModel = await selectModel(DEFAULT_MODEL)
if(!session) {
return {
emotions: await askLlamaAboutEmotions(content)
}
}
let now = new Date()
let convoFile = path.join(PROJECT_PATH, now.getFullYear() + '-'
+ String(now.getMonth() + 1).padStart(2, '0')
+ '-' + DEFAULT_MODEL
+ '-' + session + '.json')
if(typeof ACTIVE_CONVERSATIONS[convoFile] == 'undefined') {
if(fs.existsSync(convoFile)) {
ACTIVE_CONVERSATIONS[convoFile] = JSON.parse(fs.readFileSync(convoFile))
} else {
ACTIVE_CONVERSATIONS[convoFile] = {}
}
}
let contextContainsImage = false
if(context && context.startsWith('data:image/png;base64,')) {
contextContainsImage = true
}
let summary
if(!otr) {
summary = await promptModel('Summerize this prompt in one short sentence:\n'
+ content + '\nOnly respond with the summary, no pleasantries.')
}
let keywords = await promptModel('List a few key words that categorize this prompt:\n'
+ content + '\nOnly respond with a single category, no pleasantries.')
let emotions = await askLlamaAboutEmotions(content)
let result = ACTIVE_CONVERSATIONS[convoFile][Date.now()] = {
user: user,
content: otr ? void 0 : content,
context: contextContainsImage ? void 0 : context,
summary: summary,
keywords: keywords,
emotions: emotions,
otr: otr ? true : false,
}
fs.writeFileSync(convoFile, JSON.stringify(ACTIVE_CONVERSATIONS[convoFile], null, 4))
return result
}
module.exports = storeResponse
const path = require('path');
const fs = require('fs');
const selectModel = importer.import('select llm');
const {
ACTIVE_CONVERSATIONS,
PROJECT_PATH,
DEFAULT_MODEL,
} = importer.import('general chit chat');
const { askLlamaAboutEmotions } = importer.import('ask llm about emotions');
/**
* Stores a response to a user's prompt.
* @param {string} user - The user who made the request.
* @param {string} session - The session ID of the user.
* @param {string} content - The prompt made by the user.
* @param {string} context - The context of the prompt.
* @param {boolean} otr - Whether the response is an OTR (Off-The-Record) response.
* @returns {PromiseFunction Breakdown
storeResponse FunctionStores responses from user interactions.
user: The user who interacted with the system.session: The current session ID.content: The content of the user's interaction.context: Additional context about the interaction.otr: A flag indicating whether the interaction was in an off-the-record (OTR) session.An object containing metadata about the user's interaction, including:
user: The user who interacted with the system.content: The content of the user's interaction, unless it was an OTR session.context: Additional context about the interaction, unless it contained an image.summary: A brief summary of the user's interaction.keywords: A list of keywords categorizing the user's interaction.emotions: An analysis of the emotions expressed in the user's interaction.otr: A flag indicating whether the interaction was in an OTR session.DEFAULT_MODEL constant.session is provided, returns an object containing an analysis of emotions in the content.content to determine if it contains an image and updates the conversation data accordingly.content.content.importer: An import function.path: A module for working with file paths.fs: A module for interacting with the file system.selectModel: A function for selecting a model.askLlamaAboutEmotions: A function for analyzing emotions in text.ACTIVE_CONVERSATIONS: An object containing conversation data.PROJECT_PATH: A constant representing the project's root directory.DEFAULT_MODEL: A constant representing the default model to use.