ChatGPT plugins quick start

Using Java, Quarkus and JBang
@maxandersen
decoding AI in Java

redhat

What is your day-to-day programming language?

Is it Java, Python, JavaScript, Go, C# or something else?

Write it in chat!

A User talks to ChatGPT

chatgpt

Your App talks to ChatGPT

chatgptapp

Your app talks to ChatGPT

GPT gpt = RestClientBuilder.newBuilder()
    .baseUri(URI.create("https://api.openai.com"))
    .build(GPT.class);

	final List<Map<String, String>> messages = new ArrayList<>();
			messages.add(prompt("system", """
          You are to advise a software
          developer on what the following code found
          in a file at"""
           + sourceFile + " does."));
			messages.add(prompt("user",
      Files.readAllLines(sourceFile).stream().collect(Collectors.joining("\n"))));

	 var result = gpt.completions(token,
      Map.of("model", model,
        "temperature", temperature,
        "messages", messages));

Your app talks to ChatGPT part 2

$ quarkus explain pom.xml
Requesting explanation of pom.xml with model gpt-3.5-turbo and temperature 0.8. Have patience...
This is an XML file for a Maven project, which is a build automation tool primarily used for Java projects. The file contains information about the project, its dependencies, and the build process.

- The `groupId`, `artifactId`, and `version` tags define the project's coordinates.
- The `properties` section defines variables used throughout the file, such as the version of the Quarkus platform, the version of the compiler plugin, and whether integration tests should be skipped.
- The `dependencyManagement` section lists dependencies that are used throughout the project and provides a way to manage their versions in one place.
- The `dependencies` section lists the project's dependencies, which include the Camel Quarkus Mail component, the Quarkus Arc extension, and the Quarkus JUnit 5 extension.
- The `build` section lists plugins used during the build process, including the Quarkus Maven plugin, the Maven compiler plugin, and the Maven Surefire and Failsafe plugins. These plugins are responsible for compiling code, running tests, and generating executable code, among other tasks.
- The `profiles` section defines build profiles that can be activated depending on certain conditions. In this case, the `native` profile is activated when the `native` property is set, and it sets options for building a native executable.

ChatGPT with Plugins

Make ChatGPT talk to your app!

chatgptplugin

Demo

ChatGPT with Plugins

Make ChatGPT talk to your app!

chatgptplugin

ChatGPT with Plugins

  • Unlimited opportunities for plugins

    • Home Automation? i.e. HomeAssistant

    • Issue tracker?

    • Quarkus Devmode?

    • Your own app?

    • …​just imagine

  • Must have Plus Subscription

  • Plugins can be written in any language

How to make a plugin with Python

How to make a plugin with Java

How to make a minimal plugin with Java

What I used in this demo

  • JBang - allow for java builder/launcher with embedded dependencies

  • Quarkus - excellent Java framework for building cloud native apps

ChatGPT with Plugins

Make ChatGPT talk to your app!

chatgptplugin

Try it out

  • Questions?