Skip to content

Commit a318037

Browse files
committed
Update README and code examples with Model Selection Guide and correct model reference
1 parent c4a2a13 commit a318037

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

03-CoreGenerativeAITechniques/README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Getting Started](#getting-started)
77
- [Step 1: Set Your Environment Variable](#step-1-set-your-environment-variable)
88
- [Step 2: Navigate to the Examples Directory](#step-2-navigate-to-the-examples-directory)
9+
- [Model Selection Guide](#model-selection-guide)
910
- [Tutorial 1: LLM Completions and Chat](#tutorial-1-llm-completions-and-chat)
1011
- [Tutorial 2: Function Calling](#tutorial-2-function-calling)
1112
- [Tutorial 3: RAG (Retrieval-Augmented Generation)](#tutorial-3-rag-retrieval-augmented-generation)
@@ -54,6 +55,25 @@ export GITHUB_TOKEN=your_github_token_here
5455
cd 03-CoreGenerativeAITechniques/examples/
5556
```
5657

58+
## Model Selection Guide
59+
60+
These examples use different models optimized for their specific use cases:
61+
62+
**GPT-4.1-nano** (Completions example):
63+
- Ultra-fast and ultra-cheap
64+
- Perfect for basic text completion and chat
65+
- Ideal for learning fundamental LLM interaction patterns
66+
67+
**GPT-4o-mini** (Functions, RAG, and Responsible AI examples):
68+
- Small but fully-featured "omni workhorse" model
69+
- Reliably supports advanced capabilities across vendors:
70+
- Vision processing
71+
- JSON/structured outputs
72+
- Tool/function calling
73+
- More capabilities than nano, ensuring examples work consistently
74+
75+
> **Why this matters**: While "nano" models are great for speed and cost, "mini" models are the safer choice when you need reliable access to advanced features like function calling, which may not be fully exposed by all hosting providers for nano variants.
76+
5777
## Tutorial 1: LLM Completions and Chat
5878

5979
**File:** `src/main/java/com/example/genai/techniques/completions/LLMCompletionsApp.java`
@@ -85,9 +105,9 @@ List<ChatRequestMessage> messages = List.of(
85105
);
86106

87107
ChatCompletionsOptions options = new ChatCompletionsOptions(messages)
88-
.setModel("gpt-4o-mini")
89-
.setMaxTokens(200) // Limit response length
90-
.setTemperature(0.7); // Control creativity (0.0-1.0)
108+
.setModel("gpt-4.1-nano") // Fast, cost-effective model for basic completions
109+
.setMaxTokens(200) // Limit response length
110+
.setTemperature(0.7); // Control creativity (0.0-1.0)
91111
```
92112

93113
#### 3. Conversation Memory
@@ -118,6 +138,8 @@ mvn compile exec:java -Dexec.mainClass="com.example.genai.techniques.completions
118138

119139
Function calling enables AI models to request execution of external tools and APIs through a structured protocol where the model analyzes natural language requests, determines required function calls with appropriate parameters using JSON Schema definitions, and processes returned results to generate contextual responses, while the actual function execution remains under developer control for security and reliability.
120140

141+
> **Note**: This example uses `gpt-4o-mini` because function calling requires reliable tool calling capabilities that may not be fully exposed in nano models on all hosting platforms.
142+
121143
### Key Code Concepts
122144

123145
#### 1. Function Definition
@@ -193,6 +215,8 @@ mvn compile exec:java -Dexec.mainClass="com.example.genai.techniques.functions.F
193215

194216
Retrieval-Augmented Generation (RAG) combines information retrieval with language generation by injecting external document context into AI prompts, enabling models to provide accurate answers based on specific knowledge sources rather than potentially outdated or inaccurate training data, while maintaining clear boundaries between user queries and authoritative information sources through strategic prompt engineering.
195217

218+
> **Note**: This example uses `gpt-4o-mini` to ensure reliable processing of structured prompts and consistent handling of document context, which is crucial for effective RAG implementations.
219+
196220
### Key Code Concepts
197221

198222
#### 1. Document Loading
@@ -248,6 +272,8 @@ Try asking: "What is GitHub Models?" vs "What is the weather like?"
248272

249273
The Responsible AI example showcases the importance of implementing safety measures in AI applications. It demonstrates how modern AI safety systems work through two primary mechanisms: hard blocks (HTTP 400 errors from safety filters) and soft refusals (polite "I can't assist with that" responses from the model itself). This example shows how production AI applications should gracefully handle content policy violations through proper exception handling, refusal detection, user feedback mechanisms, and fallback response strategies.
250274

275+
> **Note**: This example uses `gpt-4o-mini` because it provides more consistent and reliable safety responses across different types of potentially harmful content, ensuring the safety mechanisms are properly demonstrated.
276+
251277
### Key Code Concepts
252278

253279
#### 1. Safety Testing Framework

03-CoreGenerativeAITechniques/examples/src/main/java/com/example/genai/techniques/completions/LLMCompletionsApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
*/
2929
public class LLMCompletionsApp {
3030
// Define the model once to use consistently across all examples
31-
// gpt-4o-mini is a cost-effective model good for learning and experimentation
32-
private static final String MODEL = "gpt-4o-mini";
31+
// gpt-4.1-nano is a cost-effective model good for learning and experimentation
32+
private static final String MODEL = "gpt-4.1-nano";
3333

3434
public static void main(String[] args) {
3535
// GitHub Models endpoint - provides free access to various AI models for learning

0 commit comments

Comments
 (0)