Pular para o conteĂşdo principal

Postagens

Mostrando postagens com o rĂłtulo java

Connecting to MCP Servers using Java

You probably heard about Model Context Protocol (MCP) , which is basically a standard for connecting Tools to LLMs. It was released November 2024 and a few months later we have a good list of MCP Clients and MCP Servers .  Building MCP Server is easy with Quarkus and there are a few good servers available with one single jbang command. Check the Quarkiverse MCP Servers project! For the client I did find myself with some difficult finding a good lightweight open MCP Client. Don't get me wrong, I know there are good alternatives, but I only use ollama locally and I don't want to fell in the multiverse of LLM Clients to find one that fits my needs. I wanted to build my own MCP Client! In this post let's take a look at MCP Java SDK to build our own client. MCP Java SDK MCP provides a good modern Java SDK for building MCP applications. Quarkus and langchain4j are also a good alternative, but this time I needed something low level.  To get started with the MCP Java SDK you ...

LLM-Powered Java Development: Using Quarkus and Langchain4J to Run Python-Generated Code

Code on my github   You may have heard that Auto Regressive LLMs (Large Language Models) are not good with certain tasks, given wrong or inaccurate results. Classical examples is the prompt: count the number of r in word strawberry Asking local llama 3.2 to count the number of 'r' on word 'strawberry' and it wrongly says 2 Or which number is bigger: 9.11 or 9.9 Asking Llama 3.2 the prompt which number is bigger: 9.11 or 9.9 and it wrongly says that 9.11 is bigger Of course modern LLMs may be trained to target such cases and may get it right, but if you try similar prompts you may get inaccurate results or even make the LLM "think" that they should answer something else and change the answer to something wrong. But still, there are issues that LLMs simply can't solve due the tokenization process and the context lenght. This is discussed in depth in recent Andrej Karpathy video about LLMs: In this same video Karpathy suggests the use of code to solve such ...

Computer Vision with JavaFX and DJL

Computer Vision is not a new topic in Computer Science, but in the recent years it got a boost due the use of Neural Networks for classification, object detection, instance segmentation and pose prediction. We can make use of these algorithms in Java using a Deep Learning library, such as DL4J  as we already did in this blog with  handwritten digits recognition , and detecting objects in a JavaFX application . However, deep learning is popular mostly among Python developers (one reason is because Python easily wraps on top of native libraries, it will be easier in Java after Project Panama ), so we have much more pre-trained models for Tensorflow and Pytorch libraries. It is possible to import them, but it requires a bit more of work then simply reusing a pre-trained model. Fortunately there is a new library called Deep Java Library  which offers a good set of pre-trained models. It makes use of Jupyter , which makes easier to try the library APIs. Another DJL feature ...

Database Query Server using Quarkus

We are updating our application to Quarkus and I have this requirement of supporting datasouces that users of our application can create. This is already supported in Widlfly , but does not seem to be supported on Quarkus . Before implementing this in our system we created a PoC which we share in this post. The problem Agroal is the part of Quarkus responsible for DataSources and pool connections. It is easy to configure datasources in Quarkus, but some properties only works during development time, after the JAR for distribution is built then you can't change some properties. The solution is programatically create datasources  so the application is flexible in a way that we can add datasets using system properties. We also must make sure that all supported data base drivers are in the application so users just needs to setup properties and no other action is required. All drivers dependencies Datasource from property We can create datasources using a map of properties. The proper...

Using jbang for ETL Scripts

As a Java programmer I prefer to use good old Java to extract/transform/load data to make it usable in tools I work for data visualization. However, it is a burden having to use maven just to write a single Java file. Hopefully there's a new tool called jbang that makes it easier to do scripting in Java. More than simple scripts What is impressive about jbang is that you are not restricted to standard Java APIs in fact you can use any library you want coming from Maven! What you will miss is the burden of having to deal with pom.xml and maven builds. Dependencies are simply declared in the Java file itself using a " DEPS " comment, for example: //DEPS org.slf4j:slf4j-nop:1.7.25 Installation To install jbang you just have to check the best way for you in downloads page.  In my case I have sdkman, so it was just a matter of running: $ sdk install jbang Hello World The simplest hello world we can thing can run with jbang without any additional configuration, just install j...

Porting Battleship Game to Android

 The final goal of creating a battleship game was porting it to Android so I can run it on my phone. I was not in the mood to do all configuration and remember how to do it. This changed when GluonHQ introduced start.gluon.io . In this brief post I will share my steps porting the Battleship Game to JavaFX.  Android application development To take advantage of start.gluon.io I created a project and made it part of battleship maven project : The I modified the original JavaFX app so I could use it in the Android ready app: Decoupled the application setup from a pure desktop app: Instead doing setup on desktop main, I moved it to a separated class, so I could reuse the setup in mobile app; Resize: Since I didn't know the target device size, I had to react to scene resize to redraw the game boards. This was easily accomplished by adding a default method in Screen interface, which is called when Scene is resized. Then screen can modify boards size accordingly. I made more small c...