İçeriğe geç

GitHub Models hosting integration

Bu içerik henüz dilinizde mevcut değil.

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 CLI — Aspire.Hosting.GitHub.Models paketi ekle
aspire add github-models

Aspire CLI etkileşimlidir; istendiğinde uygun sonucu seçin:

Aspire CLI — Örnek çıktı
Select an integration to add:
> github-models (Aspire.Hosting.GitHub.Models)
> Other results listed as selectable options...

To add a GitHubModelResource to your AppHost project, call the AddGitHubModel method:

C# — AppHost.cs
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.

For organization-specific requests, you can specify an organization parameter:

C# — AppHost.cs
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.

The GitHub Models integration supports multiple ways to configure authentication:

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"
}
}

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"
}
}

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();

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.OpenAIGpt4oMini
  • GitHubModel.OpenAI.OpenAIGpt41Mini
  • GitHubModel.DeepSeek.DeepSeekV30324
  • GitHubModel.Microsoft.Phi4MiniInstruct

Check the GitHub Models documentation for more information about these models and their capabilities.