Skip to content

Commit 77e740d

Browse files
authored
Merge branch 'main' into fix/issue-13483-google-ai-vertexai-api-key
2 parents 2bf8b08 + 2c880ea commit 77e740d

65 files changed

Lines changed: 6303 additions & 4455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"esbenp.prettier-vscode",
99
"dbaeumer.vscode-eslint",
1010
"ms-semantic-kernel.semantic-kernel",
11-
"ms-java.vscode-java-pack",
11+
"vscjava.vscode-java-pack",
1212
"ms-azuretools.vscode-dapr"
1313
]
1414
}

dotnet/Directory.Packages.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="12.2.8" />
6666
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.1" />
6767
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.3.2" />
68-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.3" />
68+
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.4" />
6969
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
70-
<PackageVersion Include="Microsoft.Bcl.Memory" Version="10.0.2" />
70+
<PackageVersion Include="Microsoft.Bcl.Memory" Version="10.0.4" />
7171
<PackageVersion Include="Microsoft.Bcl.Numerics" Version="10.0.2" />
7272
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" />
7373
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
@@ -106,7 +106,7 @@
106106
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.2" />
107107
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
108108
<PackageVersion Include="System.IO.Packaging" Version="10.0.2" />
109-
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.2" />
109+
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.4" />
110110
<PackageVersion Include="System.Memory.Data" Version="10.0.2" />
111111
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
112112
<PackageVersion Include="System.Numerics.Tensors" Version="10.0.3" />
@@ -182,12 +182,12 @@
182182
<PackageVersion Include="sqlite-vec" Version="0.1.7-alpha.2.1" />
183183
<PackageVersion Include="NRedisStack" Version="1.0.0" />
184184
<PackageVersion Include="Milvus.Client" Version="2.3.0-preview.1" />
185-
<PackageVersion Include="Testcontainers" Version="4.6.0" />
185+
<PackageVersion Include="Testcontainers" Version="4.10.0" />
186186
<PackageVersion Include="Testcontainers.Milvus" Version="4.8.1" />
187187
<PackageVersion Include="Testcontainers.MongoDB" Version="4.6.0" />
188188
<PackageVersion Include="Testcontainers.MsSql" Version="4.6.0" />
189189
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.6.0" />
190-
<PackageVersion Include="Testcontainers.Qdrant" Version="4.6.0" />
190+
<PackageVersion Include="Testcontainers.Qdrant" Version="4.10.0" />
191191
<PackageVersion Include="Testcontainers.Redis" Version="4.6.0" />
192192
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.2" />
193193
<PackageVersion Include="Qdrant.Client" Version="1.15.1" />

dotnet/samples/Concepts/Concepts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<PackageReference Include="Docker.DotNet" />
1919
<PackageReference Include="Google.Apis.Auth" />
2020
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
21+
<PackageReference Include="Microsoft.Bcl.Memory" />
2122
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" />
2223
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2324
<PackageReference Include="Npgsql" />

dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@ internal async Task<string> GenerateImageAsync(
3737
var imageOptions = new ImageGenerationOptions()
3838
{
3939
Size = size,
40-
ResponseFormat = GeneratedImageFormat.Uri
4140
};
4241

4342
// The model is not required by the OpenAI API and defaults to the DALL-E 2 server-side - https://platform.openai.com/docs/api-reference/images/create#images-create-model.
44-
// However, considering that the model is required by the OpenAI SDK and the ModelId property is optional, it defaults to DALL-E 2 in the line below.
45-
targetModel = string.IsNullOrEmpty(targetModel) ? "dall-e-2" : targetModel!;
43+
// However, considering that the model is required by the OpenAI SDK and the ModelId property is optional, it defaults to gpt-image-1 in the line below.
44+
targetModel = string.IsNullOrEmpty(targetModel) ? "gpt-image-1" : targetModel!;
4645

4746
ClientResult<GeneratedImage> response = await RunRequestAsync(() => this.Client!.GetImageClient(targetModel).GenerateImageAsync(prompt, imageOptions, cancellationToken)).ConfigureAwait(false);
4847
var generatedImage = response.Value;
4948

50-
return generatedImage.ImageUri?.ToString() ?? throw new KernelException("The generated image is not in url format");
49+
if (generatedImage.ImageUri is not null)
50+
{
51+
return generatedImage.ImageUri.ToString();
52+
}
53+
54+
if (generatedImage.ImageBytes is not null)
55+
{
56+
return $"data:image/png;base64,{Convert.ToBase64String(generatedImage.ImageBytes.ToArray())}";
57+
}
58+
59+
throw new KernelException("The generated image has no valid content.");
5160
}
5261

5362
/// <summary>
@@ -113,6 +122,9 @@ internal async Task<IReadOnlyList<ImageContent>> GetImageContentsAsync(
113122
{
114123
"STANDARD" => GeneratedImageQuality.Standard,
115124
"HIGH" or "HD" => GeneratedImageQuality.High,
125+
"MEDIUM" => GeneratedImageQuality.Medium,
126+
"LOW" => GeneratedImageQuality.Low,
127+
"AUTO" => GeneratedImageQuality.Auto,
116128
_ => throw new NotSupportedException($"The provided quality '{quality}' is not supported.")
117129
};
118130
}

dotnet/src/Connectors/Connectors.OpenAI/Services/OpenAITextToImageService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public OpenAITextToImageService(
3636
HttpClient? httpClient = null,
3737
ILoggerFactory? loggerFactory = null)
3838
{
39-
this._client = new(modelId ?? "dall-e-2", apiKey, organization, null, httpClient, loggerFactory?.CreateLogger(this.GetType()));
39+
this._client = new(modelId ?? "gpt-image-1", apiKey, organization, null, httpClient, loggerFactory?.CreateLogger(this.GetType()));
4040
}
4141

4242
/// <inheritdoc/>

dotnet/src/Connectors/Connectors.OpenAI/Settings/OpenAITextToImageExecutionSettings.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public sealed class OpenAITextToImageExecutionSettings : PromptExecutionSettings
1919
/// </summary>
2020
/// <remarks>
2121
/// <list type="bullet">
22-
/// <item>Must be one of <c>256x256, 512x512, or 1024x1024</c> for <c>dall-e-2</c> model.</item>
23-
/// <item>Must be one of <c>1024x1024, 1792x1024, 1024x1792</c> for <c>dall-e-3</c> model.</item>
22+
/// <item>Must be one of <c>1024x1024, 1536x1024, 1024x1536, auto</c> for <c>gpt-image-1</c> model.</item>
2423
/// </list>
2524
/// </remarks>
2625
public (int Width, int Height)? Size
@@ -38,12 +37,12 @@ public sealed class OpenAITextToImageExecutionSettings : PromptExecutionSettings
3837
/// The quality of the image that will be generated.
3938
/// </summary>
4039
/// <remarks>
41-
/// Must be one of <c>standard</c> or <c>hd</c> or <c>high</c>.
4240
/// <list type="bullet">
4341
/// <item><c>standard</c>: creates images with standard quality. This is the default.</item>
4442
/// <item><c>hd</c> OR <c>high</c>: creates images with finer details and greater consistency.</item>
43+
/// <item><c>medium</c>: creates images with medium quality (supported by <c>gpt-image-1</c>).</item>
44+
/// <item><c>low</c>: creates images with lower quality for faster generation (supported by <c>gpt-image-1</c>).</item>
4545
/// </list>
46-
/// This param is only supported for <c>dall-e-3</c> model.
4746
/// </remarks>
4847
[JsonPropertyName("quality")]
4948
public string? Quality
@@ -66,7 +65,7 @@ public string? Quality
6665
/// <item><c>vivid</c>: causes the model to lean towards generating hyper-real and dramatic images.</item>
6766
/// <item><c>natural</c>: causes the model to produce more natural, less hyper-real looking images.</item>
6867
/// </list>
69-
/// This param is only supported for <c>dall-e-3</c> model.
68+
/// This param is not supported for <c>gpt-image-1</c> model.
7069
/// </remarks>
7170
[JsonPropertyName("style")]
7271
public string? Style

dotnet/src/IntegrationTests/Connectors/AzureOpenAI/AzureOpenAITextToImageTests.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class AzureOpenAITextToImageTests
2525
.Build();
2626

2727
[Fact(Skip = "This test is for manual verification.")]
28-
public async Task ItCanReturnImageUrlAsync()
28+
public async Task ItCanReturnImageContentAsync()
2929
{
3030
// Arrange
3131
AzureOpenAIConfiguration? configuration = this._configuration.GetSection("AzureOpenAITextToImage").Get<AzureOpenAIConfiguration>();
@@ -35,7 +35,8 @@ public async Task ItCanReturnImageUrlAsync()
3535
.AddAzureOpenAITextToImage(
3636
deploymentName: configuration.DeploymentName,
3737
endpoint: configuration.Endpoint,
38-
credentials: new AzureCliCredential())
38+
credentials: new AzureCliCredential(),
39+
apiVersion: "2025-04-01-preview")
3940
.Build();
4041

4142
var service = kernel.GetRequiredService<ITextToImageService>();
@@ -45,11 +46,11 @@ public async Task ItCanReturnImageUrlAsync()
4546

4647
// Assert
4748
Assert.NotNull(result);
48-
Assert.StartsWith("https://", result);
49+
Assert.NotEmpty(result);
4950
}
5051

5152
[Fact]
52-
public async Task GetImageContentsCanReturnImageUrlAsync()
53+
public async Task GetImageContentsCanReturnImageAsync()
5354
{
5455
// Arrange
5556
AzureOpenAIConfiguration? configuration = this._configuration.GetSection("AzureOpenAITextToImage").Get<AzureOpenAIConfiguration>();
@@ -59,7 +60,8 @@ public async Task GetImageContentsCanReturnImageUrlAsync()
5960
.AddAzureOpenAITextToImage(
6061
deploymentName: configuration.DeploymentName,
6162
endpoint: configuration.Endpoint,
62-
credentials: new AzureCliCredential())
63+
credentials: new AzureCliCredential(),
64+
apiVersion: "2025-04-01-preview")
6365
.Build();
6466

6567
var service = kernel.GetRequiredService<ITextToImageService>();
@@ -70,8 +72,8 @@ public async Task GetImageContentsCanReturnImageUrlAsync()
7072
// Assert
7173
Assert.NotNull(result);
7274
Assert.NotEmpty(result);
73-
Assert.NotEmpty(result[0].Uri!.ToString());
74-
Assert.StartsWith("https://", result[0].Uri!.ToString());
75+
var imageContent = result[0];
76+
Assert.True(imageContent.Uri is not null || imageContent.Data is not null, "Image content should have either a URI or binary data.");
7577
}
7678

7779
[Fact]
@@ -89,6 +91,7 @@ public async Task SemanticKernelVersionHeaderIsSentAsync()
8991
deploymentName: configuration.DeploymentName,
9092
endpoint: configuration.Endpoint,
9193
credentials: new AzureCliCredential(),
94+
apiVersion: "2025-04-01-preview",
9295
httpClient: httpClient)
9396
.Build();
9497

@@ -100,8 +103,8 @@ public async Task SemanticKernelVersionHeaderIsSentAsync()
100103
// Assert
101104
Assert.NotNull(result);
102105
Assert.NotEmpty(result);
103-
Assert.NotEmpty(result[0].Uri!.ToString());
104-
Assert.StartsWith("https://", result[0].Uri!.ToString());
106+
var imageContent = result[0];
107+
Assert.True(imageContent.Uri is not null || imageContent.Data is not null, "Image content should have either a URI or binary data.");
105108
Assert.NotNull(httpHeaderHandler.RequestHeaders);
106109
Assert.True(httpHeaderHandler.RequestHeaders.TryGetValues("Semantic-Kernel-Version", out var values));
107110
}

dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAITextToImageTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public sealed class OpenAITextToImageTests
2222
.Build();
2323

2424
[Theory(Skip = "This test is for manual verification.")]
25-
[InlineData("dall-e-2", 512, 512)]
26-
[InlineData("dall-e-3", 1024, 1024)]
25+
[InlineData("gpt-image-1", 1024, 1024)]
2726
public async Task OpenAITextToImageByModelTestAsync(string modelId, int width, int height)
2827
{
2928
// Arrange
@@ -45,7 +44,7 @@ public async Task OpenAITextToImageByModelTestAsync(string modelId, int width, i
4544
}
4645

4746
[Fact(Skip = "Failing in integration tests pipeline with - HTTP 400 (invalid_request_error: billing_hard_limit_reached) error.")]
48-
public async Task OpenAITextToImageUseDallE2ByDefaultAsync()
47+
public async Task OpenAITextToImageUseDefaultModelAsync()
4948
{
5049
// Arrange
5150
OpenAIConfiguration? openAIConfiguration = this._configuration.GetSection("OpenAITextToImage").Get<OpenAIConfiguration>();
@@ -58,22 +57,22 @@ public async Task OpenAITextToImageUseDallE2ByDefaultAsync()
5857
var service = kernel.GetRequiredService<ITextToImageService>();
5958

6059
// Act
61-
var result = await service.GenerateImageAsync("The sun rises in the east and sets in the west.", 256, 256);
60+
var result = await service.GenerateImageAsync("The sun rises in the east and sets in the west.", 1024, 1024);
6261

6362
// Assert
6463
Assert.NotNull(result);
6564
Assert.NotEmpty(result);
6665
}
6766

6867
[Fact(Skip = "Failing in integration tests pipeline with - HTTP 400 (invalid_request_error: billing_hard_limit_reached) error.")]
69-
public async Task OpenAITextToImageDalle3GetImagesTestAsync()
68+
public async Task OpenAITextToImageGetImagesTestAsync()
7069
{
7170
// Arrange
7271
OpenAIConfiguration? openAIConfiguration = this._configuration.GetSection("OpenAITextToImage").Get<OpenAIConfiguration>();
7372
Assert.NotNull(openAIConfiguration);
7473

7574
var kernel = Kernel.CreateBuilder()
76-
.AddOpenAITextToImage(apiKey: openAIConfiguration.ApiKey, modelId: "dall-e-3")
75+
.AddOpenAITextToImage(apiKey: openAIConfiguration.ApiKey, modelId: "gpt-image-1")
7776
.Build();
7877

7978
var service = kernel.GetRequiredService<ITextToImageService>();
@@ -84,6 +83,7 @@ public async Task OpenAITextToImageDalle3GetImagesTestAsync()
8483
// Assert
8584
Assert.NotNull(result);
8685
Assert.NotEmpty(result);
87-
Assert.NotEmpty(result[0].Uri!.ToString());
86+
var imageContent = result[0];
87+
Assert.True(imageContent.Uri is not null || imageContent.Data is not null, "Image content should have either a URI or binary data.");
8888
}
8989
}

dotnet/src/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</ItemGroup>
3131
<ItemGroup>
3232
<PackageReference Include="AWSSDK.SecurityToken" />
33+
<PackageReference Include="Microsoft.Bcl.Memory" />
3334
<PackageReference Include="Microsoft.Net.Compilers.Toolset" />
3435
<PackageReference Include="Azure.Identity" />
3536
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />

dotnet/src/IntegrationTests/testsettings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
"Endpoint": ""
5454
},
5555
"OpenAITextToImage": {
56-
"ServiceId": "dall-e-2",
57-
"ModelId": "dall-e-2",
56+
"ServiceId": "gpt-image-1",
57+
"ModelId": "gpt-image-1",
5858
"ApiKey": ""
5959
},
6060
"AzureOpenAITextToImage": {
61-
"ServiceId": "azure-dalle3",
62-
"DeploymentName": "Dalle3",
61+
"ServiceId": "azure-gpt-image-1",
62+
"DeploymentName": "gpt-image-1",
6363
"Endpoint": ""
6464
},
6565
"HuggingFace": {

0 commit comments

Comments
 (0)