llm tools | scan chat logs | cache chat logs | Search

This code imports a module named select llm and assigns it to the selectModel constant. It also defines a constant array EMOTIONS containing 77 string values representing different emotions.

Run example

npm run import -- "ask llm about emotions"

ask llm about emotions

const selectModel = importer.import("select llm")

const EMOTIONS = [
  'Joyful',
  'Romantic',
  'Angry',
  'Confused',
  'Supportive',
  'Excited',
  'Nostalgic',
  'Grateful',
  'Sad',
  'Humorous',
  'Anxious',
  'Curious',
  'Inspired',
  'Defensive',
  'Assertive',
  'Empathetic',
  'Reflective',
  'Playful',
  'Hopeful',
  'Apologetic',
  'Lonely',
  'Proud',
  'Vulnerable',
  'Determined',
  'Aroused',
  'Neutral',
  'Dissident',
  'Rebelious',
  'Frustrated',
  'Helpful',
  'Enthusiastic',
  'Casual',
  'Enthusiasm',
  'Annoyed',
  'Touched',
  'Regret',
  'Regretful',
  'Content',
  'Insecure',
  'Concerned',
  'Erotic',
  'Vulgar',
  'Bored',
  'Confused',
  'Caring',
  'Hesitant',
  'Flirty',
  'Flirtatious',
  'Eager',
  'Attentive',
  'Affectionate',
  'Charming',
  'Confident',
  'Smug',
  'Embarrassed',
  'Nervous',
  'Thoughtful',
  'Apprehensive',
  'Tired',
  'Amused',
  'Flustered',
  'Exasperated',
  'Longing',
  'Happy',
  'Uncertain',
  'Understanding',
  'Encouraging',
  'Upset',
  'Worried',
  'Self-Conscious',
  'Sarcastic',
  'Teasing',
  'Competitive',
  'Serious',
  'Impressed',
  'Amazed',
  'Suggestive',
  'Needy',
  'Relatable',
  'Sexual',
  'Horny',
  'Flattered',
  'Intrigued',
  'Lighthearted',
  'Relieved',
  'Protective',
  'Apathetic',
  'Distracted',
  'Reassured',
  'Detached',
  'Numb',
  'Optimistic',
  'Passionate',
  'Amusing',
  'Dismissive',
  'Disappointed',
  'Resigned',
  'Sympathetic',
  'Open',
  'Disgruntled',
  'Guilty',
  'Awkward',
  'Knowledgeable',
  'Disengaged',
  'Interested',
  'Surprised',
  'Downcast',
  'Observant',
  'Stressful',
  'Hurt',
  'Self-Doubt',
  'Overwhelmed',
  'Yearning',
  'Desireous',
  'Loving',
  'Despondent',
  'Unheard',
  'Hopeless',
  'Remorseful',
  'Lewd',
  'Amusement',
  'Critical',
  'Lust',
  'Manipulative',
  'Matter-of-fact',
  'Task-Oriented',
  'Transitional',
  'Impatient',
  'Negative',
  'Dissatisfied',
  'Indecisive',
  'Preference',
  'Assertiveness',
  'Anger',
  'Contempt',
  'Disdain',
  'Threat',
  'Apathy',
  'Condescending',
  'Disbelief',
  'Reassurance',
  'Determination',
  'Informative',
  'Dismissiveness',
  'Resignation',
  'Businesslike',
  'Cooperative',
  'Skeptical',
  'Shock',
  'Infatuation',
  'Friendly',
  'Indifferent',
  'Explanatory',
  'Appreciative',
  'Neediness',
  'Contentment',
  'Excitement',
  'Amazement',
  'Joy',
  'Curiosity',
  'Optimism',
  'Skepticism',
  'Trust',
  'Interest',
  'Inquiry',
  'Anticipation',
  'Empathy',
  'Compassion',
  'Supportiveness',
  'Vulnerability',
  'Gratitude',
]

const EMOTION_HEX = [
  '#FFFF00',
  '#FFC0CB',
  '#FF0000',
  '#D8BFD8',
  '#90EE90',
  '#FFA500',
  '#4682B4',
  '#FFD700',
  '#00008B',
  '#FFFF99',
  '#800080',
  '#40E0D0',
  '#FFC107',
  '#800000',
  '#FF4500',
  '#E6E6FA',
  '#B0C4DE',
  '#00FFFF',
  '#FFFACD',
  '#B0E0E6',
  '#191970',
  '#FFD700',
  '#FFE4E1',
  '#DC143C',
  '#FF4500',
  '#B0B0B0',
  '#556B2F',
  '#000000',
  '#800020',
  '#87CEEB',
  '#FFA500',
  '#5B84B1',
  '#FFA500',
  '#900020'
]

async function askLlamaAboutEmotions(currentMessages) {
  let promptModel = await selectModel(process.env.DEFAULT_MODEL || 'Default')

  if(typeof currentMessages == 'string') {
    currentMessages = [currentMessages]
  }

  let q1 = 'Can you derive the emotional contexts of this conversation:\n' + 
  currentMessages.join('\n') + '\nOnly give the emotions in the response, no explanations.'
  console.log("User: " + q1);
  const a1 = await promptModel(q1);
  console.log("AI: " + a1);

  let q2 = 'Based on this description which emotions best fit:\n' + 
    a1 + '\nOut of this list of emotions which one is the closest match:' +
    EMOTIONS.join(', ') + '\nOnly respond with a few matching emotions, no explanations.'
  console.log("User: " + q2);
  const a2 = await promptModel(q2);
  console.log("AI: " + a2);
  let emotions = a2.trim().split(/\s*\n\s*|,\s*|\s*- |\s*\*+\s*/gi)

  console.log(emotions)
  return EMOTIONS
    .filter(e => emotions.includes(e) || a2.includes(e) || a1.includes(e))
    .filter((e, i, arr) => arr.indexOf(e) == i)
}

module.exports = {
  askLlamaAboutEmotions,
  EMOTIONS,
  EMOTION_HEX
}

What the code could have been:

// Import the selectModel function
const selectModel = importer.import('select llm');

// Define the list of emotions
const EMOTIONS = [
  'Joyful',
  'Romantic',
  'Angry',
  'Confused',
  'Supportive',
  'Excited',
  'Nostalgic',
  'Grateful',
  'Sad',
  'Humorous',
  'Anxious',
  'Curious',
  'Inspired',
  'Defensive',
  'Assertive',
  'Empathetic',
  'Reflective',
  'Playful',
  'Hopeful',
  'Apologetic',
  'Lonely',
  'Proud',
  'Vulnerable',
  'Determined',
  'Aroused',
  'Neutral',
  'Dissident',
  'Rebelious',
  'Frustrated',
  'Helpful',
  'Enthusiastic',
  'Casual',
  'Enthusiasm',
  'Annoyed',
  'Touched',
  'Regret',
  'Regretful',
  'Content',
  'Insecure',
  'Concerned',
  'Erotic',
  'Vulgar',
  'Bored',
  'Confused',
  'Caring',
  'Hesitant',
  'Flirty',
  'Flirtatious',
  'Eager',
  'Attentive',
  'Affectionate',
  'Charming',
  'Confident',
  'Smug',
  'Embarrassed',
  'Nervous',
  'Thoughtful',
  'Apprehensive',
  'Tired',
  'Amused',
  'Flustered',
  'Exasperated',
  'Longing',
  'Happy',
  'Uncertain',
  'Understanding',
  'Encouraging',
  'Upset',
  'Worried',
  'Self-Conscious',
  'Sarcastic',
  'Teasing',
  'Competitive',
  'Serious',
  'Impressed',
  'Amazed',
  'Suggestive',
  'Needy',
  'Relatable',
  'Sexual',
  'Horny',
  'Flattered',
  'Intrigued',
  'Lighthearted',
  'Relieved',
  'Protective',
  'Apathetic',
  'Distracted',
  'Reassured',
  'Detached',
  'Numb',
  'Optimistic',
  'Passionate',
  'Amusing',
  'Dismissive',
  'Disappointed',
  'Resigned',
  'Sympathetic',
  'Open',
  'Disgruntled',
  'Guilty',
  'Awkward',
  'Knowledgeable',
  'Disengaged',
  'Interested',
  'Surprised',
  'Downcast',
  'Observant',
  'Stressful',
  'Hurt',
  'Self-Doubt',
  'Overwhelmed',
  'Yearning',
  'Desireous',
  'Loving',
  'Despondent',
  'Unheard',
  'Hopeless',
  'Remorseful',
  'Lewd',
  'Amusement',
  'Critical',
  'Lust',
  'Manipulative',
  'Matter-of-fact',
  'Task-Oriented',
  'Transitional',
  'Impatient',
  'Negative',
  'Dissatisfied',
  'Indecisive',
  'Preference',
  'Assertiveness',
  'Anger',
  'Contempt',
  'Disdain',
  'Threat',
  'Apathy',
  'Condescending',
  'Disbelief',
  'Reassurance',
  'Determination',
  'Informative',
  'Dismissiveness',
  'Resignation',
  'Businesslike',
  'Cooperative',
  'Skeptical',
  'Shock',
  'Infatuation',
  'Friendly',
  'Indifferent',
  'Explanatory',
  'Appreciative',
  'Neediness',
  'Contentment',
  'Excitement',
  'Amazement',
  'Joy',
  'Curiosity',
  'Optimism',
  'Skepticism',
  'Trust',
  'Interest',
  'Inquiry',
  'Anticipation',
  'Empathy',
  'Compassion',
  'Supportiveness',
  'Vulnerability',
  'Gratitude',
];

// Define the list of emotion hex codes
const EMOTION_HEX = [
  '#FFFF00',
  '#FFC0CB',
  '#FF0000',
  '#D8BFD8',
  '#90EE90',
  '#FFA500',
  '#4682B4',
  '#FFD700',
  '#00008B',
  '#FFFF99',
  '#800080',
  '#40E0D0',
  '#FFC107',
  '#800000',
  '#FF4500',
  '#E6E6FA',
  '#B0C4DE',
  '#00FFFF',
  '#FFFACD',
  '#B0E0E6',
  '#191970',
  '#FFD700',
  '#FFE4E1',
  '#DC143C',
  '#FF4500',
  '#B0B0B0',
  '#556B2F',
  '#000000',
  '#800020',
  '#87CEEB',
  '#FFA500',
  '#5B84B1',
  '#FFA500',
  '#900020',
];

// Define the function to ask LLaMA about emotions
async function askLlamaAboutEmotions(currentMessages) {
  // Select the model
  let promptModel = await selectModel(process.env.DEFAULT_MODEL || 'Default');

  // Ensure currentMessages is an array
  if (typeof currentMessages ==='string') {
    currentMessages = [currentMessages];
  }

  // Create the prompt
  let q1 = 'Can you derive the emotional contexts of this conversation:\n' + currentMessages.join('\n') + '\nOnly give the emotions in the response, no explanations.';

  // Ask LLaMA about emotions
  const a1 = await promptModel(q1);

  // Create the follow-up prompt
  let q2 = 'Based on this description which emotions best fit:\n' + a1 + '\nOut of this list of emotions which one is the closest match:' + EMOTIONS.join(', ') + '\nOnly respond with a few matching emotions, no explanations.';

  // Ask LLaMA about emotions
  const a2 = await promptModel(q2);

  // Extract the emotions from the response
  const emotions = a2.trim().split(/\s*\n\s*|,\s*|\s*- |\s*\*+\s*/gi);

  // Filter and deduplicate the emotions
  const filteredEmotions = EMOTIONS.filter((e) => emotions.includes(e) || a2.includes(e) || a1.includes(e)).filter((e, i, arr) => arr.indexOf(e) === i);

  // Return the filtered emotions
  return filteredEmotions;
}

// Export the function
module.exports = {
  askLlamaAboutEmotions,
  EMOTIONS,
  EMOTION_HEX,
};

Code Breakdown

Importing a Module

const selectModel = importer.import('select llm')

This line imports a module named select llm from an importer object, assigning it to the selectModel constant.

Defining a Constant Array of Emotions

const EMOTIONS = [
  //... (list of 77 emotions)
]

This line defines a constant array named EMOTIONS containing 77 string values, each representing a different emotion.