This code defines a set of functions and constants to facilitate interacting with an API, including generating a description of the API functions and asking the user to match a prompt with an API function. The code exports four values, allowing other parts of the program to access and use the API functions and their corresponding exports and descriptions.
npm run import -- "classify llm prompt"const getExports = importer.import("get exports from source")
const API_FUNCTIONS = [
'load message history',
'general chit chat',
'brians resume',
'file system access',
'access web information',
'stable diffusion request',
'request ollama vision',
//'ask another llm for help',
'add conversation context',
'llm save memories'
// 'switch llm models'
]
const API_EXPORTS = API_FUNCTIONS.map(func => getExports(importer.interpret(func).code)[0])
const API_DESCRIPTION = API_FUNCTIONS
.map(func => importer.interpret(func))
.filter((code, i) => API_EXPORTS[i])
.map((code, i) => API_EXPORTS[i] + ' - ' + code.markdown.join('').trim()
.replaceAll(/^#.*?\n/gi, '')
.replaceAll(code.questions, '')
.replaceAll(/\s*[\n]+[\s\r\n]*/gi, '-'))
.join('\n')
async function askLlamaMatchingFunction(promptModel, prompt, image) {
let q1 = 'Given the following functions:\n'
+ API_DESCRIPTION + '\nDo any of these functions relate to this prompt:\n'
+ (image ? 'An image has been provided as a part of the input.' : '')
+ prompt + '\nOnly return the function names in order of relevance.'
console.log('User: ' + q1)
let a1 = await promptModel(q1)
console.log('AI: ' + a1)
let matchingFunctions = a1.split(/\s*\n\s*|\s*,\s*/gi)
.map((matchStr) => {
for (let i = 0; i < API_FUNCTIONS.length; i++) {
if (!API_EXPORTS[i]) {
continue
}
if (API_EXPORTS[i].includes(matchStr) || matchStr.match(API_EXPORTS[i])) {
return ({
importStr: API_FUNCTIONS[i],
exportStr: API_EXPORTS[i]
})
}
}
})
.filter(func => a1.length > 0 && func)
.map(func => func.importStr)
return matchingFunctions
}
module.exports = {
askLlamaMatchingFunction,
API_FUNCTIONS,
API_EXPORTS,
API_DESCRIPTION,
}
const API_FUNCTIONS = [
'Load Message History',
'General Chit Chat',
'Brian\'s Resume',
'File System Access',
'Access Web Information',
'Stable Diffusion Request',
'Request Ollama Vision',
// 'Ask Another LLM for Help',
'Add Conversation Context',
'LLM Save Memories',
// 'Switch LLM Models'
]Breakdown of the Code
getExports is a function that imports and exports functionality from a source.API_FUNCTIONS is an array of API function names.API_EXPORTS is an array of API function exports, obtained by calling getExports for each function in API_FUNCTIONS.API_DESCRIPTION is a string containing a description of the API functions, generated by mapping over API_FUNCTIONS, interpreting each function as Markdown, filtering out empty descriptions, and combining the results.askLlamaMatchingFunction FunctionaskLlamaMatchingFunction takes three arguments: promptModel, prompt, and image.askLlamaMatchingFunction: the function that can be used to ask the user to match a prompt with an API function.API_FUNCTIONS: the array of API function names.API_EXPORTS: the array of API function exports.API_DESCRIPTION: the string describing the API functions.