The messageResume
function breaks down a large HTML resume into smaller sections, prompting the user for a short summary and related answers. It extracts text from the HTML, iterates over it in chunks, and returns an array of user responses joined by newline characters.
npm run import -- "brians resume"
const {selectDom} = importer.import("select tree")
// TODO: populate the context with details from my resume
async function messageResume(promptModel, session, prompt) {
let text = selectDom(['//*[text()]', './text()'], importer.interpret('brians resume in html').code)
let originalPrompt = 'This is part of Brian Cullinan\'s resume:\n'
let originalLength = originalPrompt.length
let answers = []
for(let i = 0; i < text.length; i++) {
originalPrompt += text[i]
if(originalPrompt.length > 2048) {
let q1 = originalPrompt + '\nWrite a short summary of this resume section.'
console.log('User: ' + q1)
answers.push(await promptModel(q1))
let a2 = await promptModel(originalPrompt
+ '\nAnswer this prompt, or respond No if it is not related to the question:\n'
+ prompt + '\nRespond with "No" if the prompt is unrelated.')
if(a2.trim() != 'No' && a2.trim() != 'No.') {
answers.push(a2)
}
originalPrompt = 'This is part of Brian Cullinan\'s resume:\n'
}
}
if(originalPrompt.length > originalLength) {
let q1 = originalPrompt + '\nWrite a short summary of this resume section.'
console.log('User: ' + q1)
answers.push(await promptModel(q1))
let a2 = await promptModel(originalPrompt
+ '\nAnswer this prompt, or respond No if it is not related to the question:\n'
+ prompt + '\nRespond with "No" if the prompt is unrelated.')
if(a2.trim() != 'No' && a2.trim() != 'No.') {
answers.push(a2)
}
}
return answers.join('\n')
}
module.exports = messageResume
const { selectDom } = require('./select-tree');
/**
* Message resume function to extract and summarize resume sections.
* @param {object} promptModel - Model for generating prompts and getting user responses.
* @param {object} session - Session object for the user.
* @param {string} prompt - Original prompt to guide the conversation.
* @returns {string} - Summarized answers from the user.
*/
async function messageResume({ promptModel, session, prompt }) {
const resumeHtml = await importer.interpret('brians resume in html');
const textNodes = selectDom(['//*[text()]', './text()'], resumeHtml.code);
const MAX_PROMPT_LENGTH = 2048;
const originalPrompt = 'This is part of Brian Cullinan\'s resume:\n';
const answers = [];
// Populate the context with details from the resume
for (const textNode of textNodes) {
let accumulatedPrompt = originalPrompt + textNode;
// Break the prompt into smaller chunks if it exceeds the maximum length
while (accumulatedPrompt.length > MAX_PROMPT_LENGTH) {
const chunk = accumulatedPrompt.substring(0, MAX_PROMPT_LENGTH + originalPrompt.length);
const question = chunk + '\nWrite a short summary of this resume section.';
console.log('User:', question);
answers.push(await promptModel(question));
const relatedResponse = await promptModel(
chunk +
'\nAnswer this prompt, or respond No if it is not related to the question:\n' +
prompt +
'\nRespond with "No" if the prompt is unrelated.'
);
// Only keep the response if it's not 'No' or 'No.'
if (relatedResponse.trim()!== 'No' && relatedResponse.trim()!== 'No.') {
answers.push(relatedResponse);
}
accumulatedPrompt = accumulatedPrompt.substring(MAX_PROMPT_LENGTH + originalPrompt.length);
}
// Add the last chunk of the prompt to the answers if it's not empty
if (accumulatedPrompt.length > originalPrompt.length) {
const question = accumulatedPrompt + '\nWrite a short summary of this resume section.';
console.log('User:', question);
answers.push(await promptModel(question));
const relatedResponse = await promptModel(
accumulatedPrompt +
'\nAnswer this prompt, or respond No if it is not related to the question:\n' +
prompt +
'\nRespond with "No" if the prompt is unrelated.'
);
// Only keep the response if it's not 'No' or 'No.'
if (relatedResponse.trim()!== 'No' && relatedResponse.trim()!== 'No.') {
answers.push(relatedResponse);
}
}
}
return answers.join('\n');
}
module.exports = messageResume;
Function: messageResume
Purpose: Splits a large HTML block of text (a resume) into smaller sections and prompts the user for a short summary and related answers.
Parameters:
promptModel
: A function that generates prompts and receives user responses.session
: The session object (not used in the function).prompt
: The original prompt to be answered (related to the resume section).Behavior:
selectDom
.answers
array.answers
array joined by newline characters.Export: The function is exported as a module, making it available for use in other scripts.