System prompt in Java
This folder contains Java examples for interacting with OpenAI, Anthropic, and Google Gemini models using system prompts.
Requirements
- Java 21+
- Maven 3.9+
- Corresponding API keys are set as environment variables (
OPENAI_API_KEY,ANTHROPIC_API_KEY, andGOOGLE_API_KEY)
Examples
OpenAiGptSystemPrompt.java: System prompt with OpenAI GPT models.AnthropicClaudeSystemPrompt.java: System prompt with Anthropic Claude models.GoogleGeminiSystemPrompt.java: System prompt with Google Gemini models.OllamaLocalSystemPrompt.java: System prompt with Ollama models.
Other instruction mechanisms
- Agent skills: Reusable packages of instructions and resources.
- Instruction artifacts: Project-specific guidance files (e.g.,
AGENTS.md).
Running the examples
You can run each example using Maven:
bash
mvn compile exec:java -Dexec.mainClass="io.github.bonigarcia.ce.OpenAiGptSystemPrompt"
mvn compile exec:java -Dexec.mainClass="io.github.bonigarcia.ce.AnthropicClaudeSystemPrompt"
mvn compile exec:java -Dexec.mainClass="io.github.bonigarcia.ce.GoogleGeminiSystemPrompt"
mvn compile exec:java -Dexec.mainClass="io.github.bonigarcia.ce.OllamaLocalSystemPrompt"