Blog Infos
Author
Published
Topics
, , , ,
Published

Maybe it will… Maybe it won’t… Nobody knows. But now, it can help you be even more productive (or spend less time working 😉).

Many people use AI to enhance the development process. They ask questions and paste code back into the project. Switching between Android Studio (or any other IDE) and ChatGPT takes some time. What if we can use a plugin to speed up this process?

Yes, I know there is a GitHub Copilot tool exists, but isn’t it a good thing to have a diversity of AI tools? ChatGPT constantly evolves its models, and now you can use GPT-4; it will be something else in the future.

A video version of this article is here:

Why is it helpful?

It’s very easy to use it. Just press Control + Enter and select a menu item.

Currently, it can:

  1. Write any question to ChatGPT; the answer will be pasted into your file.
  • You can ask a custom question, for example, “Please, create a method that has an int as a parameter and should return a square value of it”
  • Or you can send the selected code to ChatGPT and ask, “Please, could you say if the code has some issues?”
  • You can also send the whole file for analysis or enhancement.

2. Ask ChatGPT to cover the file with tests (any tests).

3. Ask ChatGPT to analyze the file.

3. Ask ChatGPT to cover the addition of documentation to a file.

Basically, with a custom prompt, you can make any request to the GPT model, from “Create a “Hello World!” bash script” to “What is the purpose of humankind?”

Although the answer may not fit your needs, you can tune it and make it more specific.

AskGPT plugin set up

The plugin is pretty straightforward. It uses a ChatGPT API to ask questions and paste code within the current file or create a new file.

You can find the plugin on the JetBrains Plugin Marketplace or by a link:

https://plugins.jetbrains.com/plugin/23996-ask-gpt

Next, you need to go to an open and create a ChatGPT token at https://platform.openai.com/api-keys to call the API.

And yes, the ChatGPT API is not free. There is nothing free in this world, so we have to get used to it 💸

Then, open the menu Tools -> AskGPT -> AskGPT Settings and paste the token there.

Also, in this menu, you can tune questions for tests, bugs, and docs.

That’s pretty much it. 😃

AskGPT plugin in action

It really can help with the generation of code. In your Android Studio (or any other JetBrains IDE, like Intellij IDE), press Control + Enter and choose what you need:

And then write your prompt:

And voila:

You don’t need to spend time on it. Moreover, if you want to cover it with tests, do the same trick:

Yes, you still need to fix imports and some naming. However, you can tune the prompt and write something like “Cover a file with unit tests using Mockk library. It should have a positive and negative scenario for each method and test if all exceptions are properly handled.”

If you just opened a class or method that doesn’t make sense to you, you can ask chatGPT to clarify it for you!

What if the case is more complex than a simple key-value storage?

The ChatGPT can process some code better than some developers 😃

So it could help if you need a hand and nobody is around.

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

,

Boostez votre application mobile grâce à ChatGPT

ChatGPT et L’intelligence artificielle en général sont en train de révolutionner notre monde. Chez WeMoms (le réseau social de la maternité) on exploite ces outils au maximum pour booster le développement de nos apps Android…
Watch Video

Boostez votre application mobile grâce à ChatGPT

David Silvera
Lead Android developer
WeMoms

Boostez votre application mobile grâce à ChatGPT

David Silvera
Lead Android develop ...
WeMoms

Boostez votre application mobile grâce à ChatGPT

David Silvera
Lead Android developer
WeMoms

Jobs

How does the plugin work?

AskGPT is an open-source plugin. The plugin repository:

https://github.com/Nerdy-Things/askgpt?source=post_page—–e455b8b95c29——————————–

The code has a few actions for each menu item. All of them will send a simple POST request to the OpenAI API (https://platform.openai.com/docs/api-reference) and parse the response into the Android Studio (or any other JetBrains IDE). An API token is saved in local preferences, so no one, except your local users, can access it. You are paying for what you are using. It’s a very transparent and reliable system.

What are the real-case scenarios where the AskGPT plugin could be helpful?

There are tons of them. Tests, code analysis, documentation, and comments are just the tip of the iceberg.

Data classes generation

For example, you can create data models from a JSON response in three easy steps:

  1. Create a file with JSON.

2. Call the AskGPT with a prompt:

3. Relax for a second and see the result:

data class Donut(
    @SerializedName("id") val id: String,
    @SerializedName("type") val type: String,
    @SerializedName("name") val name: String,
    @SerializedName("ppu") val ppu: Double,
    @SerializedName("batters") val batters: Batter,
    @SerializedName("topping") val toppings: List<Topping>
)

data class Batter(
    @SerializedName("batter") val batter: List<BatterItem>
)

data class BatterItem(
    @SerializedName("id") val id: String,
    @SerializedName("type") val type: String
)

data class Topping(
    @SerializedName("id") val id: String,
    @SerializedName("type") val type: String
)

Should all fields be nullable? Just tune the prom otand add “Make all fields nullable.”

Don’t limit your imagination. Use it for anything.

UI generation:

Result (after fixed import):

Isn’t it cool to have this screen in thirty seconds?

Retrofit API Service from a swagger documentation
  1. Copy HTML from a website from Swagger docs(that’s really cool):

2. And trigger “AskGPT question” with this HTML:

3. Enjoy the result:

interface StoreService {

    @POST("/store/order")
    fun placeOrder(@Body order: Order) : Call<Order>

    @GET("/store/order/{orderId}")
    fun getOrderById(@Path("orderId") orderId: Int) : Call<Order>

    @DELETE("/store/order/{orderId}")
    fun deleteOrder(@Path("orderId") orderId: Int) : Call<Void>

    @GET("/store/inventory")
    fun getInventory() : Call<Map<String, Int>>
}

data class Order(
    val id: Int,
    val petId: Int,
    val quantity: Int,
    val shipDate: String,
    val status: String,
    val complete: Boolean
)

It converted HTML Swagger documents to the Kotlin classes for a Retrofit Api Service.

Isn’t it awesome?

Of course, a developer should be a developer and fix some strange findings. Sometimes, it takes longer to fix complex code than to write it alone. Sometimes, GPT will use old libraries instead of new ones, or it won’t know about freshly released Material 4 (that isn’t released, but will it be?).

It’s not a magic wand.

It’s just another tool to make a lazy developer even more lazy.

And don’t forget to be kind with ChatGPT. You don’t know the future.

Let me know your thoughts.

Cheers 🍻

This article is previously published on proandroiddev.com

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Using annotations in Kotlin has some nuances that are useful to know
READ MORE
blog
One of the latest trends in UI design is blurring the background content behind the foreground elements. This creates a sense of depth, transparency, and focus,…
READ MORE
blog
Now that Android Studio Iguana is out and stable, I wanted to write about…
READ MORE
blog
The ModalBottomSheet in Jetpack Compose is easy to use, it just pops up at…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu