Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add organization
  • Loading branch information
sebastienros committed Jul 10, 2025
commit 82f49dedd81c1aab065ffa2aa9ffb2fdd7b3564f
21 changes: 16 additions & 5 deletions src/Aspire.Hosting.GitHub.Models/GitHubModelResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace Aspire.Hosting.GitHub.Models;
/// </summary>
public class GitHubModelResource : Resource, IResourceWithConnectionString, IResourceWithoutLifetime
{
internal const string GitHubModelsEndpoint = "https://models.github.ai/inference";

/// <summary>
/// Initializes a new instance of the <see cref="GitHubModelResource"/> class.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="model">The model name.</param>
public GitHubModelResource(string name, string model) : base(name)
/// <param name="organization">The organization.</param>
public GitHubModelResource(string name, string model, ParameterResource? organization) : base(name)
{
Model = model;
Organization = organization;
}

/// <summary>
Expand All @@ -28,16 +28,27 @@ public GitHubModelResource(string name, string model) : base(name)
public string Model { get; set; }

/// <summary>
/// Gets or sets the API key for accessing GitHub Models.
/// Gets or sets the organization login associated with the organization to which the request is to be attributed.
/// </summary>
/// <remarks>
/// If set, the token must be attributed to an organization.
/// </remarks>
public ParameterResource? Organization { get; set; }

/// <summary>
/// Gets or sets the API key (PAT or GitHub App minted token) for accessing GitHub Models.
/// </summary>
/// <remarks>
/// If not set, the value will be retrieved from the environment variable GITHUB_TOKEN.
/// The token must have the <code>models: read</code> permission if using a fine-grained PAT or GitHub App minted token.
/// </remarks>
public ParameterResource Key { get; set; } = new ParameterResource("github-api-key", p => Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? string.Empty, secret: true);

/// <summary>
/// Gets the connection string expression for the GitHub Models resource.
/// </summary>
public ReferenceExpression ConnectionStringExpression =>
ReferenceExpression.Create($"Endpoint={GitHubModelsEndpoint};Key={Key};Model={Model};DeploymentId={Model}");
Organization is not null
? ReferenceExpression.Create($"Endpoint=https://models.github.ai/orgs/{Organization}/inference;Key={Key};Model={Model};DeploymentId={Model}")
: ReferenceExpression.Create($"Endpoint=https://models.github.ai/inference;Key={Key};Model={Model};DeploymentId={Model}");
}
5 changes: 3 additions & 2 deletions src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ public static class GitHubModelsExtensions
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
/// <param name="model">The model name to use with GitHub Models.</param>
/// <param name="organization">The organization login associated with the organization to which the request is to be attributed.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<GitHubModelResource> AddGitHubModel(this IDistributedApplicationBuilder builder, [ResourceName] string name, string model)
public static IResourceBuilder<GitHubModelResource> AddGitHubModel(this IDistributedApplicationBuilder builder, [ResourceName] string name, string model, IResourceBuilder<ParameterResource>? organization = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);
ArgumentException.ThrowIfNullOrEmpty(model);

var resource = new GitHubModelResource(name, model);
var resource = new GitHubModelResource(name, model, organization?.Resource);

return builder.AddResource(resource)
.WithInitialState(new()
Expand Down