Skip to content

Commit 3bdb9bb

Browse files
author
PHAN Xuan Quang
committed
ok
1 parent db7bbfc commit 3bdb9bb

37 files changed

+835
-22
lines changed

Gemini.NET.sln

-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ VisualStudioVersion = 17.12.35527.113
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gemini.NET", "Gemini.NET\Gemini.NET.csproj", "{02C0663E-6E10-48AB-B1D1-973BC58F0CC9}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{DFFFB8C2-414E-4FAD-B3B7-188433F03091}"
9-
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commons", "Commons\Commons.csproj", "{14CC73F1-3F0F-4B8F-BA74-7A3D6CCA012D}"
11-
EndProject
128
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example APIs", "Example APIs\Example APIs.csproj", "{E41574CD-BFC4-4A72-913D-D9E11EC075AD}"
139
EndProject
1410
Global
@@ -21,14 +17,6 @@ Global
2117
{02C0663E-6E10-48AB-B1D1-973BC58F0CC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
2218
{02C0663E-6E10-48AB-B1D1-973BC58F0CC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
2319
{02C0663E-6E10-48AB-B1D1-973BC58F0CC9}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{DFFFB8C2-414E-4FAD-B3B7-188433F03091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{DFFFB8C2-414E-4FAD-B3B7-188433F03091}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{DFFFB8C2-414E-4FAD-B3B7-188433F03091}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{DFFFB8C2-414E-4FAD-B3B7-188433F03091}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{14CC73F1-3F0F-4B8F-BA74-7A3D6CCA012D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{14CC73F1-3F0F-4B8F-BA74-7A3D6CCA012D}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{14CC73F1-3F0F-4B8F-BA74-7A3D6CCA012D}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{14CC73F1-3F0F-4B8F-BA74-7A3D6CCA012D}.Release|Any CPU.Build.0 = Release|Any CPU
3220
{E41574CD-BFC4-4A72-913D-D9E11EC075AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3321
{E41574CD-BFC4-4A72-913D-D9E11EC075AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
3422
{E41574CD-BFC4-4A72-913D-D9E11EC075AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Models.Shared;
2+
using Models.Shared;
3+
using Newtonsoft.Json;
4+
5+
namespace Models.Request
6+
{
7+
/// <summary>
8+
/// Represents a request to the Gemini API for generating content or performing tasks.
9+
/// </summary>
10+
public class ApiRequest
11+
{
12+
/// <summary>
13+
/// The list of content parts that form the input to the model.
14+
/// This includes the user's message and any additional content like images.
15+
/// </summary>
16+
[JsonProperty("contents")]
17+
public List<Content> Contents { get; set; }
18+
19+
/// <summary>
20+
/// The configuration for the generation process.
21+
/// This includes parameters like temperature, top-k, and maximum output tokens.
22+
/// </summary>
23+
[JsonProperty("generationConfig")]
24+
public GenerationConfig GenerationConfig { get; set; }
25+
26+
/// <summary>
27+
/// The system instructions that guide the model's behavior.
28+
/// This is optional and can be used to set specific context or constraints.
29+
/// </summary>
30+
[JsonProperty("systemInstruction")]
31+
public SystemInstruction? SystemInstruction { get; set; }
32+
33+
/// <summary>
34+
/// (Optional) The list of tools available to the model.
35+
/// Tools can include features like web search or function calling capabilities.
36+
/// This is optional and depends on the model's capabilities.
37+
/// </summary>
38+
[JsonProperty("tools")]
39+
public List<Tool>? Tools { get; set; }
40+
41+
/// <summary>
42+
/// The safety settings for content generation.
43+
/// These settings control the model's behavior regarding potentially harmful content.
44+
/// This is optional and uses default safety settings if not specified.
45+
/// </summary>
46+
[JsonProperty("safetySettings")]
47+
public List<SafetySetting>? SafetySettings { get; set; }
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Models.Enums;
2+
using Helpers;
3+
using Newtonsoft.Json;
4+
5+
namespace Models.Request
6+
{
7+
/// <summary>
8+
/// Represents a safety configuration that controls content filtering for specific harm categories.
9+
/// Safety settings allow fine-grained control over the model's content generation
10+
/// to prevent potentially harmful or inappropriate content.
11+
/// </summary>
12+
public class SafetySetting
13+
{
14+
/// <summary>
15+
/// The harm category to apply safety settings to.
16+
/// This is a required field that specifies which type of content to filter (e.g., hate speech, harassment).
17+
/// The value should correspond to a SafetySettingHarmCategory enum value.
18+
/// </summary>
19+
[JsonProperty("category")]
20+
public required string Category { get; set; }
21+
22+
/// <summary>
23+
/// The threshold level for content filtering in this category.
24+
/// Determines how strictly to filter content, from BLOCK_NONE to BLOCK_ALL.
25+
/// Default value is BLOCK_NONE, allowing all content in this category.
26+
/// </summary>
27+
[JsonProperty("threshold")]
28+
public string Threshold { get; set; } = EnumHelper.GetDescription(SafetySettingHarmThreshold.BlockNone);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Request
4+
{
5+
public class DynamicRetrievalConfig
6+
{
7+
[JsonProperty("mode")]
8+
public required string Mode { get; set; } = "MODE_DYNAMIC";
9+
10+
[JsonProperty("dynamic_threshold")]
11+
public required float DynamicThreshold { get; set; } = 0.3F;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Models.Shared
2+
{
3+
/// <summary>
4+
/// Represents configuration for the Google Search tool.
5+
/// This class serves as a marker for enabling Google Search capabilities in the model.
6+
/// When included in the tools configuration, it allows the model to perform web searches.
7+
/// </summary>
8+
public class GoogleSearch
9+
{
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Request
4+
{
5+
public class GoogleSearchRetrieval
6+
{
7+
[JsonProperty("dynamic_retrieval_config")]
8+
public required DynamicRetrievalConfig DynamicRetrievalConfig { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Helpers;
2+
using Newtonsoft.Json;
3+
4+
namespace Models.Request
5+
{
6+
/// <summary>
7+
/// Represents configuration parameters for controlling the model's text generation behavior.
8+
/// Contains settings that affect the creativity, diversity, and length of generated content.
9+
/// </summary>
10+
public class GenerationConfig
11+
{
12+
/// <summary>
13+
/// The sampling temperature.
14+
/// Controls the randomness of the output. Higher values (e.g., 0.8) make the output more random,
15+
/// while lower values (e.g., 0.2) make it more focused and deterministic.
16+
/// Default value is 1.0.
17+
/// </summary>
18+
[JsonProperty("temperature")]
19+
public float Temperature { get; set; } = 1;
20+
21+
/// <summary>
22+
/// The top-k sampling parameter.
23+
/// Limits the cumulative probability of tokens considered for generation to the k most likely ones.
24+
/// Higher values allow more diverse word choices.
25+
/// Default value is 40.
26+
/// </summary>
27+
[JsonProperty("topK")]
28+
public sbyte TopK { get; set; } = 40;
29+
30+
/// <summary>
31+
/// The nucleus sampling parameter.
32+
/// Limits the cumulative probability of tokens considered for generation.
33+
/// Higher values (e.g., 0.95) allow more diverse word choices.
34+
/// Default value is 0.95.
35+
/// </summary>
36+
[JsonProperty("topP")]
37+
public float TopP { get; set; } = 0.95F;
38+
39+
/// <summary>
40+
/// The maximum number of tokens in the generated output.
41+
/// Limits the length of the model's response.
42+
/// Default value is 8192.
43+
/// </summary>
44+
[JsonProperty("maxOutputTokens")]
45+
public int MaxOutputTokens { get; set; } = 8192;
46+
47+
/// <summary>
48+
/// The MIME type of the expected response.
49+
/// Determines the format of the generated content (e.g., text/plain, text/markdown).
50+
/// Default value is text/plain.
51+
/// </summary>
52+
[JsonProperty("responseMimeType")]
53+
public string ResponseMimeType { get; set; } = EnumHelper.GetDescription(Enums.ResponseMimeType.PlainText);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Models.Shared;
2+
using Helpers;
3+
using Newtonsoft.Json;
4+
5+
namespace Models.Request
6+
{
7+
/// <summary>
8+
/// Represents system-level instructions that guide the model's behavior.
9+
/// System instructions can be used to set context, define roles, or establish constraints
10+
/// for the model's responses.
11+
/// </summary>
12+
public class SystemInstruction
13+
{
14+
/// <summary>
15+
/// The role for this instruction (e.g., user, assistant).
16+
/// Default value is "user".
17+
/// </summary>
18+
[JsonProperty("role")]
19+
public string Role { get; set; } = EnumHelper.GetDescription(Enums.Role.User);
20+
21+
/// <summary>
22+
/// The list of content parts that make up the system instruction.
23+
/// This is a required field and must contain at least one part.
24+
/// </summary>
25+
[JsonProperty("parts")]
26+
public required List<Part> Parts { get; set; }
27+
}
28+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Shared
4+
{
5+
/// <summary>
6+
/// Represents a tool that extends the model's capabilities.
7+
/// Tools provide additional functionality like web search that the model can use during generation.
8+
/// </summary>
9+
public class Tool
10+
{
11+
/// <summary>
12+
/// The Google Search tool configuration.
13+
/// When configured, allows the model to perform web searches during content generation.
14+
/// </summary>
15+
[JsonProperty("googleSearch")]
16+
public GoogleSearch? GoogleSearch { get; set; } = new GoogleSearch();
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Failed
4+
{
5+
public class ApiResponse
6+
{
7+
[JsonProperty("error")]
8+
public Error Error { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Failed
4+
{
5+
public class Detail
6+
{
7+
[JsonProperty("@type")]
8+
public string Type;
9+
10+
[JsonProperty("fieldViolations")]
11+
public List<FieldViolation> FieldViolations;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Failed
4+
{
5+
public class Error
6+
{
7+
[JsonProperty("code")]
8+
public int? Code { get; set; }
9+
10+
[JsonProperty("message")]
11+
public string Message { get; set; }
12+
13+
[JsonProperty("status")]
14+
public string Status { get; set; }
15+
16+
[JsonProperty("details")]
17+
public List<Detail>? Details { get; set; }
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Failed
4+
{
5+
public class FieldViolation
6+
{
7+
[JsonProperty("field")]
8+
public string Field;
9+
10+
[JsonProperty("description")]
11+
public string Description;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Success
4+
{
5+
public class ApiResponse
6+
{
7+
[JsonProperty("candidates")]
8+
public List<Candidate>? Candidates { get; set; }
9+
10+
[JsonProperty("usageMetadata")]
11+
public UsageMetadata? UsageMetadata { get; set; }
12+
13+
[JsonProperty("modelVersion")]
14+
public string? ModelVersion { get; set; }
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Models.Shared;
2+
using Newtonsoft.Json;
3+
4+
namespace Models.Response.Success
5+
{
6+
public class Candidate
7+
{
8+
[JsonProperty("content")]
9+
public Content? Content { get; set; }
10+
11+
[JsonProperty("finishReason")]
12+
public string? FinishReason { get; set; }
13+
14+
[JsonProperty("index")]
15+
public int? Index { get; set; }
16+
17+
[JsonProperty("groundingMetadata")]
18+
public GroundingMetadata? GroundingMetadata { get; set; }
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Success
4+
{
5+
public class GroundingChunk
6+
{
7+
[JsonProperty("web")]
8+
public Web Web { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Success
4+
{
5+
public class GroundingSupport
6+
{
7+
[JsonProperty("segment")]
8+
public Segment Segment { get; set; }
9+
10+
[JsonProperty("groundingChunkIndices")]
11+
public List<int?> GroundingChunkIndices { get; set; }
12+
13+
[JsonProperty("confidenceScores")]
14+
public List<double?> ConfidenceScores { get; set; }
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Success
4+
{
5+
public class RetrievalMetadata
6+
{
7+
[JsonProperty("googleSearchDynamicRetrievalScore")]
8+
public double? GoogleSearchDynamicRetrievalScore { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Models.Response.Success
4+
{
5+
public class SearchEntryPoint
6+
{
7+
[JsonProperty("renderedContent")]
8+
public string RenderedContent { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)