Skip to content

Commit 8e05d2a

Browse files
author
PHAN Xuan Quang
committed
update package
1 parent a63ead6 commit 8e05d2a

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

Gemini.NET/API Models/API Request/ApiRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ApiRequest
2020
/// This includes parameters like temperature, top-k, and maximum output tokens.
2121
/// </summary>
2222
[JsonProperty("generationConfig")]
23-
public GenerationConfig GenerationConfig { get; set; }
23+
public GenerationConfig? GenerationConfig { get; set; }
2424

2525
/// <summary>
2626
/// The system instructions that guide the model's behavior.

Gemini.NET/API Models/API Request/GenerationConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GenerationConfig
4242
/// Default value is 8192.
4343
/// </summary>
4444
[JsonProperty("maxOutputTokens")]
45-
public int MaxOutputTokens { get; set; } = 8192;
45+
public int? MaxOutputTokens { get; set; }
4646

4747
/// <summary>
4848
/// The MIME type of the expected response.

Gemini.NET/ApiRequestBuilder.cs

+19-21
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class ApiRequestBuilder
1717
private string? _systemInstruction;
1818
private GenerationConfig? _config;
1919
private bool _useGrounding = false;
20-
private List<SafetySetting>? _safetySettings;
20+
private IEnumerable<SafetySetting>? _safetySettings;
2121
private List<Content>? _chatHistory;
22-
private List<ImageData>? _images;
22+
private IEnumerable<ImageData>? _images;
2323

2424
/// <summary>
2525
/// Sets the system instruction for the API request.
@@ -70,7 +70,7 @@ public ApiRequestBuilder EnableGrounding()
7070
/// </summary>
7171
/// <param name="safetySettings">The list of safety settings to set.</param>
7272
/// <returns>The current instance of <see cref="ApiRequestBuilder"/>.</returns>
73-
public ApiRequestBuilder WithSafetySettings(List<SafetySetting> safetySettings)
73+
public ApiRequestBuilder WithSafetySettings(IEnumerable<SafetySetting> safetySettings)
7474
{
7575
_safetySettings = safetySettings;
7676
return this;
@@ -82,8 +82,8 @@ public ApiRequestBuilder WithSafetySettings(List<SafetySetting> safetySettings)
8282
/// <returns>The current instance of <see cref="ApiRequestBuilder"/>.</returns>
8383
public ApiRequestBuilder DisableAllSafetySettings()
8484
{
85-
_safetySettings = new List<SafetySetting>
86-
{
85+
_safetySettings =
86+
[
8787
new SafetySetting
8888
{
8989
Category = EnumHelper.GetDescription(SafetySettingHarmCategory.DangerousContent),
@@ -104,7 +104,7 @@ public ApiRequestBuilder DisableAllSafetySettings()
104104
{
105105
Category = EnumHelper.GetDescription(SafetySettingHarmCategory.SexuallyExplicit),
106106
},
107-
};
107+
];
108108

109109
return this;
110110
}
@@ -155,9 +155,9 @@ public ApiRequestBuilder WithPrompt(string prompt)
155155
/// <param name="chatMessages"></param>
156156
/// <returns></returns>
157157
/// <exception cref="ArgumentNullException"></exception>
158-
public ApiRequestBuilder WithChatHistory(List<ChatMessage> chatMessages)
158+
public ApiRequestBuilder WithChatHistory(IEnumerable<ChatMessage> chatMessages)
159159
{
160-
if (chatMessages == null || chatMessages.Count == 0)
160+
if (chatMessages == null || !chatMessages.Any())
161161
{
162162
throw new ArgumentNullException(nameof(chatMessages), "Chat history can't be null or empty.");
163163
}
@@ -183,9 +183,9 @@ public ApiRequestBuilder WithChatHistory(List<ChatMessage> chatMessages)
183183
/// Sets the Base64 images for the API request.
184184
/// </summary>
185185
/// <returns></returns>
186-
public ApiRequestBuilder WithBase64Images(List<string> images)
186+
public ApiRequestBuilder WithBase64Images(IEnumerable<string> images)
187187
{
188-
_images = images.Select(ImageHelper.AsImageData).ToList();
188+
_images = images.Select(ImageHelper.AsImageData);
189189
return this;
190190
}
191191

@@ -201,11 +201,9 @@ public ApiRequest Build()
201201
throw new ArgumentNullException(nameof(_prompt), "Prompt can't be an empty string.");
202202
}
203203

204-
var contents = _chatHistory == null
205-
? new List<Content>()
206-
: _chatHistory;
204+
var contents = _chatHistory ?? [];
207205

208-
if (_images != null)
206+
if (_images != null && _images.Any())
209207
{
210208
contents.Add(new Content
211209
{
@@ -239,27 +237,27 @@ public ApiRequest Build()
239237
{
240238
Contents = contents,
241239
GenerationConfig = _config,
242-
SafetySettings = _safetySettings,
240+
SafetySettings = _safetySettings?.ToList(),
243241
Tools = _useGrounding
244-
? new List<Tool>
245-
{
242+
?
243+
[
246244
new Tool
247245
{
248246
GoogleSearch = new GoogleSearch()
249247
}
250-
}
248+
]
251249
: null,
252250
SystemInstruction = string.IsNullOrEmpty(_systemInstruction)
253251
? null
254252
: new SystemInstruction
255253
{
256-
Parts = new List<Part>
257-
{
254+
Parts =
255+
[
258256
new Part
259257
{
260258
Text = _systemInstruction
261259
}
262-
}
260+
]
263261
}
264262
};
265263
}

0 commit comments

Comments
 (0)