• isContextRequiredForChatQuery

    • counts from a database if the query is similar to messages that require context. Has a low threshold of 0.02, so need to be really sure no context is needed.
  • There are predefined recipes you can click on

    export const recipesList = {
        'explain-code-detailed': 'Explain selected code (detailed)',
        'explain-code-high-level': 'Explain selected code (high level)',
        'generate-unit-test': 'Generate a unit test',
        'generate-docstring': 'Generate a docstring',
        'improve-variable-names': 'Improve variable names',
        'translate-to-language': 'Translate to different language',
        'git-history': 'Summarize recent code changes',
    }
    
  • Each Recipe’s main method is getInteraction()

  • ChatQuestion is also a Recipe - that’s the freeform one

    • getInteraction() = human prompt, empty asst, and .getContextMessages()
    • getContextMessages():
      • If isContextRequiredForChatQuery, then append codebaseContext.getContextMessages()

        • contextType defaults to embeddings (in VSC config). For this…
          • (context is split into multiple human messages followed by asst responding “Ok.”, truncated by token limit)

          • embeddings search (via Sourcegraph servers)

            • up to 8 code results and 2 text results
          • Snippets are included with:

            const CODE_CONTEXT_TEMPLATE = `Use following code snippet from file \\`{filePath}\\`:
            \\`\\`\\`{language}
            {text}
            \\`\\`\\``
            
          • There’s also slightly different handling of markdown

      • If code or editor context required (determined from regex for “current file” etc.), then append getEditorContext()

        • include visible content
        const CURRENT_EDITOR_CODE_TEMPLATE = `I have the \\`{filePath}\\` file opened in my editor. You are able to answer questions about \\`{filePath}\\`. The following code snippet is from the currently open file in my editor \\`{filePath}\\`:
        \\`\\`\\`{language}
        {text}
        \\`\\`\\``
        
  • Another example: GenerateTest

    • human:

      `Generate a unit test in ${languageName} for the following code:\\n\\`\\`\\`${extension}\\n${truncatedSelectedText}\\n\\`\\`\\`\\n${MARKDOWN_FORMAT_PROMPT}`
      
    • asst:

      `Here is the generated unit test:\\n\\`\\`\\`${extension}\\n`
      
    • getContextMessagesFromSelection: include similar snippets search for selection (codebase context), and include selection, using the standard codebase context stuff

  • Interaction(human, asst, context) = […context, human, asst]

  • Searches and sources are from Sourcegraph server, so it may be different from what’s local