-
Notifications
You must be signed in to change notification settings - Fork 850
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
Merged
Merged
Image generation tool #6749
Changes from 6 commits
Commits
Show all changes
45 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 173352a
Merge remote-tracking branch 'upstream/main' into ImageGenerationTool
ericstj 69d2d98
React to changes and fix tests
ericstj 86363f8
Address feedback
ericstj 94cffbd
Fix SkipTestException from ConditionalTheory
ericstj 67089ab
Merge branch 'main' of https://github.com/dotnet/extensions into Imag…
ericstj 56cf3b4
Fix formatting
ericstj ad2b953
Add back image replacement coalescing (removed in merge)
ericstj e20b768
Fix template tests and use new OpenAI
ericstj b392df3
Merge branch 'main' of https://github.com/dotnet/extensions into Imag…
ericstj a38fd6c
Remove use of temporary staging nuget feed
ericstj cfa3f16
Address feedback
ericstj dcdebef
Make ImageGeneratingChatClient use ImageGenerationTool*Content
ericstj a60ddd2
Remove ApplyUpdates and Coalesce ImageResults instead of DataContent.
ericstj 50db985
Workaround OpenAI issue where image data is not read for partial images.
ericstj 10467a5
Improved workaround
ericstj 8cff0ae
Return ImageGenerationToolCallContent from OpenAI
ericstj 7780595
Add OpenAI image tool tests with representation of real traffic
ericstj 9b94d68
Correct the event sequence for streaming single image
ericstj 87dfaa4
Fix some docs and refactor for clarity
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.
Uh oh!
There was an error while loading. Please reload this page.