This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Commit-teller – Problems during the development




🚨 Issues

After the beginning I knew that I will be integrating OpenAI’s API and the GitHub API into the appliance, and I needed to verify I can go native with Quarkus. Going native requires GraalVM, however it’s not sufficient, your code have to be suitable with the native technology, and at after the primary dependencies I pulled in I used to be not checking it incessantly if my code continues to be in a position to be compiled into native.



🔨 Dependencies

I solely wanted two necessary dependencies that may fulfil my necessities:



🚀 Why did I need to use third get together libs?

I needed to maneuver shortly, I checked the GitHub’s API, it appeared advantageous, however the request and response objects could be actually large, so if there’s any lib that may assist me to skip writing lots of boilerplate code, I attempt to make the most of them.

OpenAI integration is just not totally different, I needed to skip writing the boilerplate and transfer quick.



🧐 Issues and resolution with the OpenAI API

The openai-java has 3 modules that the builders can use, and I wanted all of them to fulfil the necessities.

The utilization of the lib was simple, a number of options are carried out however for me the immediate completion was the wanted one. It has small request and response objects, with a consumer class that may invoke the API.

The issues arrived once I tried to compile it to native, and within the background the lib makes use of the Retrofit library, which in my view created the issue. I attempted to dig deeper, however a number of hours simply handed, and I stated that’s sufficient, I do know Quarkus has an extension to invoke REST APIs, I can do it tremendous quick by simply writing the request and response courses.

The consumer interface:

@RegisterRestClient
public interface OpenAIClient {

    @POST
    @Path("/v1/completions")
    @ClientHeaderParam(
      identify = "Authorization",
      worth = "Bearer {token}"
    )
    CompletionResponse postCompletion(
      CompletionRequest request,
      @NotBody String token);
}
Enter fullscreen mode

Exit fullscreen mode

The request class:

public document CompletionRequest(
    String immediate,
    String mannequin,
    double temperature,
    @JsonProperty("max_tokens")
    int maxTokens
) {
}
Enter fullscreen mode

Exit fullscreen mode

And the response class:

public document CompletionResponse(Checklist<Completion> decisions) {
    public document Completion(String textual content) {
    }
}
Enter fullscreen mode

Exit fullscreen mode

And the configuration for the consumer:

quarkus.rest-client."org.rodnansol
.committeller.core.language
.openai.OpenAIClient"
.url=https://api.openai.com
Enter fullscreen mode

Exit fullscreen mode

That is it, and poor me was searching for libs that may assist me with that 🙂 It took lower than 10 minutes to put in writing it and wire it into the present code.

I used information, as a result of these courses are simply information courses, I am not going to control them later, simply use the outcomes.

The purpose of execution:

@ApplicationScoped
public class OpenAILanguageProcessor
    implements LanguageProcessor {
    non-public static ultimate Logger LOGGER = LoggerFactory.getLogger(OpenAILanguageProcessor.class);
    non-public ultimate OpenAIProperties openAIProperties;
    non-public ultimate OpenAIClient openAIClient;

    public OpenAILanguageProcessor(
        OpenAIProperties openAIProperties,
        @RestClient OpenAIClient openAIClient) {
        this.openAIProperties = openAIProperties;
        this.openAIClient = openAIClient;
    }

    @Override
    public ProcessResult processPrompt(
      ProcessPromptCommand command
) {
        CompletionResponse completionResponse
            = openAIClient.postCompletion(
            new CompletionRequest(
                command.immediate(),
                openAIProperties.mannequin(),
                openAIProperties.temperature(),
                openAIProperties.maxToken()),
            openAIProperties.apiKey()
        );

        Checklist<CompletionResponse.Completion> decisions
            = completionResponse.decisions();
        if (decisions == null || decisions.isEmpty()) {
            throw new LanguageProcessorException(
                "No decisions are returned," +
                    " unable to return end result"
            );
        }
        var completionChoice = decisions.get(0);
        return new ProcessResult(completionChoice.textual content());
    }
}

Enter fullscreen mode

Exit fullscreen mode

That is it, native was working advantageous. 🔥



🙈 Issues and (partial) resolution with the GitHub API

The jcabi-github dependency appeared good to start with but it surely was having points with the occasion feed administration, the endpoints weren’t correctly setup within the code, but it surely was solely a minor challenge, I used to be in a position to overcome it by utilizing two totally different operations to fetch the required information.

After making an attempt to go native, the issues simply got here out, the lib is written in a manner that the native compiler was unable to beat and I used to be searching for fast fixes. In Quarkus you may setup hints for native compiler, but it surely was not clear at first look, what ought to be setup.

The answer was to maneuver to a different resolution and use a Quarkus extension that I didn’t uncover on the first place.

Quarkus extensions are principally plugins for the framework itself, you want/ought to/would write an extension if you need to make the most of the framework advantages like build-time optimizations or the native binary technology. I used to be glad that I discovered it as a result of should you discover an official Quarkus extension than you may “hope” that it’ll compile to native.

Not on this case 🚧

The extension is backed by a unique third get together lib that may work together with the GitHub API, it’s referred to as Hub4j GitHub API, the change from the jcabi dependency was simple and all the things was working as earlier than, BUT not the native mode.

There are some issues with that dependency too, I used to be digging deeper however I used to be unable to determine the true purpose behind that.



End result

Even I deliberate to go native however I cannot, this doesn’t imply the instrument cannot be used, it undoubtedly could be, however customers would wish Java on their machine to run it, however the GitHub motion will include a Java 17 so there ought to be no drawback with the execution. 🎉

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

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

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?