diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..a048061 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + com.mibaltoalex + siam + SIAM + 1.0.1 + + + Miguel J. Carmona (MIBALTOALEX) + miguel@mibaltoalex.com + ${project.organization.name} + ${project.organization.url} + + + + MIBALTOALEX + https://www.mibaltoalex.com + + + + + maven-compiler-plugin + 3.10.1 + + UTF-8 + 17 + 17 + + + + maven-shade-plugin + + + + shade + + + true + + + ${project.groupId}.${project.artifactId}.${project.name} + + + + + + + + maven-jar-plugin + 3.3.0 + + + false + + ${project.groupId}.${project.artifactId}.${project.name} + false + + + Miguel J. Carmona (MIBALTOALEX) + ${project.organization.name} + + + + + + + + + + false + + central + https://repo.maven.apache.org/maven2 + + + + + + false + + central + https://repo.maven.apache.org/maven2 + + + + 17 + 17 + 17 + UTF-8 + UTF-8 + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..83cdf70 --- /dev/null +++ b/pom.xml @@ -0,0 +1,154 @@ + + + 4.0.0 + com.mibaltoalex + siam + SIAM + 1.0.1 + jar + + + 17 + 17 + 17 + UTF-8 + UTF-8 + + + + MIBALTOALEX + https://www.mibaltoalex.com + + + + + Miguel J. Carmona (MIBALTOALEX) + miguel@mibaltoalex.com + ${project.organization.name} + ${project.organization.url} + + + + + + + + + central + https://repo.maven.apache.org/maven2 + + false + + + + + + + + central + https://repo.maven.apache.org/maven2 + + false + + + + + + + + com.google.code.gson + gson + 2.10.1 + compile + + + + org.projectlombok + lombok + 1.18.24 + compile + + + + com.konghq + unirest-java + 4.0.0-RC2 + compile + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + UTF-8 + 17 + 17 + + + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + + true + + + ${project.groupId}.${project.artifactId}.${project.name} + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + false + + + ${project.groupId}.${project.artifactId}.${project.name} + false + + + Miguel J. Carmona (MIBALTOALEX) + ${project.organization.name} + + + + + + + + diff --git a/src/main/java/com/mibaltoalex/siam/Config.java b/src/main/java/com/mibaltoalex/siam/Config.java new file mode 100644 index 0000000..67271f1 --- /dev/null +++ b/src/main/java/com/mibaltoalex/siam/Config.java @@ -0,0 +1,21 @@ +package com.mibaltoalex.siam; + +import kong.unirest.Unirest; + +/** + * @author Miguel J. Carmona (MIBALTOALEX) + */ +final class Config { + + Config() { + Unirest.config().defaultBaseUrl(getSiamEndpoint()); + } + + public String getSiamKey(){ + return System.getenv("SIAM_KEY"); + } + + private String getSiamEndpoint(){ + return System.getenv("SIAM_ENDPOINT"); + } +} diff --git a/src/main/java/com/mibaltoalex/siam/Prompt.java b/src/main/java/com/mibaltoalex/siam/Prompt.java new file mode 100644 index 0000000..035bd7f --- /dev/null +++ b/src/main/java/com/mibaltoalex/siam/Prompt.java @@ -0,0 +1,11 @@ +package com.mibaltoalex.siam; + +import lombok.Builder; + +/** + * @author Miguel J. Carmona (MIBALTOALEX) + */ +@Builder +final class Prompt { + private String inputs; +} diff --git a/src/main/java/com/mibaltoalex/siam/Response.java b/src/main/java/com/mibaltoalex/siam/Response.java new file mode 100644 index 0000000..5e3cdf2 --- /dev/null +++ b/src/main/java/com/mibaltoalex/siam/Response.java @@ -0,0 +1,8 @@ +package com.mibaltoalex.siam; + +/** + * @author Miguel J. Carmona (MIBALTOALEX) + */ +final class Response { + String generated_text; +} diff --git a/src/main/java/com/mibaltoalex/siam/SIAM.java b/src/main/java/com/mibaltoalex/siam/SIAM.java new file mode 100644 index 0000000..1cf15d7 --- /dev/null +++ b/src/main/java/com/mibaltoalex/siam/SIAM.java @@ -0,0 +1,51 @@ +package com.mibaltoalex.siam; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import kong.unirest.HttpResponse; +import kong.unirest.Unirest; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * El asistente inteligente SIAM + * + * @author Miguel J. Carmona (MIBALTOALEX) + */ +public final class SIAM { + + //java -jar app -DSIAM_KEY="mikey" -DSIAM_ENDPOINT="boing" + private static final Gson gson = new Gson(); + + public static void main(String[] args) { + try (Scanner sc = new Scanner(System.in)) { + Config config = new Config(); + System.out.print("> "); + while (sc.hasNextLine()) { + final String input = sc.nextLine(); + String payload = gson.toJson(Prompt.builder().inputs(input).build()); + HttpResponse resultado = Unirest.post("") + .header("Accept", "application/json") + .header("Authorization", "Bearer " + config.getSiamKey()) + .body(payload).asString(); + if (resultado.isSuccess()) { + showResponse(resultado); + } else { + System.err.println(resultado.getBody()); + } + System.out.print("> "); + } + } catch (Throwable ignored) { + System.err.println("La configuracion parece ser incorrecta"); + } + } + + private static void showResponse(HttpResponse resultado) { + Type respuestasListType = new TypeToken>() { + }.getType(); + ArrayList respuestaArray = gson.fromJson(resultado.getBody(), respuestasListType); + respuestaArray.stream().distinct().forEach(respuesta -> System.out.println(respuesta.generated_text)); + } +}