-
The license for IBM watsonx Code Assistant Individual can be found in the product-licenses folder in this repository.
-
You can use this repository to add issues for watsonx Code Assistant Individual. The license for issues, discussion, and any files or samples shared in issues can be found in the LICENSE file.
Watsonx Code Assistant Individual is an innovative, lightweight AI coding companion built for IBM’s state-of-the-art Granite large language models. This companion offers robust, contextually aware AI coding assistance for popular programming languages such as C, C++, Go, Java, JavaScript, Python, and TypeScript. Seamlessly integrated into Visual Studio Code, watsonx Code Assistant Individual accelerates development productivity and simplifies coding tasks by providing powerful AI support hosted locally on the developer’s laptop or workstation using Ollama.
- Chat with an IBM Granite code model to create code, and ask general programming questions.
- Use the chat to explain and extend existing code from your workspace.
Complete the line that you're currently typing:
And even full methods and functions:
Create a comment that describes a function, method, or piece of logic in your editor, and have watsonx Code Assistant Individual create it.
- Install the granite 8b code instruct model for both chat and code completion.
- Optionally, install the granite 8b code base model for code completion.
- These models run locally on your laptop using Ollama.
Watsonx Code Assistant Individual accesses models through Ollama, which is a widely used local inferencing engine for LLMs. Ollama wraps the underlying model-serving project llama.cpp.
MacOS, Linux, Windows: Download and run the ollama installer
Ollama on macOS and Windows will automatically download updates. Click on the taskbar or menubar item, and then click "Restart to update" to apply the update. Updates can also be installed by downloading the latest version manually.
brew upgrade ollama
curl -fsSL https://ollama.com/install.sh | sh
In a terminal window, run:
ollama serve
Leave that window open while you use Ollama.
If you receive the message Error: listen tcp 127.0.0.1:11434: bind: address already in use
, the Ollama server is already started. There's nothing else that you need to do.
Get started with watsonx Code Assistant Individual by installing the granite-code:8b
model available in the Ollama library.
-
Open a new terminal window.
-
On the command line, type
ollama run granite-code:8b
to download and deploy the model. You see output similar to the following example:pulling manifest pulling 8718ec280572... 100% ▕███████████████████████ 4.6 GB pulling e50df8490144... 100% ▕███████████████████████ ▏ 123 B pulling 58d1e17ffe51... 100% ▕███████████████████████▏ 11 KB pulling 9893bb2c2917... 100% ▕███████████████████████▏ 108 B pulling 0e851433eda0... 100% ▕███████████████████████▏ 485 B verifying sha256 digest writing manifest removing any unused layers success >>>
-
Type
/bye
after the>>>
to exit the Ollama command shell. -
Try the model by typing:
ollama run granite-code:8b "How do I create a python class?"
-
You should see a response similar to the following:
To create a Python class, you can define a new class using the "class" keyword followed by the name of the class and a colon. Inside the class definition, you can specify the methods and attributes that the class will have. Here is an example: ...
- Open the watsonx Code Assistant extension page in the Visual Studio Marketplace.
- Click Install on the Marketplace page.
- In Visual Studio Code, click Install on the extension.
By default, the Ollama server runs on IP address 127.0.0.1
, port 11434
, using http as a protocol. If you change the IP address or the port where Ollama is available:
- Open the extension settings.
- Locate the entry for API Host.
- Add the host IP and port.
By default, watsonx Code Assistant Individual uses the granite-code:8b
model for both chat and code completion.
If your environment has capacity, install the granite-code:8b-base
model, and use it as Local Code Gen Model as follows.
To use a different model:
- Install the
granite-code:8b-base
model. See Install the Granite code model. - Open the extension settings.
- Update the model name for either Local Code Gen Model to
granite-code:8b-base
.
Watsonx Code Assistant Individual does not provide additional security controls. We recommended the following steps to properly secure your setup:
- Apply all Visual Studio Code updates to help ensure that you have the latest security and bug fixes. For more information, see the Microsoft Documentation.
- The watsonx Code Assistant Individual extension logs are stored in *.log files under
<your home directory>/.wca
. These files are not encrypted, besides the encryption that your file system provides. Safeguard the logs against improper access.
By default, the Ollama server runs on IP address 127.0.0.1, port 11434, using http as a protocol, on your local device. To use https instead, or go through a proxy server, follow the Ollama documentation.
Watsonx Code Assistant Individual stores all your chat conversations locally in your file system under <your home directory>/.wca/chat.db
, in a database format defined by SQLite. Watsonx Code Assistant Individual does not share conversations with anyone. This file is not encrypted, besides the encryption that your file system provides. Safeguard this file against improper access.
Watsonx Code Assistant Individual does not collect any telemetry data. In general, watsonx Code Assistant Individual does not send any data that it processes to a third party, IBM included.
- Open the watsonx Code Assistant Individual view by selecting View -> Open View -> watsonx Code Assistant in the menu, or clicking the watsonx Code Assistant icon in the sidebar
- The chat panel opens to the left of the Visual Studio Code editor.
- To move the chat, drag the icon to the right or bottom of the editor.
Enter a free-text question or instruction and click Enter. watsonx Code Assistant Individual sends your input to the code model, and shows the response in the chat.
To ask questions or refine a specific file, class, function, or method in your workspace, you can use code references. These references provide important context for the LLM, and can help to increase the accuracy of the answer.
- Type the
@
sign as part of your chat message. - A screen pops up, and shows all files, classes, and methods from your workspace.
- Type the characters of the file, class, or method name that you want to reference. The list filters automatically.
- Select the reference.
Watsonx Code Assistant Individual sends the contents of the reference automatically to the model as part of your message.
Chat message examples:
Use case | Example message |
---|---|
Generate a function based on an existing function | Create a method send_translate_message that is similar to @send_code_explanation_message |
Generate a unit test that follows existing unit tests | Create a unit test for @getName that is similar to the unit tests in @testLoadTablesChildConnectionReceiverJob.h |
Enhance existing functions | Add error handling and log statements to @format_documents |
Enhance existing functions | Update @setEmail with error handling for null strings |
Explain code | What does @main.py do |
Explain code | Explain the logic of @send_invoice |
Generate documentation for functions and classes | Add javadoc to @Customer |
When you open a workspace folder, watsonx Code Assistant Individual creates an index of these items in memory so you can reference these files and functions in the chat. The IDE also indexes files that you add or change during your Visual Studio Code session. The index contains up to 1,000 of the most recent files in 7 programming languages: C, C++, Go, Java, JavaScript, Python, and TypeScript.
Each chat message is part of a chat conversation. We highly recommend keeping conversations focused around a specific subject or task. Create a new chat conversation to get more relevant results for your questions when you switch your context, for example, to another programming language, another project in your workspace, or a different programming task.
To create a new chat conversation:
- Open the menu at the top of the chat.
- Select New Chat.
To switch between chat conversations:
- Open the menu at the top of the chat.
- Select Chat Sessions.
- Select the conversation.
To delete a chat conversation:
- Open the menu at the top of the chat.
- Select Chat Sessions.
- Select the menu on the right of the conversation.
- Click Delete.
To rename a chat conversation:
- Open the menu at the top of the chat.
- Select Chat Sessions.
- Select the menu on the right of the conversation.
- Click Rename.
- Write your chat messages in English.
- Start with a simple and clear instruction.
- Use subsequent chat messages to refine the code output of the model.
- Be as specific and detailed as you can for each step. You can gradually enhance the created code through subsequent chat messages.
- Use file and method references in your message to provide relevant context. For example, if you want the model to create a method that is similar to another method, add "similar to
@<method>
" to your message. - If you find the answers become less relevant, or if you start a new task, create a new chat conversation, and work from there. It is better to have many short chat conversations, each with a specific context, rather than one large conversation that might confuse the model with different and unrelated chat messages.
Watsonx Code Assistant Individual and the Granite code models are created to answer questions that are related to code, general programming, and software engineering. While the IDE doesn’t restrict your questions or prompts, the Granite code models are not designed for language tasks. Any such use is at your own risk, and results can be unreliable so validate all output independently and consider deploying a Hate Abuse Profanity (HAP) filter.
- Start typing a line of code.
- Watsonx Code Assistant Individual adds a code suggestion to complete the line that you typed.
- Press Tab to accept the suggestion.
- Start typing a line of code.
- Press
Option
+.
(Mac) orAlt
+.
(Windows) - Watsonx Code Assistant Individual adds a code suggestion to complete the line that you typed, and adds code lines.
- Press Tab to accept the suggestion.
- Type a comment.
- Press
Option
+.
(Mac) orAlt
+.
(Windows) - Watsonx Code Assistant Individual adds a code suggestion based on your comment.
- Press Tab to accept the suggestion.
Use chat to:
- Generate the overall outline of a class
- Specify a method in detail
- Refine the suggested code with more instructions (for example, rename or replace)
Use in-editor code generation to:
- Complete a line of code you start to type
- Automatically create boilerplate code-like getters and setters
- Create methods and code that can be described with a single comment line
When you use comment-to-code in the editor, write a comment that describes the intended behavior - as you do when you write comments for code you wrote. For example, use //return even numbers from an arraylist
or //method that returns even numbers from an arraylist
. Don't write your comment as an instruction, such as //write a method that returns even numbers from an arraylist
. Granite models are trained to complete code on data that contains many "typical", descriptive comments, so these kinds of comments yield better results.
The key ingredient for code generation is the context, that is, the surrounding code you pass to the model. For in-editor code generation, watsonx Code Assistant Individual uses the following context:
- The 20 lines of code before the line where the generation is triggered.
- The 20 lines of code after the line where the generation is triggered.
- Up to 200 lines from the beginning of the current file where generation is triggered.
- Up to 5 code snippets that are similar to the code that surrounds the line where generation was triggered. These snippets are taken from the last 10 files that you opened that are in the same programming language as the current file.
To improve the results of in-editor code generation:
- Open files in your workspace that have code you want watsonx Code Assistant Individual to know about. Watsonx Code Assistant Individual tries to find code in these files that is similar to the place where you trigger completion, for example, methods that use similar classes and variables, and sends this code to the model as context.
- Don’t use in-editor code generation when you start from scratch. Code generation in almost empty files might not have enough context. You can help watsonx Code Assistant Individual by starting with a class definition or adding import statements. You can also use the watsonx Code Assistant Individual chat to create the initial outline, copy the result into a file in your workspace, and continue with in-editor code generation.