Are you fed up of all of those so called "free" Copilot alternatives with paywalls and signups? Fear not my developer friend! Twinny is the most no-nonsense locally hosted (or api hosted) AI code completion plugin for Visual Studio Code designed to work seamlessly with Ollama, llama.cpp and LM Studio. Like Github Copilot but 100% free and 100% private.
Fill in the middle code completion:
![](https://private-user-images.githubusercontent.com/5537428/300016455-69f567c0-2700-4474-b621-6099255bc87b.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxODcwNTcsIm5iZiI6MTcxOTE4Njc1NywicGF0aCI6Ii81NTM3NDI4LzMwMDAxNjQ1NS02OWY1NjdjMC0yNzAwLTQ0NzQtYjYyMS02MDk5MjU1YmM4N2IuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjNUMjM1MjM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTU5MWQ5NWU5YTM5ZTk3MGMwMWFkNWZlNjYwMjVhYTQ1NjZmZGMxYmE2NDhlZDU1Zjc5NDI0YTc2NjU1MzhiNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.eVuzNDRQ_niXcn2sH54uIm8BgbonO2tpfV2Wh2qMpQg)
Chat with AI about your code
![](https://private-user-images.githubusercontent.com/5537428/296261810-679bd283-28e9-47ff-9165-84dfe293c56a.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxODcwNTcsIm5iZiI6MTcxOTE4Njc1NywicGF0aCI6Ii81NTM3NDI4LzI5NjI2MTgxMC02NzliZDI4My0yOGU5LTQ3ZmYtOTE2NS04NGRmZTI5M2M1NmEuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjNUMjM1MjM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTBmODVjMmNlMjI4ODU2N2I0MjE3YjA0YTVjMzlhNTMyM2ZjMmZmM2NjMTk4YjdkMDFkMjJiMTU1NmE1OTdhZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.o93MOsb3SIHqFu8gRQz5FiaTq7M81NrDb2-VAqTkmUM)
- Configurable single or multiline fill-in-middle completions
- Configurable prompt templates add, edit, remove, delete and set as default
- Easy installation and setup
- Ollama, llamacpp and LM Studio API compatible
- Accept code solutions directly to editor
- Create new documents from code blocks
- Copy generated code solution blocks
- Chat history preserved per workspace
Install the verified extension at this link or find the extension in the extensions section of Visual Studio Code marketplace.
Twinny is configured to use Ollama by deafult. Therefore, when installing the twinny extension in Visual Studio Code, it will automatically prompt and guide you through the installation of Ollama using two default small models codellama:7b-instruct
for chat and codellama:7b-code
for "fill in the middle" completions.
If you already have Ollama installed or you want to use llama.cpp or LM Studio instead, you can cancel the automatic setup of Ollama and proceed to update the values inside twinny extension settings to point to your existing models and server. At this point it's a good idea to set Disable Server Checks
option to true which this will disable the checks on startup.
You can find the settings inside the extension sidebar by clicking the gear icon inside the twinny sidebar or by searching for twinny
in the extensions search bar.
When choosing an API provider the port and API path names will be updated automatically based on the provider you choose to use.
If you are using llama.cpp - The twinny settings for FIM model name and Chat model name will be ignored, as this should already be configured when running the llama.cpp server.
When the extension is ready you will see a ๐ค
icon at the bottom of your code editor.
Enjoy enhanced code completions and chat with twinny! ๐
FIM
- If using Llama the model must support the llama special tokens for prefix and suffix if using codellama models.
- If using deepseek only use base models for FIM completions for example
deepseek-coder:base
anddeepseek-coder:6.7b-base-q5_K_M
stable-code:code
has been tested and works for FIM.
Chat
- All instruct models should work but prompt templates might need editing if using something other than codellama.
Shortcut | Description |
---|---|
ALT+\ |
Trigger inline code completion |
CTRL+SHIFT+t |
Open twinny sidebar |
CTRL+SHIFT+/ |
Stop code generation |
- If the server settings are incorrectly set chat and fim completion will not work, if this is the case please open an issue with your error message.
- Some models may not support the special tokens of Llama which means they would not work correctly for FIM completions.
- Sometimes a restart of vscode is required for new settings to take effect.
- Using file context often causes unreliable completions for FIM because small models get confused when provided with more than one file context.
- See open issues for more information
If you have a suggestion for improvement please open an issue and I will do my best to make it happen!
We are actively looking for contributors who want to help improve the project, if you are interested in helping out please reach out on twitter.
Contributions are welcome please open an issue describing your changes and open a pull request when ready.
This project is under MIT licence, please read the LICENSE file for more information.