liveBook · Manning

OpenAI API

As explained in Software Testing with Generative AI

A web interface that provides programmatic access to OpenAI's artificial-intelligence models and services.

Provides programmatic access to OpenAI language models through authenticated requests, with usage charged by input and output tokens. Set a usage limit to control costs. section 6.3.1

A practical integration involves:

  • Create an OpenAI account, generate a secret API key, and store it because it cannot be viewed again. section 6.3.1
  • Add the LangChain4j OpenAI library, choose a model such as gpt-3.5-turbo or gpt-4o, and send a prompt. section 6.3.2
  • Request structured JSON test data, parse it into a Java object, and use it in an automated contact-form check. section 6.3.2

Generated contact-form data

A prompt asks for a name, email, UK-format phone number, a subject over 20 characters, and a description over 50 characters. The returned JSON populates a contact form, whose success message is then asserted. section 6.3.2

<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-open-ai</artifactId>
    <version>0.31.0</version>
</dependency>

Shows the Maven dependency used to connect Java code with OpenAI through LangChain4j. section 6.3.2

How Software Testing with Generative AI covers it

How deep it goes
Explains account setup, authentication, model selection, prompting, JSON parsing, and test integration without detailing HTTP internals.
Examples
Uses a structured contact-form prompt, generated JSON, Java deserialization, and a success-message assertion.
What it assumes
Assumes Java and Maven familiarity while explaining account registration, API-key creation, and basic prompt submission.
What you can do after
Build automated Java checks that generate and consume test data through LangChain4j.
How it connects
Connects language models, GPT models, LangChain4j, JSON, and automated testing.

Also explained in

Compare how 4 books explain OpenAI API →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.