Chat and Language Models
LLMs are currently available in two API types:
LanguageModel
s. Their API is very simple - they accept aString
as input and return aString
as output.
This API is now becoming obsolete in favor of chat API (second API type).ChatLanguageModel
s. These accept either a single or multipleChatMessage
s as input
and return anAiMessage
as output.
ChatMessage
usually contains text, but some LLMs also support a mix of text andImage
s.
Examples of such chat models include OpenAI’sgpt-3.5-turbo
and Google’sgemini-pro
.
Support for LanguageModel
s will no longer be expanded in LangChain4j,
so in all new features, we will use a ChatLanguageModel
API.
ChatLanguageModel
is the low-level API in LangChain4j, offering the most power and flexibility.
There are also high-level APIs (Chain
s and AiServices
) that we will cover later, after we go over the basics.
Apart from ChatLanguageModel
and LanguageModel
, LangChain4j supports the following types of models:
EmbeddingModel
- This model can translate text into anEmbedding
.ImageModel
- This model can generate and editImage
s.ModerationModel
- This model can check if the text contains harmful content.ScoringModel
- This model can score (or rank) multiple pieces of text against a query,
essentially determining how relevant each piece of text is to the query. This is useful for RAG.
These will be covered later.
Now, let’s take a closer look at the ChatLanguageModel
API.
public interface ChatLanguageModel {
String gen