March 5th, 2024

Java 1.0 Release Candidate for Semantic Kernel now available

Martijn Verburg
Principal Software Engineering Group Manager

On the 19th of July 2023, we announced the first public alpha release of the Microsoft Semantic Kernel for Java. Today, we are thrilled to announce 1.0.0-rc2 as our first public Release Candidate of the Microsoft Semantic Kernel for Java! This Java library opens new developer possibilities by seamlessly integrating AI services like OpenAI and Azure OpenAI with conventional and Java idiomatic programming. Now, it is much easier to enhance existing code (business logic) with AI!

Start your AI-Java journey today!

If you have ever dreamt of combining the power of AI with the reliability of Java, your dream has now become a reality. Begin your AI-Java journey by exploring the SK, contributing to the project, and engaging with the developer community. Together, let us unlock the endless possibilities at the intersection of AI and conventional programming.

What is Semantic Kernel for Java?

Semantic Kernel for Java is an open-source library that empowers developers to harness the power of AI while coding in Java. It is compatible with Java 8 and above, ensuring flexibility and accessibility to a wide range of Java applications. By integrating AI services into your Java projects, you can unlock the full potential of artificial intelligence and large language models without sacrificing the familiar Java development environment.

Want to get started? Check out our samples

We understand that new technology can be daunting, but fear not! We have provided a repository of samples to help you quickly grasp the potential of Semantic Kernel for Java. Explore the sample code at: github.com/microsoft/semantic-kernel/tree/java-v1/java/samples/sample-code and learn how to incorporate AI services into your Java applications effortlessly.

One of the best ways to see the power of the Semantic Kernel Java SDK is to check out sample 59: OpenAI function calling. Just like the .NET SDK, you can easily give your kernel access to plugins that your agents can then automatically use. In this sample, we demonstrate how you can quickly build and semantically describe a plugin before using it with Semantic Kernel. Below, you can see a mock plugin that provides details about a given city.

public static class CityPlugin {
        @DefineKernelFunction(name = "getsTheWeatherForCity", description = "Gets the current weather at a city name")
        public String getsTheWeatherForCity(
            @KernelFunctionParameter(name = "cityName", description = "Name of the city") String cityName) {
            // Replace with a call to an actual weather API
            return "80 and sunny";
        }
    }

Afterwards, you can easily import your AI services and the plugin directly into a kernel.

ChatCompletionService chat = OpenAIChatCompletion.builder()
    .withModelId(MODEL_ID)
    .withOpenAIAsyncClient(client)
    .build();

KernelPlugin plugin = KernelPluginFactory.createFromObject(new CityPlugin(), "cityPlugin");

var kernel = Kernel.builder()
    .withAIService(ChatCompletionService.class, chat)
    .withPlugin(plugin)
    .build();

Now, when you invoke the kernel, the functions will be automatically

// Create the semantic function to invoke
var function = KernelFunctionFromPrompt.builder()
    .withTemplate("What is the probable current color of the sky in Thrapston?")
    .build();

// Enable automatic function calling for invocation
var toolCallBehavior = ToolCallBehavior.allowAllKernelFunctions(true);

var result = kernel
    .invokeAsync(function)
    .withToolCallBehavior(toolCallBehavior)
    .withResultType(ContextVariableTypes.getGlobalVariableTypeForClass(String.class))
    .block();

System.out.println(result.getResult());

After running this code, the LLM with make a call to get the weather at Thrapston, learn that it’s “80 and sunny” and respond back with a message that the sky is likely blue!

Accessing the new Java SDK

If you want to get started with the new Java SDK, we have several different ways you can access it, whether it’s from our open-source repo or on Maven Central.

We’re Open Source and MIT Licensed

We proudly share that the Semantic Kernel for Java is an open-source project. It is released under the permissive MIT license, giving you the freedom to explore, modify, and contribute to the SK. You can find the source code on GitHub at: microsoft/semantic-kernel at java-v1. We welcome your contributions to help shape the future of this project.

NOTE: For this release candidate the source branch is java-v1.

We have easy integration with Maven and Gradle

You can find the 1.0.0-rc2 release on Maven Central. This means you can easily add the SK as a dependency to your Maven or Gradle projects. Refer to our samples folder for instructions on the artifacts, their coordinates, and how to add SK to your project.

Join the conversation on Discord

We are currently in the Release Candidate phase. We encourage you to try the library, provide feedback, and report any issues. Your input is invaluable to us in refining the API and its features.

We have set up a Discord channel to foster collaboration and discussions among developers. Join us at aka.ms/java-sk-discord to interact with other enthusiasts, ask questions, share insights, and be a part of this growing community.

Furthermore, on our Discord channel, you can also learn more about the project’s roadmap, what is coming next as we progress in implementing more features and talk directly with engineering team members.

Happy coding and happy AI experimenting!

Author

Martijn Verburg
Principal Software Engineering Group Manager

Principal Software Group Engineering Manager (Java & Go) at Microsoft. Formerly the CEO at jClarity before being acquired! aka "The Diabolical Developer" :-)

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • a b

    And I though Java 8 was old

    • Martijn VerburgMicrosoft employee Author

      This is an interesting point! Microsoft's general strategy for Java versioning is to encourage our customers to modernize their Java applications and have in the past provided guides such as https://learn.microsoft.com/en-us/java/openjdk/transition-from-java-8-to-java-11 to help them do so. However, we acknowledge that for some libraries (such as Azure SDK and Semantic Kernel for Java), we need to meet the needs of our customers who are still going through that modernization process.

      Read more