Commit inicial
This commit is contained in:
commit
3e5864162e
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/bin/
|
||||||
|
*.class
|
||||||
|
/target/
|
||||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>aadd_ia_rest</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=24
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=24
|
||||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
15
pom.xml
Normal file
15
pom.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.lapaloma.aadd.ia</groupId>
|
||||||
|
<artifactId>prueba_ia_rest</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/tools.jackson.dataformat/jackson-dataformat-xml -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>tools.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
91
src/main/java/org/lapaloma/aadd/ai/AppClienteIARest.java
Normal file
91
src/main/java/org/lapaloma/aadd/ai/AppClienteIARest.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package org.lapaloma.aadd.ai;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ExtractorCine: Clase que realiza ....
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 5 ene 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AppClienteIARest {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
AppClienteIARest app = new AppClienteIARest();
|
||||||
|
|
||||||
|
String contenidoPromptCliente = "Extrae la información completa, precisa y ordenada de las lineas del metro de Madrid";
|
||||||
|
|
||||||
|
app.cargarDatosIARest(contenidoPromptCliente);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarDatosIARest(String contenidoPromptCliente) {
|
||||||
|
|
||||||
|
String urlProveedorIA = "https://api.groq.com/openai/v1/chat/completions";
|
||||||
|
String apiKey = "aquí_colocas_el_contenido_de_tu_api_key";
|
||||||
|
String modeloIA = "openai/gpt-oss-120b";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Se define el prompt del contexto sistema
|
||||||
|
// para así fijar un comportamiento específico a la IA)
|
||||||
|
String contextoInicialIA = "Actúa como un extractor de datos JSON. " + "Analiza el contexto proporcionado. "
|
||||||
|
+ "Devuelve exclusivamente un objeto JSON con esta estructura: "
|
||||||
|
+ "{ 'lineas': [{'nombre_linea': '', 'color':'', 'numero': '', 'kilometros': xx.yy}] }. "
|
||||||
|
+ "No escribas nada de texto antes o después del JSON. "
|
||||||
|
+ "Extrae solo información de las lineas del metro de Madrid, no de otras ciudades ni transportes.";
|
||||||
|
|
||||||
|
// Se construye el cuerpo de la petición (Payload)
|
||||||
|
String jsonInformacionEntrada = """
|
||||||
|
{
|
||||||
|
"model": "%s",
|
||||||
|
"messages": [
|
||||||
|
{ "role": "system", "content": "%s" },
|
||||||
|
{ "role": "user", "content": "%s" }
|
||||||
|
],
|
||||||
|
"response_format": { "type": "json_object" }
|
||||||
|
}
|
||||||
|
""".formatted(modeloIA, contextoInicialIA, contenidoPromptCliente);
|
||||||
|
|
||||||
|
// 3. Creamos el cliente y la petición HTTP
|
||||||
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
|
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(urlProveedorIA))
|
||||||
|
.header("Authorization", "Bearer " + apiKey).header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(jsonInformacionEntrada)).build();
|
||||||
|
|
||||||
|
// Se envía petición
|
||||||
|
System.out.println("Consultando a Groq...");
|
||||||
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
|
// Se obtiente el resultado
|
||||||
|
if (response.statusCode() == 200) {
|
||||||
|
System.out.println("Datos extraídos con éxito:");
|
||||||
|
|
||||||
|
// Aquí se llama a un método para procesar el JSON recibido, por ejemplo:
|
||||||
|
procesarRespuestaJSON(response.body());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println("❌ Error: " + response.statusCode());
|
||||||
|
System.out.println(response.body());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarRespuestaJSON(String textoJsonResputa) {
|
||||||
|
|
||||||
|
System.out.println(textoJsonResputa);
|
||||||
|
|
||||||
|
// Aquí podrías usar una librería como Jackson para convertir el JSON a objetos
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user