This package provides a deprecated integration module that enables Java applications to interact with GitHub Models through the LangChain4j framework. It offers chat models (both synchronous and streaming), embedding models, and support for AI services with tool integration, JSON schema responses, and responsible AI features. The module wraps Azure AI Inference SDK to provide a unified API for accessing various language models hosted on GitHub Models, including chat completion capabilities, embeddings generation, and content filtering management. As of version 1.10.0, this module has been marked for deprecation and future removal, with users recommended to migrate to the langchain4j-openai-official module for enhanced functionality and better integration. The library is designed for reusability as a foundational component in LLM-powered Java applications that need to leverage GitHub-hosted AI models, offering builder patterns for configuration, support for proxy options, custom timeouts, and comprehensive model service versioning capabilities.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Common configuration patterns for all model builders.
All model builders require these two parameters:
.gitHubToken(String gitHubToken)GitHub personal access token for authentication.
Best Practice: Load from environment variable, never hardcode
.gitHubToken(System.getenv("GITHUB_TOKEN"))// String
.modelName(String modelName)
// Enum (type-safe)
.modelName(GitHubModelsChatModelName modelName)
.modelName(GitHubModelsEmbeddingModelName modelName)Model identifier to use.
Best Practice: Use enum constants for type safety and IDE autocomplete
// Chat models
.modelName(GitHubModelsChatModelName.GPT_4_O)
// Embedding models
.modelName(GitHubModelsEmbeddingModelName.TEXT_EMBEDDING_3_SMALL).endpoint(String endpoint)API endpoint. Default: https://models.inference.ai.azure.com
When to customize:
.endpoint("https://custom-endpoint.example.com").serviceVersion(ModelServiceVersion serviceVersion)Azure AI service API version. Uses latest if not specified.
When to customize:
import com.azure.ai.inference.ModelServiceVersion;
.serviceVersion(ModelServiceVersion.V2024_05_01)Control model behavior and output characteristics.
.temperature(Double temperature)Controls randomness. Range: 0.0-2.0
// Deterministic
.temperature(0.0)
// Balanced
.temperature(0.7)
// Creative
.temperature(1.2).topP(Double topP)Alternative to temperature. Range: 0.0-1.0
.topP(0.9)Note: Use temperature OR topP, not both
.maxTokens(Integer maxTokens)Maximum tokens in response.
// Short responses
.maxTokens(100)
// Medium responses
.maxTokens(500)
// Long responses
.maxTokens(2000).presencePenalty(Double presencePenalty)Penalize tokens based on presence in text. Range: -2.0 to 2.0
.presencePenalty(0.6) // Encourage diversity.frequencyPenalty(Double frequencyPenalty)Penalize tokens based on frequency. Range: -2.0 to 2.0
.frequencyPenalty(0.3) // Reduce repetition.seed(Long seed)Random seed for deterministic generation.
.seed(12345L)Use case: Reproducible outputs for testing
.stop(List<String> stop)Stop generation at these sequences.
.stop(Arrays.asList("\n\n", "END", "---")).responseFormat(ChatCompletionsResponseFormat responseFormat)Control output format.
import com.azure.ai.inference.models.ChatCompletionsResponseFormatJsonObject;
.responseFormat(new ChatCompletionsResponseFormatJsonObject()).strictJsonSchema(boolean strictJsonSchema)Enable strict JSON schema validation.
.strictJsonSchema(true)Note: Only available for synchronous chat model, not streaming
.dimensions(Integer dimensions)Custom embedding dimension (if model supports).
// Reduce from default 3072 to 512
.dimensions(512)Supported models:
TEXT_EMBEDDING_3_SMALL (default: 1536)TEXT_EMBEDDING_3_LARGE (default: 3072)Not supported:
GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.build();GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName(GitHubModelsChatModelName.GPT_4_O)
.temperature(0.7)
.maxTokens(1000)
.timeout(Duration.ofSeconds(60))
.maxRetries(3)
.build();GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.temperature(1.2)
.presencePenalty(0.6)
.frequencyPenalty(0.3)
.maxTokens(2000)
.build();GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.temperature(0.0)
.seed(12345L)
.maxTokens(500)
.build();GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.responseFormat(new ChatCompletionsResponseFormatJsonObject())
.strictJsonSchema(true)
.temperature(0.3)
.build();GitHubModelsStreamingChatModel model = GitHubModelsStreamingChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o-mini")
.temperature(0.8)
.maxTokens(2000)
.timeout(Duration.ofSeconds(90))
.build();GitHubModelsEmbeddingModel model = GitHubModelsEmbeddingModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName(GitHubModelsEmbeddingModelName.TEXT_EMBEDDING_3_LARGE)
.dimensions(512)
.timeout(Duration.ofSeconds(30))
.build();// ✅ Good
.gitHubToken(System.getenv("GITHUB_TOKEN"))
// ❌ Bad
.gitHubToken("ghp_hardcoded_token_12345")// ✅ Good - type-safe, autocomplete
.modelName(GitHubModelsChatModelName.GPT_4_O)
// ⚠️ OK - flexible but error-prone
.modelName("gpt-4o")// Fast, simple tasks
.timeout(Duration.ofSeconds(30))
// Standard tasks
.timeout(Duration.ofSeconds(60))
// Complex, long responses
.timeout(Duration.ofSeconds(120))
// Streaming
.timeout(Duration.ofSeconds(90))// Development
.maxRetries(1)
// Production
.maxRetries(3)
// Critical operations
.maxRetries(5)// ✅ Good - create once, reuse
private final GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.build();
public String chat(String message) {
return model.chat(request).aiMessage().text();
}
// ❌ Bad - creates new instance every call
public String chat(String message) {
GitHubModelsChatModel model = GitHubModelsChatModel.builder()
.gitHubToken(System.getenv("GITHUB_TOKEN"))
.modelName("gpt-4o")
.build();
return model.chat(request).aiMessage().text();
}Install with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-github-models@1.11.0docs