Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure AI OpenAI component #1475

Merged
merged 30 commits into from
Jan 11, 2024
Merged

Add Azure AI OpenAI component #1475

merged 30 commits into from
Jan 11, 2024

Conversation

sebastienros
Copy link
Member

@sebastienros sebastienros commented Dec 21, 2023

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-components Issues pertaining to Aspire Component packages label Dec 21, 2023
@aaronpowell
Copy link
Contributor

How will this play if someone wants to use OpenAI not Azure OpenAI Service? Or would that be a different package that you'd use since there's no "deployment" component to using OpenAI?

@sebastienros
Copy link
Member Author

How will this play if someone wants to use OpenAI not Azure OpenAI Service?

Right now this works as you can pass the api endpoint with the platform key from OpenAI in the connection string, and since OpenAIClient works with both.

Assuming we need a different resource type because of deployments, I think we should still have a single package containing a different resource and extensions. The Aspire component is mapped to the NuGet package after all.

@aaronpowell
Copy link
Contributor

How will this play if someone wants to use OpenAI not Azure OpenAI Service?

Right now this works as you can pass the api endpoint with the platform key from OpenAI in the connection string, and since OpenAIClient works with both.

Assuming we need a different resource type because of deployments, I think we should still have a single package containing a different resource and extensions. The Aspire component is mapped to the NuGet package after all.

Looking at https://github.com/dotnet/aspire/pull/1475/files#diff-6167a4d1debba09c2aa1edf9ddd056d0b186c211f8a7078d69aee859abad774cR71-R74 is seems like the ServiceUri is always required, but when using OpenAI directly you wouldn't pass that in, you'd only provide your API key.

@sebastienros
Copy link
Member Author

@aaronpowell

you'd only provide your API key

I thought one could just pass the ServiceUri and as I looked again at the sample to show you I realized it was not taking a uri, but something like "your-api-key-from-platform.openai.com" (wihtout the scheme). So yeah that doesn't work, until it actually accepts a scheme too.

Whatever, I will fix that with the new resource type that is required.

@aaronpowell
Copy link
Contributor

Ah yes, I see the confusion, the Azure.AI.OpenAI doc is confusing as OpenAI takes a single value, a string of random letters/symbols/numbers.

@sebastienros
Copy link
Member Author

I could not find an Azure.ResourceManager package for OpenAI (I assume this was hinted before). Should I implement a provisioner by generating arm/bicep or wait for an official package?

@sebastienros sebastienros marked this pull request as ready for review January 2, 2024 19:02
@mitchdenny
Copy link
Member

I could not find an Azure.ResourceManager package for OpenAI (I assume this was hinted before). Should I implement a provisioner by generating arm/bicep or wait for an official package?

You should be able to use the Azure.ResourceManager API directly and just pass in Bicep for the local provisioner.

@mitchdenny
Copy link
Member

The secrets PR was merged in. we now have a SecretResource type that you can use for Open AI.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Components changes look good for an initial merge. I'm a bit concerned about making our own connection string format. I hope we can move that format into the Azure SDK. But we don't need to block the initial change on it.

@@ -11,20 +11,25 @@ namespace Aspire.Hosting.ApplicationModel;
/// <param name="name">The name of the resource.</param>
public class AzureOpenAIResource(string name) : Resource(name), IAzureResource, IResourceWithConnectionString
{
private readonly Collection<AzureOpenDeploymentResource> _deployments = [];
private readonly Collection<AzureOpenAIDeploymentResource> _deployments = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection<T>? Why not List<T>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl I followed the way AzureSqlServerResource was implemented since it had a similar model. Should I go ahead and replace this by IList/IReadOnlyList in both resources?

/// <summary>
/// Represents an Azure OpenAI Deployment resource.
/// </summary>
public class AzureOpenAIDeploymentResource : Resource,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are defining a connection string format, perhaps we should include a connection string that includes the deployment name too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. no need to block on this feedback though.

/// <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>
/// <returns>A reference to the <see cref="IResourceBuilder{OpenAIResource}"/>.</returns>
public static IResourceBuilder<OpenAIResource> AddOpenAI(this IDistributedApplicationBuilder builder, string name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. Let's say I'm building an app that uses Open AI (not Azure Open AI) and I want to deploy it on ACA via AZD. This won't work because the manifest will contain an openai.v0 resource which AZD doesn't know how to handle.

What we'll probably need to do here is have this resource type emit a connectionString field which contains the Open AI connection string. But for security reasons it would reference a secretstore/secret which in turn would use an input field to capture this detail during deployment.

We can get this in to main and I can help you work through this though since the secrets stuff is pretty new and not baked into AZD (yet).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because the manifest will contain an openai.v0 resource which AZD doesn't know how to handle.

I thought the idea of the manifest was to describe all it could, and the consumers to convert to what they can use. In this case would do nothing for openai.v0.

Should I remove this line from the manifest at least?

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this. I have some reservations about AddOpenAI and how it'll work in the manifest and deployment time but we can do a follow up on this since it needs to integrate with the secrets stuff once its supported in deployment tools.

github-merge-queue bot pushed a commit to microsoft/semantic-kernel that referenced this pull request Jan 11, 2024
…4555)

Having an OpenAIClient in DI will become increasingly common with
dotnet/aspire#1475.

cc: @sebastienros
github-merge-queue bot pushed a commit to microsoft/semantic-kernel that referenced this pull request Jan 11, 2024
…4555)

Having an OpenAIClient in DI will become increasingly common with
dotnet/aspire#1475.

cc: @sebastienros
github-merge-queue bot pushed a commit to microsoft/semantic-kernel that referenced this pull request Jan 11, 2024
…4555)

Having an OpenAIClient in DI will become increasingly common with
dotnet/aspire#1475.

cc: @sebastienros
github-merge-queue bot pushed a commit to microsoft/semantic-kernel that referenced this pull request Jan 11, 2024
…4555)

Having an OpenAIClient in DI will become increasingly common with
dotnet/aspire#1475.

cc: @sebastienros
@sebastienros sebastienros merged commit fda8262 into main Jan 11, 2024
8 checks passed
@sebastienros sebastienros deleted the sebros/openai branch January 11, 2024 22:18
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-components Issues pertaining to Aspire Component packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants