GitHub Models hosting integration
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
The Aspire GitHub Models hosting integration models GitHub Models resources as GitHubModelResource. To access these types and APIs, install the 📦 Aspire.Hosting.GitHub.Models NuGet package:
aspire add github-modelsDie Aspire CLI ist interaktiv; das passende Suchergebnis wählen, wenn gefragt:
Select an integration to add:
> github-models (Aspire.Hosting.GitHub.Models)> Other results listed as selectable options...#:package Aspire.Hosting.GitHub.Models@*<PackageReference Include="Aspire.Hosting.GitHub.Models" Version="*" />Add a GitHub Model resource
Section titled “Add a GitHub Model resource”To add a GitHubModelResource to your AppHost project, call the AddGitHubModel method:
var builder = DistributedApplication.CreateBuilder(args);
var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini");
builder.AddProject<Projects.ExampleProject>() .WithReference(chat);
builder.Build().Run();The preceding code adds a GitHub Model resource named chat using the identifier string for OpenAI’s GPT-4o-mini model. The WithReference method passes the connection information to the ExampleProject project.
Specify an organization
Section titled “Specify an organization”For organization-specific requests, you can specify an organization parameter:
var builder = DistributedApplication.CreateBuilder(args);
var organization = builder.AddParameter("github-org");var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini", organization);
builder.AddProject<Projects.ExampleProject>() .WithReference(chat);
builder.Build().Run();When an organization is specified, the token must be attributed to that organization in GitHub.
Configure API key authentication
Section titled “Configure API key authentication”The GitHub Models integration supports multiple ways to configure authentication:
Default API key parameter
Section titled “Default API key parameter”By default, the integration creates a parameter named {resource_name}-gh-apikey that automatically falls back to the GITHUB_TOKEN environment variable:
var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini");Then in user secrets:
{ "Parameters": { "chat-gh-apikey": "YOUR_GITHUB_TOKEN_HERE" }}Custom API key parameter
Section titled “Custom API key parameter”You can also specify a custom parameter for the API key:
var apiKey = builder.AddParameter("my-api-key", secret: true);var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini") .WithApiKey(apiKey);Then in user secrets:
{ "Parameters": { "my-api-key": "YOUR_GITHUB_TOKEN_HERE" }}Health checks
Section titled “Health checks”You can add health checks to verify the GitHub Models endpoint accessibility and API key validity:
var chat = builder.AddGitHubModel("chat", "openai/gpt-4o-mini") .WithHealthCheck();Available models
Section titled “Available models”GitHub Models supports various AI models. Use the strongly-typed GitHubModel constants for the most up-to-date list of available models. Some popular options include:
GitHubModel.OpenAI.OpenAIGpt4oMiniGitHubModel.OpenAI.OpenAIGpt41MiniGitHubModel.DeepSeek.DeepSeekV30324GitHubModel.Microsoft.Phi4MiniInstruct
Check the GitHub Models documentation for more information about these models and their capabilities.