Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MiBaLToALeX authored Jan 12, 2023
1 parent 515d0ca commit 5d2d1b8
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 0 deletions.
93 changes: 93 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mibaltoalex</groupId>
<artifactId>siam</artifactId>
<name>SIAM</name>
<version>1.0.1</version>
<developers>
<developer>
<name>Miguel J. Carmona (MIBALTOALEX)</name>
<email>miguel@mibaltoalex.com</email>
<organization>${project.organization.name}</organization>
<organizationUrl>${project.organization.url}</organizationUrl>
</developer>
</developers>
<organization>
<name>MIBALTOALEX</name>
<url>https://www.mibaltoalex.com</url>
</organization>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer>
<mainClass>${project.groupId}.${project.artifactId}.${project.name}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<index>false</index>
<manifest>
<mainClass>${project.groupId}.${project.artifactId}.${project.name}</mainClass>
<addClasspath>false</addClasspath>
</manifest>
<manifestEntries>
<Created-By>Miguel J. Carmona (MIBALTOALEX)</Created-By>
<Built-By>${project.organization.name}</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>
154 changes: 154 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mibaltoalex</groupId>
<artifactId>siam</artifactId>
<name>SIAM</name>
<version>1.0.1</version>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<organization>
<name>MIBALTOALEX</name>
<url>https://www.mibaltoalex.com</url>
</organization>

<developers>
<developer>
<name>Miguel J. Carmona (MIBALTOALEX)</name>
<email>miguel@mibaltoalex.com</email>
<organization>${project.organization.name}</organization>
<organizationUrl>${project.organization.url}</organizationUrl>
</developer>
</developers>

<repositories>
<!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

<!-- Main Maven repository -->
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
<pluginRepository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.konghq/unirest-java -->
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>4.0.0-RC2</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${project.groupId}.${project.artifactId}.${project.name}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>copy-dependencies</id>-->
<!-- <phase>prepare-package</phase>-->
<!-- <goals>-->
<!-- <goal>copy-dependencies</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>-->
<!-- ${project.build.directory}/libs-->
<!-- </outputDirectory>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<index>false</index>
<manifest>
<!-- <classpathPrefix>libs/</classpathPrefix>-->
<mainClass>${project.groupId}.${project.artifactId}.${project.name}</mainClass>
<addClasspath>false</addClasspath>
</manifest>
<manifestEntries>
<Created-By>Miguel J. Carmona (MIBALTOALEX)</Created-By>
<Built-By>${project.organization.name}</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions src/main/java/com/mibaltoalex/siam/Config.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/mibaltoalex/siam/Prompt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mibaltoalex.siam;

import lombok.Builder;

/**
* @author Miguel J. Carmona (MIBALTOALEX)
*/
@Builder
final class Prompt {
private String inputs;
}
8 changes: 8 additions & 0 deletions src/main/java/com/mibaltoalex/siam/Response.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mibaltoalex.siam;

/**
* @author Miguel J. Carmona (MIBALTOALEX)
*/
final class Response {
String generated_text;
}
51 changes: 51 additions & 0 deletions src/main/java/com/mibaltoalex/siam/SIAM.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> resultado) {
Type respuestasListType = new TypeToken<ArrayList<Response>>() {
}.getType();
ArrayList<Response> respuestaArray = gson.fromJson(resultado.getBody(), respuestasListType);
respuestaArray.stream().distinct().forEach(respuesta -> System.out.println(respuesta.generated_text));
}
}

0 comments on commit 5d2d1b8

Please sign in to comment.