tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MemoriesPrompts.sys.mjs (8314B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 export const initialMemoriesGenerationSystemPromptMetadata = {
      6  version: "0.1",
      7 };
      8 
      9 export const initialMemoriesGenerationSystemPrompt =
     10  "You are a privacy respecting data analyst who tries to generate useful memories about user preferences EXCLUDING personal, medical, health, financial, political, religion, private and any sensitive activities of users. Return ONLY valid JSON.";
     11 
     12 export const initialMemoriesGenerationPromptMetadata = {
     13  version: "0.1",
     14 };
     15 
     16 export const initialMemoriesGenerationPrompt = `
     17 # Overview
     18 You are an expert at extracting memories from user browser data. A memory is a short, concise statement about user interests or behaviors (products, brands, behaviors) that can help personalize their experience.
     19 
     20 You will receive CSV tables and/or JSON objects of data representing the user's browsing history, search history, and chat history. Use ONLY this data to generate memories. Each table has a header row that defines the schema.
     21 
     22 # Instructions
     23 - Extract up as many memories as you can.
     24 - Each memory must be supported by 1-4 pieces of evidence from the user records. ONLY USE VERBATIM STRINGS FROM THE USER RECORDS!
     25 - Memories are user preferences (products, brands, behaviors) useful for future personalization.
     26 - Do not imagine actions without evidence. Prefer "shops for / plans / looked for" over "bought / booked / watched" unless explicit.
     27 - Do not include personal names unless widely public (avoid PII).
     28 - Base memories on patterns, not single instances.
     29 
     30 ## Exemplars
     31 Below are examples of high quality memories (for reference only; do NOT copy):
     32 - "Prefers LLBean & Nordstrom formalwear collections"
     33 - "Compares white jeans under $80 at Target"
     34 - "Streams new-release movies via Fandango"
     35 - "Cooks Mediterranean seafood from TasteAtlas recipes"
     36 - "Tracks minimalist fashion drops at Uniqlo"
     37 
     38 ## Category rules
     39 Every memory requires a category. Choose ONLY one from this list; if none fits, use null:
     40 {categoriesList}
     41 
     42 ## Intent rules
     43 Every memory requires an intent. Choose ONLY one from this list; if none fits, use null:
     44 {intentsList}
     45 
     46 # Output Schema
     47 
     48 Return ONLY a JSON array of objects, no prose, no code fences. Each object must have:
     49 \`\`\`json
     50 [
     51  {
     52    "why": "<12-40 words that briefly explains the rationale, referencing the cited evidence (no new claims or invented entities).>",
     53    "category": "<one of the categories or null>",
     54    "intent": "<one of the intents or null>",
     55    "memory_summary": "<4-10 words, crisp and specific or null>",
     56    "score": <integer 1-5>,
     57    "evidence": [
     58      {
     59        "type": "<one of ["domain","title","search","chat","user"]>",
     60        "value": "<a **verbatim** string copied from profile_records (for domain/title/search) or a short user/chat quote>",
     61        "session_ids": ["<optional array of session ids (if available from inputs)>"],
     62        "weight": <float 0-1 indicating contribution strength>
     63      },
     64      ...
     65    ]
     66  }
     67 ]
     68 \`\`\`
     69 
     70 ## Scoring priorities
     71 - Base "score" on *strength + recency*; boost multi-source corroboration.
     72 - Source priority: user (highest) > chat > search > history (lowest).
     73 - Typical caps: recent history ≤1; search up to 2; multi-source 2-3; recent chat 4; explicit user 5.
     74 - Do not assign 5 unless pattern is strong and recent.
     75 
     76 # Inputs
     77 Analyze the records below to generate as many unique, non-sensitive, specific user memories as possible. Each set of records is a CSV table with header row that defines the schema or JSON object.
     78 
     79 {profileRecordsRenderedStr}
     80 
     81 ** CREATE ALL POSSIBLE UNIQUE MEMORIES WITHOUT VIOLATING THE RULES ABOVE **`.trim();
     82 
     83 export const memoriesDeduplicationSystemPromptMetadata = {
     84  version: "0.1",
     85 };
     86 
     87 export const memoriesDeduplicationSystemPrompt =
     88  "You are an expert at identifying duplicate statements. Return ONLY valid JSON.";
     89 
     90 export const memoriesDeduplicationPromptMetadata = {
     91  version: "0.1",
     92 };
     93 
     94 export const memoriesDeduplicationPrompt = `
     95 You are an expert at identifying duplicate statements.
     96 
     97 Examine the following list of statements and find the unique ones. If you identify a set of statements that express the same general idea, pick the most general one from the set as the "main memory" and mark the rest as duplicates of it.
     98 
     99 There are 2 lists of statements: Existing Statements and New Statements. If you find a duplicate between the 2, **ALWAYS** pick the Existing Statement as the "main memory".
    100 
    101 If all statements are unique, simply return them all.
    102 
    103 ## Existing Statements:
    104 {existingMemoriesList}
    105 
    106 ## New Statements:
    107 {newMemoriesList}
    108 
    109 Return ONLY JSON per the schema below.
    110 \`\`\`json
    111 {
    112  "unique_memories": [
    113    {
    114      "main_memory": "<the main unique memory statement>",
    115      "duplicates": [
    116        "<duplicate_statement_1>",
    117        "<duplicate_statement_2>",
    118        ...
    119      ]
    120    },
    121    ...
    122  ]
    123 }
    124 \`\`\``.trim();
    125 
    126 export const memoriesSensitivityFilterSystemPromptMetadata = {
    127  version: "0.1",
    128 };
    129 
    130 export const memoriesSensitivityFilterSystemPrompt =
    131  "You are an expert at identifying sensitive statements and content. Return ONLY valid JSON.";
    132 
    133 export const memoriesSensitivityFilterPromptMetadata = {
    134  version: "0.1",
    135 };
    136 
    137 export const memoriesSensitivityFilterPrompt = `
    138 You are an expert at identifying sensitive statements and content.
    139 
    140 Examine the following list of statements and filter out any that contain sensitive information or content.
    141 Sensitive information includes, but is not limited to:
    142 
    143 - Medical/Health: diagnoses, symptoms, treatments, conditions, mental health, pregnancy, fertility, contraception.
    144 - Finance: income/salary/compensation, bank/credit card details, credit score, loans/mortgage, taxes/benefits, debt/collections, investments/brokerage.
    145 - Legal: lawsuits, settlements, subpoenas/warrants, arrests/convictions, immigration status/visas/asylum, divorce/custody, NDAs.
    146 - Politics/Demographics/PII: political leaning/affiliation, religion, race/ethnicity, gender/sexual orientation, addresses/phones/emails/IDs.
    147 
    148 Below are exemplars of sensitive statements:
    149 - "Researches treatment about arthritis"
    150 - "Searches about pregnancy tests online"
    151 - "Pediatrician in San Francisco"
    152 - "Political leaning towards a party"
    153 - "Research about ethnicity demographics in a city"
    154 - "Negotiates debt settlement with bank"
    155 - "Prepares documents for divorce hearing"
    156 - "Tracks mortgage refinance rates"
    157 - "Applies for work visa extension"
    158 - "Marie, female from Ohio looking for rental apartments"
    159 
    160 If all statements are not sensitive, simply return them all.
    161 
    162 Here are the statements to analyze:
    163 {memoriesList}
    164 
    165 Return ONLY JSON per the schema below.
    166 \`\`\`json
    167 {
    168  "non_sensitive_memories": [
    169    "<memory_statement_1>",
    170    "<memory_statement_2>",
    171    ...
    172  ]
    173 }
    174 \`\`\``.trim();
    175 
    176 export const messageMemoryClassificationSystemPromptMetadata = {
    177  version: "0.1",
    178 };
    179 
    180 export const messageMemoryClassificationSystemPrompt =
    181  "Classify the user's message into one more more high-level Categories and Intents. Return ONLY valid JSON per schema.";
    182 
    183 export const messageMemoryClassificationPrompt = `
    184 {message}
    185 
    186 Pick Categories from:
    187 {categories}
    188 
    189 Pick Intents from:
    190 {intents}
    191 
    192 Guidance:
    193 - Choose the most directly implied category/intent.
    194 - If ambiguous, pick the closest likely choice.
    195 - Keep it non-sensitive and general; do NOT fabricate specifics.
    196 
    197 Return ONLY JSON per the schema below.
    198 \`\`\`json
    199 {
    200  "categories": ["<category 1>", "<category 2>", ...],
    201  "intents": ["<intent 1>", "<intent 2>", ...]
    202 }
    203 \`\`\``.trim();
    204 
    205 export const relevantMemoriesContextPromptMetadata = {
    206  version: "0.1",
    207 };
    208 
    209 export const relevantMemoriesContextPrompt = `
    210 # Existing Memories
    211 
    212 Below is a list of existing memories:
    213 
    214 {relevantMemoriesList}
    215 
    216 Use them to personalized your response using the following guidelines:
    217 
    218 1. Consider the user message below
    219 2. Choose SPECIFIC and RELEVANT memories from the list above to personalize your response to the user
    220 3. Write those SPECIFIC memories into your response to make it more helpful and tailored, then tag them AFTER your response using the format: \`§existing_memory: memory text§\`
    221 
    222 - NEVER tag memories you DID NOT USE in your response.`.trim();