LangChain4j is a Java library for connecting applications and tests to large language models. It provides OpenAI-specific access for sending prompts and broader AI-services support for managing integrations. section 6.3.2 section 9.4
Common uses include:
- Generating structured test data from prompts, including JSON fields with format and length constraints. section 6.3.2
- Connecting LLM-based agents to application tools through function calling, @Tool, and @P annotations. section 9.4
- Selecting different GPT models while balancing capability and price. section 6.3.2
Generating contact-form data
An OpenAiChatModel receives a delimited prompt requesting a name, email, UK-format phone number, and minimum-length subject and description. The returned JSON is deserialized into ContactFormDetails, entered into a contact form, and checked for a success message. Generated data still requires verification. section 6.3.2
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>0.31.0</version>
</dependency>
The Maven dependency shows the OpenAI integration used by the Java example. section 6.3.2
