GitHubModelsExtensions Methods
AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)Section titled AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> AddGitHubModel( this IDistributedApplicationBuilder builder, string name, string model, IResourceBuilder<ParameterResource>? organization = null) { // ... }}Parameters
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.modelstringThe model name to use with GitHub Models.organizationIResourceBuilder<ParameterResource>optionalThe organization login associated with the organization to which the request is to be attributed.Returns
IResourceBuilder<GitHubModelResource>A reference to the ApplicationModel.IResourceBuilder`1.AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)Section titled AddGitHubModel(IDistributedApplicationBuilder, string, GitHubModel, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>GitHubModel. public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> AddGitHubModel( this IDistributedApplicationBuilder builder, string name, GitHubModel model, IResourceBuilder<ParameterResource>? organization = null) { // ... }}Parameters
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.modelGitHubModelThe model descriptor, using the GitHubModel class like so: builder.AddGitHubModel( name: "chat", model: GitHubModel.Microsoft.Phi3MediumInstruct)organizationIResourceBuilder<ParameterResource>optionalThe organization login associated with the organization to which the request is to be attributed.Returns
IResourceBuilder<GitHubModelResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
This overload is not available in polyglot app hosts. Use the string-based overload instead.
Create a GitHub Model resource for the Microsoft Phi-3 Medium Instruct model:var builder = DistributedApplication.CreateBuilder(args);
var githubModel = builder.AddGitHubModel( "chat", GitHubModel.Microsoft.Phi3MediumInstruct);WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)Section titled WithApiKey(IResourceBuilder<GitHubModelResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<GitHubModelResource>public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> WithApiKey( this IResourceBuilder<GitHubModelResource> builder, IResourceBuilder<ParameterResource> apiKey) { // ... }}Parameters
builderIResourceBuilder<GitHubModelResource>The resource builder.apiKeyIResourceBuilder<ParameterResource>The API key parameter.Returns
IResourceBuilder<GitHubModelResource>The resource builder.Exceptions
ArgumentExceptionThrown when the provided parameter is not marked as secret.WithHealthCheck(IResourceBuilder<GitHubModelResource>)Section titled WithHealthCheck(IResourceBuilder<GitHubModelResource>)extensionIResourceBuilder<GitHubModelResource>public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> WithHealthCheck( this IResourceBuilder<GitHubModelResource> builder) { // ... }}Parameters
builderIResourceBuilder<GitHubModelResource>The resource builder.Returns
IResourceBuilder<GitHubModelResource>The resource builder.Remarks
This method adds a health check that verifies the GitHub Models endpoint is accessible, the API key is valid, and the specified model is available. The health check will:
- Return
HealthStatus.Healthywhen the endpoint returns HTTP 200 - Return
HealthStatus.Unhealthywith details when the API key is invalid (HTTP 401) - Return
HealthStatus.Unhealthywith error details when the model is unknown (HTTP 404)
Because health checks are included in the rate limit of the GitHub Models API, it is recommended to use this health check sparingly, such as when you are having issues understanding the reason the model is not working as expected. Furthermore, the health check will run a single time per application instance.