Work with AI tools using granite.code
The used of AI tool to speed up the coding efficiency becomes a new trend in the programming field and industry. The upstream contributors and maintainers are trying to use those tool to improve the development speed and reduce the workload. Those new technologies also catch my eyes and I’ll give them a try. Many AI code assistance tools were proposed and they were based on the open AI model, for example Github copilot. But If you concern about the security and you don’t allow the information leak.
Here I’ll ask the local model Granite.code to tell us how to install and deply it locally. It gave me the answer shown bellow.
1 | As an AI developed by IBM, I don't have the capability to directly guide you through deploying Granite.Code |
Hmm, It try to invite the user to use the Could version. Here is the steps to deploy Granite.code to your local laptop. Moreover, first, you have to ensure you have a Mac M2 or have a GPU support. Then, checkout the IBM website to get the detailed step to deploy it and the URLs are shown as follows.
- Deploy ollama on a Mac https://www.ibm.com/granite/docs/run/granite-with-ollama/mac/
- vscode plugin, IBM Waston X code assistant https://www.ibm.com/granite/docs/use-cases/coding-assistant/
My configuration is a bit tricky since my working laptop doesn’t have a GPU or something can accelerate the AI compute. So, I ran the model on my Mac M2 (Yes, a Mac, haha) and tweaked the Watson code assistant to access the API server on my M2.
OK, now, I ask granite.code for a Glib hello world example and here is the answer. That gave a pieces of example and the expected out comes.
Watson code assistant provide four main functions, Describe the code, unit test generator, document generator, and code completion. However, M2 is slow so I have to skip the code completion. I really love to use code describe, it give me a glance if I first trace the code.
Here is the example:
1 | /explain up_daemon_get_on_ac_local |
I got:
1 | This C code is a function named |
It gave me a summary of input parameters, local vaiables, and a summary of the function. It took 1min to analyze the code
and generate the result. It is useful before you deep dive into the code.
The document generator generate the doxygen comment format. It it a bit different from GTK comment but I can translate
it to the GTK format. That is good for me. The example was shown as follows. It looks normal but it still needs some
work to make it to a API document.
1 | /** |
For the unit test code generator, it only gave the gtest code. However, for our Glib developers, we can’t use this feature.
Coding with a local AI assistance is a very good idea. It is like a virtual colleague to answer your question. However, it
needs a powerful computer to make it come true. My Mac M2 took a few minutes to analyze question and generate the result.
Base on this performance, The code completion can’t be a really powerful tool for me. The feature mentioned above is
nice and worst to wait for the result. It inspired me to make higher quality documents and it also listed all the possible
stuff. To have a AI tools for coding actually improves the code quality and development efficiency.