-
Notifications
You must be signed in to change notification settings - Fork 839
Image generation tool #6749
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
Draft
ericstj
wants to merge
26
commits into
dotnet:main
Choose a base branch
from
ericstj:ImageGenerationTool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Image generation tool #6749
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ffe9a92
Prototype of using ImageGenerationTool
ericstj e5edc77
Handle DataContent returned from ImageGen
ericstj 2d19cce
React to rename and improve metadata
ericstj 5eef474
Handle image_generation tool content from streaming
ericstj ff80804
Add handling for combining updates with images
ericstj 1725ce1
Add tests for new ChatResponseUpdateExtensions
ericstj c44f5fb
Merge branch 'main' of https://github.com/dotnet/extensions into Imag…
ericstj b4fe94b
Rename ImageGenerationTool to HostedImageGenerationTool
ericstj 06bfa30
Remove ChatResponseUpdateCoalescingOptions
ericstj ca8b15d
Add ImageGeneratingChatClient
ericstj 62e0ac5
Fix namespace of tool
ericstj 81e6e5a
Replace traces of function calling
ericstj 6559a66
More namepsace fix
ericstj 398bbdb
Enable editing
ericstj ac2de35
Merge branch 'main' of https://github.com/dotnet/extensions into Imag…
ericstj 1d96532
Update to preview OpenAI with image tool support
ericstj 6a6ffa2
Temporary OpenAI feed
ericstj 94ceab2
Fix tests
ericstj 96e9747
Add integration tests for ImageGeneratingChatClient
ericstj 9ddc91a
Remove ChatRole.Tool -> Assistant workaround
ericstj 3b589ac
Remove use of private reflection for Image results
ericstj 20919ab
Add ChatResponseUpdate.Clone
ericstj e5f68a6
Move all mutable state into RequestState object
ericstj 9f9a430
Adjust prompt to improve integration test reliability
ericstj 799a72e
Refactor tool initialization
ericstj 6029b01
Add integration tests for streaming
ericstj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
251 changes: 251 additions & 0 deletions
251
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...icrosoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdateCoalescingOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Provides options for configuring how <see cref="ChatResponseUpdate"/> instances are coalesced | ||
/// when converting them to <see cref="ChatMessage"/> instances. | ||
/// </summary> | ||
[Experimental("EXTAI0001")] | ||
public class ChatResponseUpdateCoalescingOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether to replace existing <see cref="DataContent"/> items | ||
/// when a new <see cref="DataContent"/> item with the same <see cref="DataContent.Name"/> is encountered. | ||
/// </summary> | ||
/// <value> | ||
/// <see langword="true"/> to replace existing <see cref="DataContent"/> items with the same name; | ||
/// <see langword="false"/> to keep all <see cref="DataContent"/> items. The default is <see langword="false"/>. | ||
/// </value> | ||
/// <remarks> | ||
/// When this property is <see langword="true"/>, if a <see cref="DataContent"/> item is being added | ||
/// and there's already a <see cref="DataContent"/> item in the content list with the same | ||
/// <see cref="DataContent.Name"/>, the existing item will be replaced with the new one. | ||
/// This is useful for scenarios where updated data should override previous data with the same identifier. | ||
/// </remarks> | ||
public bool ReplaceDataContentWithSameName { get; set; } | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Libraries/Microsoft.Extensions.AI.Abstractions/Image/ImageGenerationTool.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary>Represents a hosted tool that can be specified to an AI service to enable it to perform image generation.</summary> | ||
/// <remarks> | ||
/// This tool does not itself implement image generation. It is a marker that can be used to inform a service | ||
/// that the service is allowed to perform image generation if the service is capable of doing so. | ||
/// </remarks> | ||
[Experimental("MEAI001")] | ||
public class ImageGenerationTool : AITool | ||
ericstj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ImageGenerationTool"/> class with the specified options. | ||
/// </summary> | ||
/// <param name="options">The options to configure the image generation request. If <paramref name="options"/> is <see langword="null"/>, default options will be used.</param> | ||
public ImageGenerationTool(ImageGenerationOptions? options = null) | ||
: base() | ||
{ | ||
AdditionalProperties = new AdditionalPropertiesDictionary(new Dictionary<string, object?> | ||
ericstj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
[nameof(ImageGenerationOptions)] = options | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override IReadOnlyDictionary<string, object?> AdditionalProperties { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's other hosted tools, like OpenAI's Code Interpreter. Other providers have something similar. Anthropic for example has Web Search, Fetch and Code Interpreter as "Server Tools". Maybe out of scope for this change, but a generalized abstraction for these would be great. AdditionalProperties seems to be common for all of them - including the Anthropic ones. So I think this would fit beautifully as a more general abstraction than
ImageGenerationTool
.ServerTool
orHostedTool
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have HostedWebSearchTool, HostedCodeInterpreterTool, HostedFileSearchTool, and HostedMcpServerTool. Having a HostedImageGenerationTool makes sense to me. Different providers have different ways of exposing the same fundamental information, so being able to write e.g. HostedWebSearchTool, and have that map to the right thing for Gemini and Anthropic and OpenAI makes sense to me. AdditionalProperties can be used in each when there's some setting that's not exposed in a strongly-typed fashion on the tool type.