This library has not been maintained for several months, and I am interested in taking over its development.
However, the original author has been inactive for some time.
I’ve created a fork of this library, incorporating support for the latest features of the chat API, and have also fixed some of the existing bugs in the library.
You are welcome to use it. Should I manage to reach the author, I intend to discuss the continuation of maintaining this library with them.
github–>Lambdua/openai4j
If possible, after reviewing my project and deeming it satisfactory, I would like to continue maintaining the java-lib related to the openai-api. Additionally, I request that the official documentation update or replace any links that are no longer maintained. Thank you.
Check out Langchain4j. I think the langchain approach gives MUCH more flexibility to your code, because you can plug in ANY LLM or Service, meaning everything from local models, to cloud providers like OpenAI, Google Gemini, etc.
Also there’s a new Java 22 feature “Panama” (OpenJDK: Panama) which, if it works, would give you the ability to call python directly from Java, ergo, you could make direct calls to the REAL “Langchain” (i.e. the Python one) directly from java. I haven’t gotten Panama to work yet however. If you do please share it here!
Langchain is a sophisticated library that includes many elements not directly related to the openai-api. Many people are reluctant to invest a significant amount of time to master such a complex library.
Panama is a feature that has not yet matured; I plan to experiment with it later, and if successful, I will provide relevant documentation. I have tried methods such as using Jep for Java to call Python libraries, but these methods are comparatively complex and not very user-friendly for most Java developers.
Currently, the Java library linked on the official site is no longer being maintained. It would be prudent to update this promptly, as many developers have already voiced their concerns in the issues section.
I saw the Java library you’re talking about that’s no longer being maintained, and my impression was that it was probably merely discovered by OpenAI (or they were told about it) and so they may be mentioning it on their site. However I think OpenAI is not likely the sponsor of that, and will just let it die if it dies.
Note to any OpenAI people seeing this: I’m a Java developer with decades of experience, willing to support/improve any Java libraries myself! (for pay. I’m available to hire)
About Langchain, I’d politely disagree that it’s difficult to use. It’s easy to use. The fact that it’s powerful and feature rich doesn’t mean it’s hard to use. Anything that can do as much as Langchain can take time but only if you need those advanced features.
That’s sadly true @backpetysiweb, however there is an alternative Java library since the July 2023: simple-openai, which is updated with the latest features.
I’m the author and invite you to be a contributor.
I’ve only played around with Python langchain for a single day, because I’m a Java developer, with limited Python skill. Haven’t tried out Lanchain4j myself either.
I’m still on the fence about whether a good solution for Java apps, is to just embed a real Python instance inside a docker compose and call it from Java. I just don’t see Java ever catching up to Python in terms of integration to AI libraries. And the “real” Langchain is the Python one imo. I’m not gonna ever rewrite my Java 500,000 loc project in Python, but calling Python from my app to do AI services is totally reasonable.
Python Lanchain will never be abandoned. It will exist probably in 20 years still. However, all of these java side projects people are creating are not guaranteed.
Langchain is not just a development framework designed for a specific LLM, it has rich functions and features, which are excellent and great libraries for most developers
But my core requirement is actually just some simple support for OpenAI API. I don’t need so many features, so for certain scenarios, each language has its own simple API implementation, which is simpler than calling a “third-party” language library
Openai4j is expected to support Assistant v2 version API next week The Openai4j library is simply designed for the convenience of Java developers calling Openai API, and it does not have features that other Openai APIs do not provide Simple and sufficiently singular
I just wanted to reply to this old post of mine with my current best idea for how to call LLMs from Java, which is this:
Not only will it let you call OpenAI but, like the Python Langchain it supports tons of other LLMs also, and has support for RAG/VectorDatabases, etc!!! I haven’t converted my Java code to LangChain4J yet but will be soon.