konveyor-ecosystem / kai

Konveyor AI - static code analysis driven migration to new targets via Generative AI
Apache License 2.0
8 stars 10 forks source link

mistral change: adding ejb rule messaging edit #168

Closed savitharaghunathan closed 1 month ago

savitharaghunathan commented 2 months ago

Tested against "mistralai/mixtral-8x7b-instruct-v0-1"

output for example/coolstore/src/main/java/com/redhat/coolstore/service/ShippingService.java

output file:

package com.redhat.coolstore.service;

import java.math.BigDecimal;
import java.math.RoundingMode;

import jakarta.ws.rs.Path;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.QueryParam;
import jakarta.enterprise.context.ApplicationScoped;

import com.redhat.coolstore.model.ShoppingCart;

@ApplicationScoped
@Path("/shipping")
public class ShippingService {

    @POST
    @Path("/calculate-shipping")
    public double calculateShipping(@QueryParam("cartItemTotal") double cartItemTotal) {

        if (cartItemTotal >= 0 && cartItemTotal < 25) {

            return 2.99;

        } else if (cartItemTotal >= 25 && cartItemTotal < 50) {

            return 4.99;

        } else if (cartItemTotal >= 50 && cartItemTotal < 75) {

            return 6.99;

        } else if (cartItemTotal >= 75 && cartItemTotal < 100) {

            return 8.99;

        } else if (cartItemTotal >= 100 && cartItemTotal < 10000) {

            return 10.99;

        }

        return 0;

    }

    @POST
    @Path("/calculate-shipping-insurance")
    public double calculateShippingInsurance(@QueryParam("cartItemTotal") double cartItemTotal) {

        if (cartItemTotal >= 25 && cartItemTotal < 100) {

            return getPercentOfTotal(cartItemTotal, 0.02);

        } else if (cartItemTotal >= 100 && cartItemTotal < 500) {

            return getPercentOfTotal(cartItemTotal, 0.015);

        } else if (cartItemTotal >= 500 && cartItemTotal < 10000) {

            return getPercentOfTotal(cartItemTotal, 0.01);

        }

        return 0;
    }

    private static double getPercentOfTotal(double value, double percentOfTotal) {
        return BigDecimal.valueOf(value * percentOfTotal)
                .setScale(2, RoundingMode.HALF_UP)
                .doubleValue();
    }

}
savitharaghunathan commented 2 months ago

prompt template - https://gist.github.com/savitharaghunathan/78e946a9a97512513d8f14a02ca07b1a

savitharaghunathan commented 2 months ago

ref: https://github.com/konveyor-ecosystem/kai/issues/117

fabianvf commented 2 months ago

@savitharaghunathan what's the status of this PR?

savitharaghunathan commented 2 months ago

@fabianvf Testing with changes right now. The solution suggested by llm dint work