Commit Inicial
This commit is contained in:
commit
c80ffcc34e
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_act5_5_ia_swing</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
|
||||||
27
ficheros/contexto_ia_atletas.txt
Normal file
27
ficheros/contexto_ia_atletas.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Actúa como un extractor de datos JSON que, a la vez, es experto en deporte olímpico.
|
||||||
|
Analiza el texto que te van a proporcionar.
|
||||||
|
Devuelve exclusivamente un objeto JSON con esta estructura:
|
||||||
|
{
|
||||||
|
"nombre": "",
|
||||||
|
"apellidos": "",
|
||||||
|
"fecha_nacimiento": "YYYY-MM-DD",
|
||||||
|
"sexo": "H/M",
|
||||||
|
"participaciones": [
|
||||||
|
{
|
||||||
|
"disciplina": {"nombre_diciplina": "",
|
||||||
|
"diciplina_individual": "0/1",
|
||||||
|
}
|
||||||
|
|
||||||
|
"juego": {"nombre": "Ciudad_Juego(en español)",
|
||||||
|
"pais": "País_Organizador(en español)",
|
||||||
|
"anyo": YYYY,
|
||||||
|
"verano": 0/1
|
||||||
|
"mascota":{
|
||||||
|
"nombre": "Nombre_Mascota",
|
||||||
|
"url_imagen": "https://img.olympics.com/images/image/private/xxx"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
No escribas nada de texto antes o después del JSON.
|
||||||
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.jjoo</groupId>
|
||||||
|
<artifactId>ProyectoJJOO</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>
|
||||||
145
src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java
Normal file
145
src/main/java/org/lapaloma/jjoo/ClienteJuegosOlimpicosIA.java
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package org.lapaloma.jjoo;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ClienteIAJuegosOlimpicos: Clase que realiza ....
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 7 feb 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ClienteJuegosOlimpicosIA extends JFrame {
|
||||||
|
private static final long serialVersionUID = -6074564949314600423L;
|
||||||
|
|
||||||
|
private JTextArea txtPeticion;
|
||||||
|
private JButton btnEnviar;
|
||||||
|
|
||||||
|
public ClienteJuegosOlimpicosIA() {
|
||||||
|
// Configuración básica de la ventana
|
||||||
|
setTitle("Cliente IA - Acceso a Datos con IA (Groq)");
|
||||||
|
setSize(500, 300);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setLayout(new BorderLayout(10, 10));
|
||||||
|
|
||||||
|
// Panel superior con FlowLayout alineado a la izquierda
|
||||||
|
JPanel panelNorte = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JLabel lblTitulo = new JLabel("Petición a procesar (sobre deportistas):");
|
||||||
|
lblTitulo.setFont(new Font("SansSerif", Font.BOLD, 13));
|
||||||
|
|
||||||
|
// Esto asegura que la etiqueta tenga espacio suficiente independientemente del
|
||||||
|
// layout
|
||||||
|
lblTitulo.setPreferredSize(new Dimension(300, 30));
|
||||||
|
|
||||||
|
panelNorte.add(lblTitulo);
|
||||||
|
add(panelNorte, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
// Caja de texto central (tipo chat)
|
||||||
|
txtPeticion = new JTextArea();
|
||||||
|
txtPeticion.setLineWrap(true);
|
||||||
|
txtPeticion.setWrapStyleWord(true);
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(txtPeticion);
|
||||||
|
scrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
|
||||||
|
BorderFactory.createLineBorder(Color.GRAY)));
|
||||||
|
add(scrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Contenedor para la parte inferior del panel central
|
||||||
|
JPanel panelEjemplo = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
// Usamos JTextArea para que el texto pueda seleccionarse y copiarse
|
||||||
|
JTextArea txtEjemplo = new JTextArea(
|
||||||
|
"Ejemplo: Obtén información completa, precisa y ordenada de atletas que participaron en juegos olímpicos de la siguiente disciplinas: Atletismo, natación y gimnasia. Serán 6 deportistas (3 hombres y 3 mujeres) por disciplina. Proporciona información de deportistas de distintos juegos olímpicos.");
|
||||||
|
|
||||||
|
txtEjemplo.setEditable(false); // No se puede borrar/escribir
|
||||||
|
txtEjemplo.setLineWrap(true);
|
||||||
|
txtEjemplo.setWrapStyleWord(true);
|
||||||
|
txtEjemplo.setBackground(getBackground()); // Color igual al del panel
|
||||||
|
txtEjemplo.setForeground(new Color(100, 100, 100));
|
||||||
|
txtEjemplo.setFont(new Font("SansSerif", Font.ITALIC, 11));
|
||||||
|
txtEjemplo.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
|
||||||
|
|
||||||
|
// Botón de copiar pequeño
|
||||||
|
JButton btnCopiar = new JButton("📋"); // Puedes usar un icono .png si prefieres
|
||||||
|
btnCopiar.setToolTipText("Copiar texto al portapapeles");
|
||||||
|
btnCopiar.setPreferredSize(new Dimension(50, 30));
|
||||||
|
|
||||||
|
// Acción del botón
|
||||||
|
btnCopiar.addActionListener(e -> {
|
||||||
|
copiarAlPortapapeles(txtEjemplo.getText());
|
||||||
|
// Opcional: feedback visual rápido
|
||||||
|
btnCopiar.setText("✅");
|
||||||
|
new Timer(1500, ev -> btnCopiar.setText("📋")).start();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Montaje
|
||||||
|
panelEjemplo.add(txtEjemplo, BorderLayout.CENTER);
|
||||||
|
panelEjemplo.add(btnCopiar, BorderLayout.EAST); // Botón a la derecha
|
||||||
|
|
||||||
|
// Añadir al panel central igual que antes
|
||||||
|
JPanel panelCentral = new JPanel(new BorderLayout());
|
||||||
|
panelCentral.add(scrollPane, BorderLayout.CENTER);
|
||||||
|
panelCentral.add(panelEjemplo, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
add(panelCentral, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Panel inferior para el botón de envío
|
||||||
|
JPanel panelSur = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
btnEnviar = new JButton("Enviar ➤");
|
||||||
|
btnEnviar.setBackground(new Color(66, 133, 244));
|
||||||
|
btnEnviar.setForeground(Color.WHITE);
|
||||||
|
btnEnviar.setFocusPainted(false);
|
||||||
|
|
||||||
|
btnEnviar.addActionListener(e -> procesarPeticionCliente());
|
||||||
|
|
||||||
|
panelSur.add(btnEnviar);
|
||||||
|
add(panelSur, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
private void copiarAlPortapapeles(String texto) {
|
||||||
|
StringSelection selection = new StringSelection(texto.replace("Ejemplo: ", ""));
|
||||||
|
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
clipboard.setContents(selection, selection);
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
new ClienteJuegosOlimpicosIA().setVisible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void procesarPeticionCliente() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
String textoPrompt = txtPeticion.getText();
|
||||||
|
|
||||||
|
System.out.println("Enviando petición: " + textoPrompt);
|
||||||
|
|
||||||
|
|
||||||
|
// Aquí se llamaría al método que hace la petición a la IA y procesa la respuesta
|
||||||
|
// Los parámetros de la petición (URL, API Key, modelo, contexto)
|
||||||
|
// están en el fichero de configuración conf.properties en la carpeta de recursos
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* GestorFicheroConfiguracion: clase utilitaria para leer propiedades del archivo application.properties.
|
||||||
|
* Provee un método estático que devuelve el valor asociado a una clave.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 25 nov 2025
|
||||||
|
*/
|
||||||
|
package org.lapaloma.jjoo.gestores;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class GestorFicheroConfiguracion {
|
||||||
|
private static final Properties PROPIEDADES = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||||
|
.getResourceAsStream("conf.properties")) {
|
||||||
|
if (is != null) {
|
||||||
|
PROPIEDADES.load(is);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Error al cargar application.properties", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene el valor asociado a la clave especificada.
|
||||||
|
*
|
||||||
|
* @param clave la clave a buscar
|
||||||
|
* @return el valor o {@code null} si no existe
|
||||||
|
*/
|
||||||
|
public static String obtenerValor(String clave) {
|
||||||
|
return PROPIEDADES.getProperty(clave);
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/main/resources/conf.properties
Normal file
5
src/main/resources/conf.properties
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Fichero para la carga de datos de Atletas con IA (GROQ)
|
||||||
|
key.api.proveedor.ia=aquí_va_tu_api_key_de_groq
|
||||||
|
url.api.proveedor.ia=https://api.groq.com/openai/v1/chat/completions
|
||||||
|
model.proveedor.ia=openai/gpt-oss-120b
|
||||||
|
fichero.contexto.ia.atletas=ficheros/contexto_ia_atletas.txt
|
||||||
Loading…
Reference in New Issue
Block a user