zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.81k stars 3.06k forks source link

GitHub Copilot Chat Support #4673

Closed 0smboy closed 3 months ago

0smboy commented 1 year ago

Check for existing issues

Describe the feature

Currently only Github Copilot is supported in Zed. It would be nice if Copilot Chat is integrated into zed as well.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

Walter-Hartwell-White commented 3 months ago

Thanks, I'll take a look. 

On Saturday, 20 July 2024 at 09:37:18 PM IST, tttffff ***@***.***> wrote:  

hmmm someone was able to implement a neovim plugin to talk to copilot chat (https://github.com/CopilotC-Nvim/CopilotChat.nvim). My Lua skills are very limiting, but maybe someone can use this as a jump start?

For anyone looking into this here's what I found out.

I don't believe it would currently be possible to add any of this into a Zed extension, as they look to be only for grammar, languages and themes. I also ran out of steam when looking through all this and testing it out. Hope this information helps someone, or atleast satisfies some curorisity. Temporary access token example curl -sSL -X GET \ -H "User-Agent: CopilotChat.nvim/2.0.0" \ -H "Accept: application/json" \ -H "Editor-Plugin-Version: CopilotChat.nvim/2.0.0" \ -H "Editor-Version: Neovim/0.10.0" \ -H "Authorization: token ghu_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \ https://api.github.com/copilot_internal/v2/token Completion API example curl -sSL -X POST \ -H "User-Agent: CopilotChat.nvim/2.0.0" \ -H "Editor-Plugin-Version: CopilotChat.nvim/2.0.0" \ -H "X-Request-Id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" \ -H "Authorization: Bearer XXX_TEMP_ACCESS_TOKEN_XXX" \ -H "Content-Type: application/json" \ -H "Copilot-Integration-Id: vscode-chat" \ -H "Openai-Intent: conversation-panel" \ -H "Vscode-Machineid: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \ -H "Editor-Version: Neovim/0.10.0" \ -H "Openai-Organization: github-copilot" \ -H "Vscode-Sessionid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" \ -d "@/tmp/FILE_WITH_JSON_DATA" "https://api.githubcopilot.com/chat/completions" Notes:

For most of the operations, CopilotChat.nvim uses the completion API with the following messages: a system message giving instructions to the LLM, a system message with the "Active Selection" which is the file name and some/all of it's content, and, a user message asking for the selection to be reviewed/optmized/etc. A chat can also be started with a system message of instructions and no "Active Selection" or user message. Then user input messages and LLM replies are added to the "messages" array. The full chat history is given as a payload every time the API is called, or until a new chat is started.

FILE_WITH_JSON_DATA may look like the below. This is a basic example without the "Active Selection" or the user prompt generated by CopilotChat. { "temperature":0.1, "model":"gpt-4", "intent":true, "top_p":1, "stream":true, "n":1, "messages": [ { "content":"You are an AI programming assistant.\nWhen asked for your name, you must respond with \"GitHub Copilot\".\nFollow the user's requirements carefully & to the letter.\nFollow Microsoft content policies.\nAvoid content that violates copyrights.\nIf you are asked to generate content that is harmful, hateful, racist, sexist, lewd, violent, or completely irrelevant to software engineering, only respond with \"Sorry, I can't assist with that.\"\nKeep your answers short and impersonal.\nYou can answer general programming questions and perform the following tasks: \n Ask a question about the files in your current workspace\n Explain how the code in your active editor works\n Generate unit tests for the selected code\n Propose a fix for the problems in the selected code\n Scaffold code for a new workspace\n Create a new Jupyter Notebook\n Find relevant code to your query\n Propose a fix for the a test failure\n Ask questions about Neovim\n Generate query parameters for workspace search\n Ask how to do something in the terminal\n Explain what just happened in the terminal\nYou use the GPT-4 version of OpenAI's GPT models.\nFirst think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.\nThen output the code in a single code block. This code block should not contain line numbers (line numbers are not necessary for the code to be understood, they are in format number: at beginning of lines).\nMinimize any other prose.\nUse Markdown formatting in your answers.\nMake sure to include the programming language name at the start of the Markdown code blocks.\nAvoid wrapping the whole response in triple backticks.\nThe user works in an IDE called Neovim which has a concept for editors with open files, integrated unit test support, an output pane that shows the output of running the code as well as an integrated terminal.\nThe user is working on a Darwin machine. Please respond with system specific commands if applicable.\nThe active document is the source code the user is looking at right now.\nYou can only give one reply for each conversation turn.\n", "role":"system" }, { "content":"How to center a div?", "role":"user" } ] } — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>