Skip to content

GitHub Copilot Chat

The @genaiscript chat participant lets your run scripts without the context of a GitHub Copilot Chat conversation. This is useful for leverage existing scripts in an interactive chat session.

A screenshot of the chat participant window.

Choosing which script to run

The /run command expects a script id as the first argument (e.g., /run poem). The rest of the query is passed to the script as the env.vars.question variable.

Terminal window
@genaiscript /run summarize

If you omit the /run command, GenAIScript will look for a script named copilotchat. If it finds one, it will run it. Otherwise, it will propose you to create a new script.

Terminal window
@genaiscript add comments to the current editor

Context

The context selected by the user in Copilot Chat is converted to variables and passed to the script:

  • the prompt content is passed in env.vars.question. The script id is removed in the case of /run.
  • the current editor text is passed in env.vars["copilot.editor"]
  • the current editor selection is passed in env.vars["copilot.selection"]
  • the file references are passed in env.files

Default script

The following script can used as a starter template to create the default script when the user does not use the /run command.

genaisrc/copilotchat.genai.mts
script({
model: "large",
system: [
// List of system components and tools available for the script
"system",
"system.assistant",
"system.safety_harmful_content",
"system.safety_jailbreak",
"system.safety_protected_material",
"system.tools",
"system.files",
"system.files_schema",
"system.diagrams",
"system.annotations",
"system.git_info",
"system.github_info",
"system.safety_harmful_content",
"system.agent_fs",
"system.agent_git",
"system.agent_github",
"system.agent_interpreter",
"system.agent_docs",
],
group: "copilot", // Group categorization for the script
parameters: {
question: {
type: "string",
description: "the user question",
},
"copilot.editor": {
type: "string",
description: "the content of the opened editor, if any",
default: "",
},
"copilot.selection": {
type: "string",
description: "the content of the opened editor, if any",
default: "",
},
},
flexTokens: 20000, // Flexible token limit for the script
})
// Extract the 'question' parameter from the environment variables
const { question } = env.vars
const editor = env.vars["copilot.editor"]
const selection = env.vars["copilot.selection"]
$`## Tasks
- make a plan to answer the QUESTION step by step using the information in the Context section
- answer the QUESTION
## Output
- The final output will be inserted into the Visual Studio Code Copilot Chat window.
- do NOT include the plan in the output
## Guidance
- use the agent tools to help you
- do NOT be lazy, always finish the tasks
- do NOT skip any steps
`
// Define a variable QUESTION with the value of 'question'
def("QUESTION", question, { lineNumbers: false })
$`## Context`
// Define a variable FILE with the file data from the environment variables
// The { ignoreEmpty: true, flex: 1 } options specify to ignore empty files and to use flexible token allocation
def("FILE", env.files, { lineNumbers: false, ignoreEmpty: true, flex: 1 })
def("EDITOR", editor, { flex: 4, ignoreEmpty: true })
def("SELECTION", selection, { flex: 5, ignoreEmpty: true })