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 OpenAI component #5621

Merged
merged 22 commits into from
Sep 24, 2024
Merged

Add OpenAI component #5621

merged 22 commits into from
Sep 24, 2024

Conversation

sebastienros
Copy link
Member

@sebastienros sebastienros commented Sep 9, 2024

Contributes to #4567

Microsoft Reviewers: Open in CodeFlow

@davidfowl davidfowl added area-integrations Issues pertaining to Aspire Integrations packages and removed area-components labels Sep 10, 2024
@eerhardt
Copy link
Member

Is there also work to enable Aspire.Azure.AI.OpenAI to work with just an OpenAIClient when configured to talk to OpenAI or a local emulator like Ollama? Or do you see that as a separate PR?

src/Components/Aspire.OpenAI/README.md Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/README.md Outdated Show resolved Hide resolved
}
```

To learn how to use the `OpenAIClient` class refer to [Using the OpenAIClient class](https://github.com/openai/openai-dotnet?tab=readme-ov-file#using-the-openaiclient-class).
Copy link
Member

Choose a reason for hiding this comment

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

How permanent is this link? Is there an official doc site we can link to instead?

Copy link
Member Author

@sebastienros sebastienros Sep 17, 2024

Choose a reason for hiding this comment

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

Just found a new page in docs, updating. Nope, couldn't find anything more official.

Copy link
Member

Choose a reason for hiding this comment

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

I believe @AngelosP would be the best person to share what are considered official docs for this library.

src/Components/Aspire.OpenAI/README.md Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/README.md Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/AssemblyInfo.cs Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/README.md Show resolved Hide resolved
src/Components/Aspire.OpenAI/AspireOpenAIExtensions.cs Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/AssemblyInfo.cs Outdated Show resolved Hide resolved
tests/Aspire.OpenAI.Tests/ConformanceTests.cs Outdated Show resolved Hide resolved
/// <summary>
/// The settings relevant to accessing OpenAI.
/// </summary>
public sealed class OpenAISettings
Copy link
Member

Choose a reason for hiding this comment

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

@KrzysztofCwalina, any concerns about adding this as a public type in this namespace? I know you and I had discussed potentially putting such types in the SCM-based client namespaces themselves.

Or, @eerhardt, could you help us understand established precedents around these settings types for Aspire more broadly? If we e.g. wanted to enable injection of an OpenAI client in a DI container outside the context of Aspire, would we want this type to live in a non-Aspire namespace?

Copy link
Member Author

Choose a reason for hiding this comment

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

These settings types are used in Aspire to drive what and how services are registered in DI. This is standard in Aspire, even components have it.

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 wanted to also add a type called OpenAISettings in the OpenAI client namespace, would that be frowned upon?

Copy link
Member

Choose a reason for hiding this comment

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

It wouldn't be great, but it would be possible. The namespace can disambiguate.

For Aspire, the pattern is {NameOfLibrary}Settings in the Aspire.{NameOfLibrary} namespace.

See

/// <summary>
/// Provides the client configuration settings for connecting to a RabbitMQ message broker.
/// </summary>
public sealed class RabbitMQClientSettings

/// <summary>
/// Provides the client configuration settings for connecting to a Redis server.
/// </summary>
public sealed class StackExchangeRedisSettings

Copy link
Member

Choose a reason for hiding this comment

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

Cool, as long as we can keep that an an option in our back pocket, I have no concerns.


## AppHost extensions

There is no specific AppHost extension corresponding to the OpenAI integration. Instead a connection string resource can be registered:
Copy link
Member

Choose a reason for hiding this comment

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

For my learning -- what is an AppHost extension and is this something we would want to have a story for in the .NET ecosystem to support better ease of use for OpenAI? Mostly just curious on this piece.

Copy link
Member Author

Choose a reason for hiding this comment

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

An AppHost extension is a package that helps provision or describe the server part of the integration. For instance with Azure.AI.OpenAI there is a server resource that can be registered, will AI models too, such that we can provision the resource when the app is deployed. With OpenAI there is no such thing we can deploy, so we only declare a connection string, like a logical representation of this resource. Ultimately we could have a component that provides Ollama services for example.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! My comment here doesn't block this PR in any way, but I'm interested in understanding why we have one for Azure.AI.OpenAI and not OpenAI? If there are pieces needed uniquely for SCM-based clients I'd be interested to understand the gaps there and if pieces are needed from SCM to address those gaps?

Copy link
Member

Choose a reason for hiding this comment

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

why we have one for Azure.AI.OpenAI and not OpenAI?

Because you can provision an Azure OpenAI service (using bicep). That's what the "AppHost" extension will do.

You can't provision an OpenAI service. You need to sign up on their website.

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
sebastienros and others added 3 commits September 17, 2024 15:12
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
# Conflicts:
#	src/Components/Aspire.OpenAI/README.md
src/Components/Aspire.OpenAI/AssemblyInfo.cs Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/OpenAISettings.cs Outdated Show resolved Hide resolved
/// <summary>
/// The settings relevant to accessing OpenAI.
/// </summary>
public sealed class OpenAISettings
Copy link
Member

Choose a reason for hiding this comment

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

It wouldn't be great, but it would be possible. The namespace can disambiguate.

For Aspire, the pattern is {NameOfLibrary}Settings in the Aspire.{NameOfLibrary} namespace.

See

/// <summary>
/// Provides the client configuration settings for connecting to a RabbitMQ message broker.
/// </summary>
public sealed class RabbitMQClientSettings

/// <summary>
/// Provides the client configuration settings for connecting to a Redis server.
/// </summary>
public sealed class StackExchangeRedisSettings

<SuppressFinalPackageVersion>true</SuppressFinalPackageVersion>
<PackageTags>ai openai</PackageTags>
<Description>A client for OpenAI that integrates with Aspire, including metrics, logging and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)OpenAI_256x.png</PackageIconFullPath>
Copy link
Member

Choose a reason for hiding this comment

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

@DamianEdwards - you've handled this for other integrations. Can you help here?

src/Components/Aspire.OpenAI/Aspire.OpenAI.csproj Outdated Show resolved Hide resolved
src/Components/Aspire.OpenAI/AspireOpenAIExtensions.cs Outdated Show resolved Hide resolved
@sebastienros
Copy link
Member Author

Failing on unrelated cosmos tests

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.

LGTM.

Directory.Packages.props Outdated Show resolved Hide resolved
host.Services.GetRequiredKeyedService<OpenAIClient>("openai") :
host.Services.GetRequiredService<OpenAIClient>();

Assert.NotNull(client);
Copy link
Member

Choose a reason for hiding this comment

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

Can we assert on something more than "not null"?

Copy link
Member

Choose a reason for hiding this comment

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

I meant, can we assert something like the connection string or URI is correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my initial thought too but I couldn't find it in the model, do you know if it's somewhere? I didn't dig super deep, maybe I missed it. Will check again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you fine with private reflection in this case?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, let's just live with what we have. If we mis-configured it, we will know because things won't work.

@sebastienros
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sebastienros sebastienros enabled auto-merge (squash) September 24, 2024 01:14
@sebastienros sebastienros merged commit b486f32 into main Sep 24, 2024
11 checks passed
@sebastienros sebastienros deleted the sebros/openai branch September 24, 2024 01:49
@sebastienros sebastienros added this to the 9.0 milestone Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants