Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ public OpenAITextToImageServiceTests()
this._mockLoggerFactory = new Mock<ILoggerFactory>();
}

[Fact]
public void ConstructorWorksCorrectly()
[Theory]
[InlineData(null, "gpt-image-2")]
[InlineData("model", "model")]
public void ConstructorWorksCorrectly(string? modelId, string expectedModelId)
{
// Arrange & Act
var sut = new OpenAITextToImageService("apiKey", "organization", "model");
var sut = new OpenAITextToImageService("apiKey", "organization", modelId);

// Assert
Assert.NotNull(sut);
Assert.Equal("organization", sut.Attributes[ClientCore.OrganizationKey]);
Assert.Equal("model", sut.Attributes[AIServiceExtensions.ModelIdKey]);
Assert.Equal(expectedModelId, sut.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ internal async Task<string> GenerateImageAsync(
};

// 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.
// 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.
targetModel = string.IsNullOrEmpty(targetModel) ? "gpt-image-1" : targetModel!;
// However, considering that the model is required by the OpenAI SDK and the ModelId property is optional, it defaults to gpt-image-2 in the line below.
targetModel = string.IsNullOrEmpty(targetModel) ? "gpt-image-2" : targetModel!;

ClientResult<GeneratedImage> response = await RunRequestAsync(() => this.Client!.GetImageClient(targetModel).GenerateImageAsync(prompt, imageOptions, cancellationToken)).ConfigureAwait(false);
var generatedImage = response.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public OpenAITextToImageService(
HttpClient? httpClient = null,
ILoggerFactory? loggerFactory = null)
{
this._client = new(modelId ?? "gpt-image-1", apiKey, organization, null, httpClient, loggerFactory?.CreateLogger(this.GetType()));
this._client = new(modelId ?? "gpt-image-2", apiKey, organization, null, httpClient, loggerFactory?.CreateLogger(this.GetType()));
}

/// <inheritdoc/>
Expand Down
Loading