Skip to content

b0-0sk/openai-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 OpenAI Client · Java + Spring Boot

This project is a secure, production-ready integration with the OpenAI API, built using Java 21 and Spring Boot. It provides a clean and extensible service for interacting with ChatGPT models via HTTP.


🚀 Features

  • 🔐 Encrypted API key support via Jasypt
  • 📡 Connects to OpenAI Chat Completion endpoint
  • 🧪 Integration test to verify external API connectivity
  • 🧰 Configuration via application.properties
  • ✅ CI-ready with GitHub Actions

⚙️ Requirements


🔧 Configuration

All sensitive configuration is encrypted using Jasypt.

🔐 Required properties:

openai.api.url=https://api.openai.com/v1/chat/completions
openai.api.model=gpt-3.5-turbo
openai.api.key=ENC(ENCRYPTED_KEY_HERE)
jasypt.encryptor.algorithm=PBEWithMD5AndTripleDES

The Jasypt password must be provided via:

  • VM Option:

    -Djasypt.encryptor.password=your-secret
    
  • Or GitHub Actions secret: JASYPT_PASSWORD


▶️ Usage

Inject the service:

@Autowired
private OpenAiService openAiService;

String reply = openAiService.chat("Hello, how are you?");
System.out.println(reply);

🧪 Integration Test

A test class (OpenAiApiConnectivityTest) ensures that the application can reach OpenAI and receive a valid response.

Run it with:

mvn test -Djasypt.encryptor.password=your-secret

⚙️ GitHub Actions CI

This project includes a GitHub Actions workflow that:

  • Builds and tests your app on push/pull requests
  • Uses secrets to pass the Jasypt password securely

Secrets required:

Name Description
JASYPT_PASSWORD Password to decrypt your API key

📁 Project structure

src
├── main
│   └── java/org/abosk/openaiclient
│       ├── config
│       ├── service
│       └── controller
├── test
│   └── java/org/abosk/openaiclient/integration
└── resources
    └── application.properties

📄 License

This project is open-source and available under the MIT License.


👨‍💻 Author

Arnau Bosch 🔗 LinkedIn 🐙 GitHub

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages