package Desafio_MusicaJPA.Alura;
import Desafio_MusicaJPA.Alura.Principal.Main;
import Desafio_MusicaJPA.Alura.Service.Repositorio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AluraApplication implements CommandLineRunner {
@Autowired(required = true)
private Repositorio repositorio;
public static void main(String[] args) {
SpringApplication.run(AluraApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
Main main = new Main(repositorio);
main.exibeMenu();
}
}
package Desafio_MusicaJPA.Alura.Service;
import Desafio_MusicaJPA.Alura.Model.Artista;
import Desafio_MusicaJPA.Alura.Model.Genero;
import Desafio_MusicaJPA.Alura.Model.Musica;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface Repositorio extends JpaRepository<Artista,Long> {
List<Artista> findByNomeContainingIgnoreCase(String trechonome);
@Query("select m from Musica m WHERE m.genero = :genero ")
List<Musica> buscaporgenero(Genero genero);
}
package Desafio_MusicaJPA.Alura.Service;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;
public class ConsultaChatGpt {
public static String buscadorDeInformações(String texto) {
OpenAiService service = new OpenAiService(System.getenv("OPENAI_APIKEY"));
CompletionRequest requisicao = CompletionRequest.builder()
.model("gpt-3.5-turbo-instruct")
.prompt("me traga informações do artista: " + texto)
.maxTokens(1000)
.temperature(0.7)
.build();
var resposta = service.createCompletion(requisicao);
return resposta.getChoices().get(0).getText();
}
}