@@ -15,7 +15,8 @@ namespace xAI;
1515/// </summary>
1616sealed class GrokImageGenerator : IImageGenerator
1717{
18- const string DefaultContentType = "image/png" ;
18+ const string DefaultInputContentType = "image/png" ;
19+ const string DefaultOutputContentType = "image/jpeg" ;
1920
2021 readonly ImageGeneratorMetadata metadata ;
2122 readonly ImageClient imageClient ;
@@ -61,9 +62,7 @@ public async Task<ImageGenerationResponse> GenerateAsync(
6162
6263 // Set the number of images to generate
6364 if ( options ? . Count is { } count )
64- {
6565 protocolRequest . N = count ;
66- }
6766
6867 // Set the response format (URL or base64)
6968 if ( options ? . ResponseFormat is { } responseFormat )
@@ -85,10 +84,8 @@ public async Task<ImageGenerationResponse> GenerateAsync(
8584 // Convert the data content to a base64 string or URL for the API
8685 var imageUrl = dataContent . Uri ? . ToString ( ) ;
8786 if ( imageUrl == null && dataContent . Data . Length > 0 )
88- {
8987 // Convert to base64 if we have raw data
90- imageUrl = $ "data:{ dataContent . MediaType ?? DefaultContentType } ;base64,{ Convert . ToBase64String ( dataContent . Data . ToArray ( ) ) } ";
91- }
88+ imageUrl = $ "data:{ dataContent . MediaType ?? DefaultInputContentType } ;base64,{ Convert . ToBase64String ( dataContent . Data . ToArray ( ) ) } ";
9289
9390 if ( imageUrl != null )
9491 {
@@ -131,10 +128,10 @@ void IDisposable.Dispose()
131128 /// <summary>
132129 /// Converts an xAI <see cref="ImageResponse"/> to a <see cref="ImageGenerationResponse"/>.
133130 /// </summary>
134- private static ImageGenerationResponse ToImageGenerationResponse ( ImageResponse response , string ? mediaType )
131+ static ImageGenerationResponse ToImageGenerationResponse ( ImageResponse response , string ? mediaType )
135132 {
136133 var contents = new List < AIContent > ( ) ;
137- var contentType = mediaType ?? "image/jpeg" ; // xAI returns JPG by default
134+ var contentType = mediaType ?? DefaultOutputContentType ; // xAI returns JPG by default
138135
139136 foreach ( var image in response . Images )
140137 {
0 commit comments