Skip to content

Commit 43967ed

Browse files
committed
google: gemini-3.1-flash-image-preview
1 parent 1bcb5c9 commit 43967ed

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

src/LlmTornado/Chat/Models/Google/ChatModelGoogle.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public override bool OwnsModel(string model)
9696
ChatModelGoogleGeminiPreview.ModelGemini3ProImagePreview,
9797
ChatModelGoogleGeminiPreview.ModelGemini3FlashPreview,
9898
ChatModelGoogleGeminiPreview.ModelGemini31ProPreview,
99-
ChatModelGoogleGeminiPreview.ModelGemini31ProPreviewCustomtools
99+
ChatModelGoogleGeminiPreview.ModelGemini31ProPreviewCustomtools,
100+
ChatModelGoogleGeminiPreview.ModelGemini31FlashImagePreview
100101
];
101102

102103
/// <summary>
@@ -113,7 +114,8 @@ public override bool OwnsModel(string model)
113114
/// </summary>
114115
public static readonly HashSet<IModel> Gemini31Models = [
115116
ChatModelGoogleGeminiPreview.ModelGemini31ProPreview,
116-
ChatModelGoogleGeminiPreview.ModelGemini31ProPreviewCustomtools
117+
ChatModelGoogleGeminiPreview.ModelGemini31ProPreviewCustomtools,
118+
ChatModelGoogleGeminiPreview.ModelGemini31FlashImagePreview
117119
];
118120

119121
/// <summary>
@@ -143,7 +145,7 @@ public override bool OwnsModel(string model)
143145
/// </summary>
144146
public static List<IModel> ImageModalitySupportingModelsList => LazyImageModalitySupportingModels.Value;
145147

146-
private static readonly Lazy<List<IModel>> LazyImageModalitySupportingModels = new Lazy<List<IModel>>(() => [ChatModelGoogleGeminiExperimental.ModelGemini2FlashImageGeneration, ChatModelGoogleGeminiPreview.ModelGemini2FlashPreviewImageGeneration, ChatModelGoogleGeminiPreview.ModelGemini25FlashImagePreview, ChatModelGoogleGeminiPreview.ModelGemini3ProImagePreview]);
148+
private static readonly Lazy<List<IModel>> LazyImageModalitySupportingModels = new Lazy<List<IModel>>(() => [ChatModelGoogleGeminiExperimental.ModelGemini2FlashImageGeneration, ChatModelGoogleGeminiPreview.ModelGemini2FlashPreviewImageGeneration, ChatModelGoogleGeminiPreview.ModelGemini25FlashImagePreview, ChatModelGoogleGeminiPreview.ModelGemini3ProImagePreview, ChatModelGoogleGeminiPreview.ModelGemini31FlashImagePreview]);
147149

148150
/// <summary>
149151
/// Models listed don't support system prompt.

src/LlmTornado/Chat/Models/Google/ChatModelGoogleGeminiPreview.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public class ChatModelGoogleGeminiPreview : IVendorModelClassProvider
6767
/// </summary>
6868
public readonly ChatModel Gemini3ProImagePreview = ModelGemini3ProImagePreview;
6969

70+
/// <summary>
71+
/// Gemini 3.1 Flash Image Preview delivers high-quality, photorealistic imagery at Flash speed.
72+
/// Features subject consistency (up to 5 characters), object fidelity (up to 14 objects),
73+
/// precise instruction following, and production-ready output from 512px to 4K.
74+
/// </summary>
75+
public static readonly ChatModel ModelGemini31FlashImagePreview = new ChatModel("gemini-3.1-flash-image-preview", LLmProviders.Google, 1_048_576);
76+
77+
/// <summary>
78+
/// <inheritdoc cref="ModelGemini31FlashImagePreview"/>
79+
/// </summary>
80+
public readonly ChatModel Gemini31FlashImagePreview = ModelGemini31FlashImagePreview;
81+
7082
/// <summary>
7183
/// Gemini 2.5 Computer Use Preview model enables building browser control agents that interact with and automate tasks using screenshots and UI actions like mouse clicks and keyboard inputs.
7284
/// </summary>
@@ -220,7 +232,7 @@ public class ChatModelGoogleGeminiPreview : IVendorModelClassProvider
220232
public static List<IModel> ModelsAll => LazyModelsAll.Value;
221233

222234
private static readonly Lazy<List<IModel>> LazyModelsAll = new Lazy<List<IModel>>(() => [
223-
ModelGemini3FlashPreview, ModelGemini3ProPreview, ModelGemini3ProImagePreview,
235+
ModelGemini3FlashPreview, ModelGemini3ProPreview, ModelGemini3ProImagePreview, ModelGemini31FlashImagePreview,
224236
ModelGemini31ProPreview, ModelGemini31ProPreviewCustomtools,
225237
ModelGemini25ComputerUsePreview102025, ModelGemini25ProPreview0325, ModelGemini25ProPreview0506, ModelGemini25ProPreview0605, ModelGemini25FlashPreview0417,
226238
ModelGemini25FlashPreview0520, ModelGemini2FlashPreviewImageGeneration, ModelGemini25FlashPreviewTts, ModelGemini25ProPreviewTts,

src/LlmTornado/Chat/Vendors/Google/VendorGoogleChatRequest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ internal class VendorGoogleChatRequestGenerationConfig
8181
[JsonProperty("topK")]
8282
public int? TopK { get; set; }
8383

84+
/// <summary>
85+
/// Optional. Seed used in decoding. If not set, the request uses a randomly generated seed.
86+
/// </summary>
87+
[JsonProperty("seed")]
88+
public int? Seed { get; set; }
89+
8490
/// <summary>
8591
/// Optional. Presence penalty applied to the next token's logprobs if the token has already been seen in the response. This penalty is binary on/off and not dependant on the number of times the token is used (after the first). Use frequencyPenalty for a penalty that increases with each use. A positive penalty will discourage the use of tokens that have already been used in the response, increasing the vocabulary.
8692
/// </summary>
@@ -1449,7 +1455,10 @@ public VendorGoogleChatRequest(ChatRequest request, IEndpointProvider provider)
14491455
MaxOutputTokens = request.MaxTokens,
14501456
StopSequences = request.MultipleStopSequences is not null ? request.MultipleStopSequences.Take(5).ToList() : request.StopSequence is not null ? [ request.StopSequence ] : null,
14511457
ResponseLogprobs = request.Logprobs,
1452-
Logprobs = request.TopLogprobs
1458+
Logprobs = request.TopLogprobs,
1459+
Seed = request.Seed,
1460+
PresencePenalty = request.PresencePenalty,
1461+
FrequencyPenalty = request.FrequencyPenalty
14531462
};
14541463

14551464
// thinkingConfig is not supported for non-thinking models
@@ -1542,6 +1551,7 @@ public VendorGoogleChatRequest(ChatRequest request, IEndpointProvider provider)
15421551
{
15431552
GenerationConfig.ImageConfig.ImageSize = request.ImageOutput.Resolution switch
15441553
{
1554+
ChatImageResolutions.Resolution512 => "512",
15451555
ChatImageResolutions.Resolution1K => "1K",
15461556
ChatImageResolutions.Resolution2K => "2K",
15471557
ChatImageResolutions.Resolution4K => "4K",

src/LlmTornado/Code/PartialModels.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,18 @@ internal class ChatMessageFinishReasonsConverter : JsonConverter<ChatMessageFini
336336
{ "spii", ChatMessageFinishReasons.SensitivePersonalInformation },
337337
{ "malformed_function_call", ChatMessageFinishReasons.MalformedToolCall },
338338
{ "image_safety", ChatMessageFinishReasons.ImageSafety },
339+
{ "image_prohibited_content", ChatMessageFinishReasons.ImageProhibitedContent },
340+
{ "image_other", ChatMessageFinishReasons.ImageOther },
341+
{ "no_image", ChatMessageFinishReasons.NoImage },
342+
{ "image_recitation", ChatMessageFinishReasons.ImageRecitation },
339343
{ "error", ChatMessageFinishReasons.Error },
344+
{ "other", ChatMessageFinishReasons.Error },
340345

341346
{ "tool_use", ChatMessageFinishReasons.ToolCalls },
342347
{ "tool_calls", ChatMessageFinishReasons.ToolCalls },
343348
{ "function_call", ChatMessageFinishReasons.ToolCalls },
349+
{ "unexpected_tool_call", ChatMessageFinishReasons.UnexpectedToolCall },
350+
{ "too_many_tool_calls", ChatMessageFinishReasons.TooManyToolCalls },
344351

345352
{ "model_context_window_exceeded", ChatMessageFinishReasons.ContextWindowExceeded },
346353

@@ -445,6 +452,36 @@ public enum ChatMessageFinishReasons
445452
/// </summary>
446453
ImageSafety,
447454

455+
/// <summary>
456+
/// Image generation stopped because generated images contain prohibited content.
457+
/// </summary>
458+
ImageProhibitedContent,
459+
460+
/// <summary>
461+
/// Image generation stopped due to a miscellaneous issue.
462+
/// </summary>
463+
ImageOther,
464+
465+
/// <summary>
466+
/// The model was expected to generate an image but none was produced.
467+
/// </summary>
468+
NoImage,
469+
470+
/// <summary>
471+
/// Image generation stopped due to recitation.
472+
/// </summary>
473+
ImageRecitation,
474+
475+
/// <summary>
476+
/// The model generated a tool call but no tools were enabled in the request.
477+
/// </summary>
478+
UnexpectedToolCall,
479+
480+
/// <summary>
481+
/// The model called too many tools consecutively, causing the system to exit execution.
482+
/// </summary>
483+
TooManyToolCalls,
484+
448485
/// <summary>
449486
/// The request was canceled/aborted.
450487
/// </summary>
@@ -1237,6 +1274,11 @@ public enum ChatImageAspectRatios
12371274
[JsonConverter(typeof(StringEnumConverter))]
12381275
public enum ChatImageResolutions
12391276
{
1277+
/// <summary>
1278+
/// 512px resolution (smallest, lowest cost per image).
1279+
/// </summary>
1280+
[EnumMember(Value = "512")]
1281+
Resolution512,
12401282
/// <summary>
12411283
/// 1K resolution (default for most models).
12421284
/// </summary>

0 commit comments

Comments
 (0)