brians resume | load message history | file system access | Search

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.

Run example

npm run import -- "brians resume"

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

What the code could have been:

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:

Behavior:

  1. Extracts text from the HTML code using selectDom.
  2. Iterates over the text in chunks of 2048 characters or less.
  3. For each chunk:
  4. After iterating over all chunks, sends the remaining prompt to the user with the same requests as above.
  5. Returns the answers array joined by newline characters.

Export: The function is exported as a module, making it available for use in other scripts.