How to Use LM Studio for AI Assistance in Visual Studio Code
In our previous article, we explored several code editors with built-in AI features. However, these features often rely on a cloud connection and may require subscriptions to access all functionalities. This can be inconvenient if you’re working offline or find the subscription costs outweigh the benefits.
If you’re looking for a free and offline alternative, LM Studio is a great option. This desktop application allows you to run powerful Large Language Models (LLMs) directly on your computer. You can even choose from various models available through the Ollama platform.
In this article, we’ll see how to use LM Studio with Visual Studio Code (VS Code) to get AI assistance in the code editor. We’ll cover setting it up, connecting it to VS Code, and using the AI assistance features.
What You’ll Need
First and foremost, let’s make sure you have a couple of things ready:
- LM Studio: This will be the app that allows us to run AI models locally on our computer. If you haven’t already, check out our guide on how to set it up: How to Run LLM Locally on Your Computer with LM Studio.
- VS Code: If you don’t have it yet, you can download it from the official source.
Setting Up LM Studio
First, open LM Studio and download the LLM you want to use.
For coding assistance, it’s best to choose a model specifically trained on code. In this example, we’ll use the “Qwen2.5 Coder” model with 14 billion parameters.
However, it’s also important to select a model that runs smoothly on your computer. If the 14B parameter model is too heavy, consider trying the 3B parameter version.
Once you’ve downloaded the LLM, load it in LM Studio and start the server. You’ll find the server controls in the “Developers” panel of the sidebar as shown in the screenshot below. The server should start running at http://localhost:1234
, and you’ll see the available endpoints listed.
Connecting LM Studio to VS Code
To leverage LM Studio’s AI power within VS Code, we’ll install the open-source extension, Continue.dev. This extension specializes in AI code assistance, making it a perfect fit for our needs.
After installation, you’ll see a new tab appear in the VS Code sidebar. This is the “Continue” tab.
Within the tab, we can find the Chat field where you can interact with the AI assistance.
While the Chat field seems functional, it won’t work or respond to your queries yet. We need to select the LLM model for the Chat to use. To enable it, click on the Model option at the bottom of the field and select + Add Chat model
Select “LLM Studio” as the Provider and “Autodetect” as the Model.
Once connected, the Chat field will display available LLM models from LM Studio. In this example, we’ll choose the “Qwen2.5 Coder with 14B” model that we’ve downloaded and set up in LM Studio.
Using the Chat Field
The Chat field works similarly to other AI assistants. You can interact with it by asking questions, requesting suggestions, or even generating code snippets. Here are some examples:
Ask for a simple HTML document snippet:
Use the @
symbol and select “Files” to provide context. For example, attach the current file to generate a docblock for a specific component.
Configuring Autocompletion
Autocompletion is one of the most common features found in AI-powered code editors. In this case, with Continue.dev + VS Code setup, it might not be enabled yet. To enable it, open the config file at ~/.continue/config.json
, and add in the following to connect the autocompletion to LM Studio.
{ "tabAutocompleteModel": { "apiBase": "http://localhost:1234/v1/", "title": "Qwen2.5-Coder 14B", "provider": "lmstudio", "model": "qwen2.5-coder:14b" } }
Once that’s set up and saved, you should see the autocompletion working in your VS Code editor.
Wrapping Up
And that’s how you can use LM Studio for AI assistance in Visual Studio Code. It’s a great way to have AI assistance in your code editor without relying on the cloud. It’s also free and you can select the model that’s best for your computer. A great alternative to cloud-based services like OpenAI or GitHub Copilot.
Give it a try and see how it can help you in your coding tasks.