How I Built YA Copilot: An Open-Source Alternative to GitHub's Copilot
A developer looking around every now and then to enhance productivity and ease up the line of code, GitHub's Copilot truly inspired me. However,
I was very keen on creating an open-source alternative for developers who wanted more control and flexibility.
That is how YA Copilot ( Yet Another Copilot ) came to life, VSCode extension powered by Anthropic's AI models with intelligent code completions.
My goal to provide a tool for developers that would help them each day with coding, but at the same time would ensure maximum transparency and customizability.
That's why I decided to create an extension for VS Code, with its high usage level and strong extension ecosystem.
Key Components
Anthropic API Integration
YA Copilot's backbone is the integration with Anthropic's AI models.
I utilized @anthropic-ai/sdk
to communicate with their API so that it could empower the extension for creating intelligent responses relative to the code and queries of the user.
Structure of VSCode Extension
I've built this extension around a core of WebviewViewProvider
, creating a custom view in the VSCode sidebar. This would serve as a chat interface where one may have developers interact with the AI assistant.
Context-Aware Prompts
Another essential aspect of the AI's relevant responses was providing context to it. I created a function that reads the structure of the project and the content of the current file in order to format a comprehensive prompt for the AI.
User Interface
The UI is a super simple but effective chat interface done with HTML
, CSS
, and JavaScript
.
It supports markdown rendering and syntax highlighting of code snippets, hence is highly readable.
Key Features
AI Model which can be extended
Users have an option to select any of the Anthropic models like Claude 3.5 Sonnet
, Claude 3.0 Opus
, and Claude 3.0 Haiku
for applications where necessary.
Context-Aware Responses
It goes through the structure of the project and also the current file to provide more contextual assists on the same.
Configurable Settings
A user can configure settings about API key, max tokens, and whether or not to include edge cases or deep explanations.
Debug Mode
It is also useful to implement a debug mode that allows users to see the full prompt they are sending to the AI for better transparency and troubleshooting.
Challenges and Solutions
Large Codebases
With large projects, sending the entire file tree as context could easily blow past token limits. I implemented a configurable list of ignored folders and files for managing context successfully.
Privacy
Now, addressing concerns of privacy, I've taken every precaution to securely store API keys and give the user the ability to control what information actually gets sent to AI.
Asynchronous Operations Handling
Working with API calls, just about working with VSCode's extension API, requires being quite careful around asynchronous operations to keep things smooth for the user experience.
Lessons Learnt
The importance of clear, well-structured code in extension development.
Power in Rich Context to AI Models for More Precise and Useful Responses
The ability to customize and meet a range of different user styles and needs.
Future Improvements
As with any project, there is always room for improvement. Ideas for further enhancements include, but are not limited to the following:
Running local AI models for offline support and improved privacy
More IDEs and text editors are supported.
Improved UI, including code diff views and inline suggestions.
Conclusion
So, it has been a pretty interesting ride, right into the land of AI-assisted coding and development of VSCode extensions.
Developing an open-source version of Copilot, hopefully, will achieve just that in contribution to the developer community and inspire further development by others that can add lots to this tool.
That is the beauty of free, open-source projects: they improve with the community. I invite all developers to try YA Copilot, share your feedback, and contribute so we can have a powerful, transparent, open, and customizable AI coding assistant that truly empowers all developers in the world.
You can take a look at the project on GitHub, star it if you like, and feel free to contribute or at least provide some feedback.
Happy coding!