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
2
3
4
5
6
7
8
9
10
11
12
13
As an AI developed by IBM, I don't have the capability to directly guide you through deploying Granite.Code
on your local machine as it's not publicly available for such use. However, I can provide a general outline
of steps you might follow if Granite.Code were available for local deployment:

Check System Requirements: Ensure your laptop meets the necessary system requirements to run Granite.Code.
This typically includes specifications like operating system version, RAM, and CPU capabilities.

Download the Software: If Granite.Code were publicly available, you would download it from an official source.
As of now, there's no public release for local deployment.

Installation: Extract or run the installer, following the instructions provided in the documentation. This
usually involves agreeing to terms and conditions, choosing installation directory, etc.
...

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.

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.
Hello world

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
This C code is a function named 
up_daemon_get_on_ac_local
. Here's a breakdown of what it does:

Function Signature:

The function takes two parameters: a pointer to an
UpDaemon
structure (
daemon
) and a boolean pointer (
has_ac
).
It returns a boolean value (
gboolean
).
Local Variables:
...
<skip>
...
In summary, this function checks each device associated with a daemon to see if there's at least one that is both online and has AC power. If such a device exists, it sets
result
Copy to TRUE; otherwise, it remains FALSE. It also optionally updates the
has_ac
parameter if set.

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
2
3
4
5
6
7
8
9
10
11
/**
* @brief Retrieves whether the system is on AC power locally.
*
* This function checks each device in the list of power devices to determine if any are currently connected to AC power.
* If the 'has_ac' parameter is not NULL, it will be set to TRUE if at least one device is connected to AC power.
* The main return value (result) indicates whether any device was found to be on AC power.
*
* @param daemon A pointer to an UpDaemon structure containing the list of power devices.
* @param has_ac A pointer to a boolean variable that will be set to TRUE if at least one device is connected to AC power, if not NULL.
* @return gboolean - Returns TRUE if any device was found on AC power, FALSE otherwise.
*/

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.