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

Enable AIFunctionFactory.Create to use Activator{Utilities}.Create #6193

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Mar 25, 2025

Adds a Create overload that takes a target type and a MethodInfo. Each invocation of the AIFunction will create/dispose of a new instance, from DI if an IServiceProvider is provided, or via new() otherwise.

@halter73, @eiriktsarpalis, @SteveSandersonMS, how do we feel about this approach? This is based on folks asking for a capability this enables in https://github.com/modelcontextprotocol/csharp-sdk.

If we want to proceed with it, I'll add tests.

Microsoft Reviewers: Open in CodeFlow

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Mar 25, 2025
@stephentoub stephentoub force-pushed the aifuncfactorycreatedi branch from d467c32 to 865c832 Compare March 25, 2025 21:11
@halter73
Copy link
Member

how do we feel about this approach?

I'm a fan.

@stephentoub stephentoub force-pushed the aifuncfactorycreatedi branch from 865c832 to 661b9db Compare March 25, 2025 22:03
@stephentoub
Copy link
Member Author

Based on offline discussion with @halter73, I'm marking this as ready for review.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

It might be worth verifying that the target type gets disposed at the end of the invocation.

…es}.Create

Adds a Create overload that takes a target type and a MethodInfo. Each invocation of the AIFunction will create/dispose of a new instance, from DI if an IServiceProvider is provided, or via new() otherwise.
@stephentoub stephentoub force-pushed the aifuncfactorycreatedi branch from 93fbe0a to 7d1f864 Compare March 26, 2025 13:46
@stephentoub
Copy link
Member Author

It might be worth verifying that the target type gets disposed at the end of the invocation.

Done

@stephentoub stephentoub enabled auto-merge (squash) March 26, 2025 13:46
@stephentoub stephentoub force-pushed the aifuncfactorycreatedi branch from 7d1f864 to ce26e55 Compare March 26, 2025 14:07
@stephentoub stephentoub merged commit 035623e into dotnet:main Mar 26, 2025
6 checks passed
@stephentoub stephentoub deleted the aifuncfactorycreatedi branch March 26, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants