GitHubModelsExtensions Methods
Class Methods 4 members
Provides extension methods for adding GitHub Models resources to the application model.
AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>) Section titled AddGitHubModel(IDistributedApplicationBuilder, string, string, IResourceBuilder<ParameterResource>) extension IResourceBuilder<GitHubModelResource> Adds a GitHub Model resource to the application model.
public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> AddGitHubModel( this IDistributedApplicationBuilder builder, string name, string model, IResourceBuilder<ParameterResource>? organization = null) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. model string The model name to use with GitHub Models. organization IResourceBuilder<ParameterResource> optional The 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>) extension IResourceBuilder<GitHubModelResource> Adds a GitHub Model resource to the application model using a
GitHubModel. public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> AddGitHubModel( this IDistributedApplicationBuilder builder, string name, GitHubModel model, IResourceBuilder<ParameterResource>? organization = null) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. model GitHubModel The model descriptor, using the GitHubModel class like so: builder.AddGitHubModel( name: "chat", model: GitHubModel.Microsoft.Phi3MediumInstruct)organization IResourceBuilder<ParameterResource> optional The 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>) extension IResourceBuilder<GitHubModelResource> Configures the API key for the GitHub Model resource from a parameter.
public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> WithApiKey( this IResourceBuilder<GitHubModelResource> builder, IResourceBuilder<ParameterResource> apiKey) { // ... }}Parameters
builder IResourceBuilder<GitHubModelResource> The resource builder. apiKey IResourceBuilder<ParameterResource> The API key parameter. Returns
IResourceBuilder<GitHubModelResource> The resource builder. Exceptions
ArgumentException Thrown when the provided parameter is not marked as secret. WithHealthCheck(IResourceBuilder<GitHubModelResource>) Section titled WithHealthCheck(IResourceBuilder<GitHubModelResource>) extension IResourceBuilder<GitHubModelResource> Adds a health check to the GitHub Model resource.
public static class GitHubModelsExtensions{ public static IResourceBuilder<GitHubModelResource> WithHealthCheck( this IResourceBuilder<GitHubModelResource> builder) { // ... }}Parameters
builder IResourceBuilder<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.