├── src
├── GeminiDotnet
│ ├── V1
│ │ ├── API_REVISION
│ │ ├── TunedModels
│ │ │ └── CancelOperationRequest.cs
│ │ ├── Operation.cs
│ │ ├── BatchGenerateContentOperation.cs
│ │ ├── AsyncBatchEmbedContentOperation.cs
│ │ ├── Empty.cs
│ │ ├── GroundingChunk.cs
│ │ ├── AsyncBatchEmbedContentRequest.cs
│ │ ├── BatchGenerateContentRequest.cs
│ │ ├── UrlContextMetadata.cs
│ │ ├── Batches
│ │ │ ├── InlinedRequests.cs
│ │ │ ├── InlinedEmbedContentRequests.cs
│ │ │ ├── InlinedResponses.cs
│ │ │ ├── InlinedEmbedContentResponses.cs
│ │ │ ├── InlinedRequest.cs
│ │ │ ├── InputConfiguration.cs
│ │ │ ├── InlinedEmbedContentRequest.cs
│ │ │ ├── InputEmbedContentConfiguration.cs
│ │ │ ├── InlinedResponse.cs
│ │ │ └── InlinedEmbedContentResponse.cs
│ │ ├── TopCandidates.cs
│ │ ├── CitationMetadata.cs
│ │ ├── Models
│ │ │ ├── EmbedContentResponse.cs
│ │ │ ├── BatchEmbedContentsRequest.cs
│ │ │ ├── BatchEmbedContentsResponse.cs
│ │ │ ├── ModalityTokenCount.cs
│ │ │ ├── ContentEmbedding.cs
│ │ │ ├── ListModelsResponse.cs
│ │ │ ├── GenerativeLanguageModality.cs
│ │ │ ├── Blob.cs
│ │ │ ├── VideoMetadata.cs
│ │ │ ├── Content.cs
│ │ │ └── CountTokensResponse.cs
│ │ ├── AsyncBatchEmbedContentResponse.cs
│ │ ├── BatchGenerateContentResponse.cs
│ │ ├── Web.cs
│ │ ├── UrlMetadata.cs
│ │ ├── SafetySetting.cs
│ │ ├── SearchEntryPoint.cs
│ │ ├── CorporaClient.cs
│ │ ├── GeneratedFilesClient.cs
│ │ ├── RetrievalMetadata.cs
│ │ ├── PromptFeedback.cs
│ │ ├── ICorporaClient.cs
│ │ ├── LogprobsResultCandidate.cs
│ │ ├── IGeneratedFilesClient.cs
│ │ ├── GeminiV1Client.cs
│ │ ├── LogprobsResult.cs
│ │ ├── SafetyRatingProbability.cs
│ │ ├── SafetyRating.cs
│ │ ├── OperationsClient.cs
│ │ ├── UrlMetadataUrlRetrievalStatus.cs
│ │ ├── TuningSnapshot.cs
│ │ └── ListOperationsResponse.cs
│ ├── V1Beta
│ │ ├── API_REVISION
│ │ ├── Files
│ │ │ ├── DownloadFileResponse.cs
│ │ │ ├── CreateFileResponse.cs
│ │ │ ├── CreateFileRequest.cs
│ │ │ ├── VideoFileMetadata.cs
│ │ │ ├── ListFilesResponse.cs
│ │ │ ├── FileSource.cs
│ │ │ └── FileState.cs
│ │ ├── CachedContents
│ │ │ ├── UrlContext.cs
│ │ │ ├── CodeExecution.cs
│ │ │ ├── CachedContentUsageMetadata.cs
│ │ │ ├── GoogleSearchRetrieval.cs
│ │ │ ├── ComputerUseEnvironment.cs
│ │ │ ├── GoogleSearch.cs
│ │ │ ├── DynamicRetrievalConfigMode.cs
│ │ │ ├── GoogleMaps.cs
│ │ │ ├── RetrievalConfiguration.cs
│ │ │ ├── DynamicRetrievalConfiguration.cs
│ │ │ ├── ListCachedContentsResponse.cs
│ │ │ ├── ToolConfiguration.cs
│ │ │ ├── LatLng.cs
│ │ │ ├── ComputerUse.cs
│ │ │ ├── FunctionDeclarationBehavior.cs
│ │ │ ├── FunctionCallingConfiguration.cs
│ │ │ ├── FileSearch.cs
│ │ │ ├── Interval.cs
│ │ │ └── Type.cs
│ │ ├── FileSearchStores
│ │ │ ├── ImportFileMetadata.cs
│ │ │ ├── UploadToFileSearchStoreMetadata.cs
│ │ │ ├── ImportFileOperation.cs
│ │ │ ├── UploadToFileSearchStoreOperation.cs
│ │ │ ├── StringList.cs
│ │ │ ├── ChunkingConfiguration.cs
│ │ │ ├── ListFileSearchStoresResponse.cs
│ │ │ ├── ListDocumentsResponse.cs
│ │ │ ├── DocumentState.cs
│ │ │ ├── ImportFileResponse.cs
│ │ │ ├── CustomMetadata.cs
│ │ │ └── ImportFileRequest.cs
│ │ ├── TunedModels
│ │ │ ├── TransferOwnershipResponse.cs
│ │ │ ├── CreateTunedModelOperation.cs
│ │ │ ├── Dataset.cs
│ │ │ ├── TransferOwnershipRequest.cs
│ │ │ ├── TuningExamples.cs
│ │ │ ├── TuningExample.cs
│ │ │ ├── ListTunedModelsResponse.cs
│ │ │ ├── TunedModelState.cs
│ │ │ ├── TunedModelSource.cs
│ │ │ └── TuningSnapshot.cs
│ │ ├── Models
│ │ │ ├── PredictLongRunningMetadata.cs
│ │ │ ├── PredictLongRunningOperation.cs
│ │ │ ├── TextPrompt.cs
│ │ │ ├── Embedding.cs
│ │ │ ├── GroundingPassages.cs
│ │ │ ├── Media.cs
│ │ │ ├── EmbedTextResponse.cs
│ │ │ ├── UrlContextMetadata.cs
│ │ │ ├── BatchEmbedTextResponse.cs
│ │ │ ├── PredictResponse.cs
│ │ │ ├── TopCandidates.cs
│ │ │ ├── CitationMetadata.cs
│ │ │ ├── EmbedContentResponse.cs
│ │ │ ├── PredictLongRunningResponse.cs
│ │ │ ├── CountMessageTokensRequest.cs
│ │ │ ├── CountTextTokensRequest.cs
│ │ │ ├── BatchEmbedContentsRequest.cs
│ │ │ ├── BatchEmbedContentsResponse.cs
│ │ │ ├── CountTextTokensResponse.cs
│ │ │ ├── CountMessageTokensResponse.cs
│ │ │ ├── Web.cs
│ │ │ ├── Video.cs
│ │ │ ├── EmbedTextRequest.cs
│ │ │ ├── Example.cs
│ │ │ ├── UrlMetadata.cs
│ │ │ ├── ModalityTokenCount.cs
│ │ │ ├── GroundingPassage.cs
│ │ │ ├── PredictRequest.cs
│ │ │ ├── SafetySetting.cs
│ │ │ ├── SearchEntryPoint.cs
│ │ │ ├── PredictLongRunningRequest.cs
│ │ │ ├── GroundingAttribution.cs
│ │ │ ├── ContentFilterReason.cs
│ │ │ ├── AttributionSourceId.cs
│ │ │ ├── ContentEmbedding.cs
│ │ │ ├── ListModelsResponse.cs
│ │ │ ├── RetrievalMetadata.cs
│ │ │ ├── ContentFilter.cs
│ │ │ ├── InputFeedbackBlockReason.cs
│ │ │ ├── GroundingPassageId.cs
│ │ │ ├── BatchEmbedTextRequest.cs
│ │ │ ├── PlaceAnswerSources.cs
│ │ │ ├── InputFeedback.cs
│ │ │ ├── LogprobsResultCandidate.cs
│ │ │ ├── Condition.cs
│ │ │ ├── GroundingChunk.cs
│ │ │ ├── GenerativeLanguageModality.cs
│ │ │ ├── ReviewSnippet.cs
│ │ │ ├── MetadataFilter.cs
│ │ │ ├── GenerateAnswerRequestAnswerStyle.cs
│ │ │ ├── PredictLongRunningGeneratedVideoResponse.cs
│ │ │ ├── SemanticRetrieverChunk.cs
│ │ │ ├── LogprobsResult.cs
│ │ │ ├── SafetyRatingProbability.cs
│ │ │ ├── SafetyRating.cs
│ │ │ └── UrlMetadataUrlRetrievalStatus.cs
│ │ ├── Operation.cs
│ │ ├── AsyncBatchEmbedContentOperation.cs
│ │ ├── BatchGenerateContentOperation.cs
│ │ ├── MediaResolution.cs
│ │ ├── Empty.cs
│ │ ├── BatchGenerateContentRequest.cs
│ │ ├── AsyncBatchEmbedContentRequest.cs
│ │ ├── PrebuiltVoiceConfiguration.cs
│ │ ├── MultiSpeakerVoiceConfiguration.cs
│ │ ├── Batches
│ │ │ ├── InlinedRequests.cs
│ │ │ ├── InlinedEmbedContentRequests.cs
│ │ │ ├── InlinedResponses.cs
│ │ │ ├── InlinedEmbedContentResponses.cs
│ │ │ ├── InlinedRequest.cs
│ │ │ ├── InputConfiguration.cs
│ │ │ ├── InlinedEmbedContentRequest.cs
│ │ │ ├── InputEmbedContentConfiguration.cs
│ │ │ ├── InlinedResponse.cs
│ │ │ └── InlinedEmbedContentResponse.cs
│ │ ├── VoiceConfiguration.cs
│ │ ├── BatchGenerateContentResponse.cs
│ │ ├── AsyncBatchEmbedContentResponse.cs
│ │ ├── FileData.cs
│ │ ├── ExecutableCodeLanguage.cs
│ │ ├── SpeakerVoiceConfiguration.cs
│ │ ├── ListPermissionsResponse.cs
│ │ ├── GeneratedFiles
│ │ │ ├── ListGeneratedFilesResponse.cs
│ │ │ └── GeneratedFileState.cs
│ │ ├── ExecutableCode.cs
│ │ ├── PermissionRole.cs
│ │ ├── CodeExecutionResult.cs
│ │ ├── Corpora
│ │ │ └── ListCorporaResponse.cs
│ │ ├── FunctionResponsePart.cs
│ │ ├── ResponseModality.cs
│ │ ├── PromptFeedback.cs
│ │ ├── PermissionGranteeType.cs
│ │ ├── Blob.cs
│ │ ├── GenerationConfigMediaResolution.cs
│ │ ├── ImageConfiguration.cs
│ │ ├── VideoMetadata.cs
│ │ ├── SafetyFeedback.cs
│ │ ├── CodeExecutionResultOutcome.cs
│ │ ├── MediaResolutionLevel.cs
│ │ ├── FunctionResponseBlob.cs
│ │ ├── Content.cs
│ │ ├── GeminiV1BetaClient.cs
│ │ └── ThinkingConfigThinkingLevel.cs
│ ├── Properties
│ │ └── Assembly.cs
│ ├── ChatRole.cs
│ ├── IGeminiClient.cs
│ ├── ErrorResponse.cs
│ ├── Text
│ │ └── Json
│ │ │ └── JsonSerializerContextExtensions.cs
│ ├── GeminiClientOptions.cs
│ ├── IGeminiApiOptions.cs
│ ├── ErrorDetails.cs
│ ├── IGeminiRequester.cs
│ ├── GeminiClientException.cs
│ └── GeminiDotnet.csproj
├── GeminiDotnet.Extensions.AI
│ ├── Properties
│ │ └── Assembly.cs
│ ├── GeminiAdditionalProperties.cs
│ ├── AdditionalPropertiesDictionaryExtensions.cs
│ ├── Contents
│ │ ├── CodeExecutionContent.cs
│ │ ├── ExecutableCodeContent.cs
│ │ └── CodeExecutionStatus.cs
│ ├── JsonContext.cs
│ ├── GeminiMappingException.cs
│ ├── GeminiClientExtensions.cs
│ └── GeminiDotnet.Extensions.AI.csproj
├── GeminiDotnet.Testing
│ ├── GeminiDotnet.Testing.csproj
│ ├── TestConfiguration.cs
│ └── IntegrationTestAttribute.cs
└── Directory.Build.Props
├── tests
├── GeminiDotnet.Tests
│ ├── xunit.runner.json
│ ├── GeminiDotnet.Tests.csproj
│ └── ErrorResponseTests.cs
├── GeminiDotnet.Extensions.AI.Tests
│ ├── xunit.runner.json
│ └── GeminiEmbeddingGeneratorTests.cs
├── GeminiDotnet.Extensions.AI.Tests.Integration
│ └── xunit.runner.json
└── GeminiDotnet.Extensions.AI.Examples
│ ├── StreamingExample.cs
│ ├── GeminiDotnet.Extensions.AI.Examples.csproj
│ ├── YouTubeExample.cs
│ └── LoggingExample.cs
├── Directory.Build.props
├── .github
└── workflows
│ └── ci.yml
├── Directory.Packages.props
└── LICENCE
/src/GeminiDotnet/V1/API_REVISION:
--------------------------------------------------------------------------------
1 | 20251217
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/API_REVISION:
--------------------------------------------------------------------------------
1 | 20251217
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
3 | }
4 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/Properties/Assembly.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("GeminiDotnet.Tests")]
4 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
3 | }
4 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Tests.Integration/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json"
3 | }
4 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/Properties/Assembly.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("GeminiDotnet.Extensions.AI.Tests")]
4 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/ChatRole.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet;
2 |
3 | public static class ChatRoles
4 | {
5 | public const string User = "user";
6 |
7 | public const string Model = "model";
8 | }
9 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Testing/GeminiDotnet.Testing.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/DownloadFileResponse.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.Files;
2 |
3 | ///
4 | /// Response for DownloadFile.
5 | ///
6 | public sealed record DownloadFileResponse
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/UrlContext.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.CachedContents;
2 |
3 | ///
4 | /// Tool to support URL context retrieval.
5 | ///
6 | public sealed record UrlContext
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/TunedModels/CancelOperationRequest.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1.TunedModels;
2 |
3 | ///
4 | /// The request message for Operations.CancelOperation.
5 | ///
6 | public sealed record CancelOperationRequest
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ImportFileMetadata.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.FileSearchStores;
2 |
3 | ///
4 | /// Metadata for LongRunning ImportFile Operations.
5 | ///
6 | public sealed record ImportFileMetadata
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TransferOwnershipResponse.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.TunedModels;
2 |
3 | ///
4 | /// Response from TransferOwnership.
5 | ///
6 | public sealed record TransferOwnershipResponse
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictLongRunningMetadata.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.Models;
2 |
3 | ///
4 | /// Metadata for PredictLongRunning long running operations.
5 | ///
6 | public sealed record PredictLongRunningMetadata
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Operation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | ///
4 | /// This resource represents a long-running operation that is the result of a
5 | /// network API call.
6 | ///
7 | public sealed record Operation : BaseOperation
8 | {
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Operation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta;
2 |
3 | ///
4 | /// This resource represents a long-running operation that is the result of a
5 | /// network API call.
6 | ///
7 | public sealed record Operation : BaseOperation
8 | {
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/UploadToFileSearchStoreMetadata.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.FileSearchStores;
2 |
3 | ///
4 | /// Metadata for LongRunning UploadToFileSearchStore Operations.
5 | ///
6 | public sealed record UploadToFileSearchStoreMetadata
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/BatchGenerateContentOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record BatchGenerateContentOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/AsyncBatchEmbedContentOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record AsyncBatchEmbedContentOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/AsyncBatchEmbedContentOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record AsyncBatchEmbedContentOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/BatchGenerateContentOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record BatchGenerateContentOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/Directory.Build.Props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | nullable
6 | true
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ImportFileOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.FileSearchStores;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record ImportFileOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictLongRunningOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.Models;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record PredictLongRunningOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/CreateTunedModelOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.TunedModels;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record CreateTunedModelOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0;net9.0;net10.0
4 | enable
5 | enable
6 | 14
7 | preview
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/IGeminiClient.cs:
--------------------------------------------------------------------------------
1 | using GeminiDotnet.V1;
2 | using GeminiDotnet.V1Beta;
3 |
4 | namespace GeminiDotnet;
5 |
6 | public interface IGeminiClient
7 | {
8 | IGeminiClientOptions Options { get; }
9 |
10 | public Uri? Endpoint { get; }
11 |
12 | public IGeminiV1Client V1 { get; }
13 |
14 | public IGeminiV1BetaClient V1Beta { get; }
15 | }
16 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/UploadToFileSearchStoreOperation.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.FileSearchStores;
2 |
3 | ///
4 | /// This resource represents a long-running operation where metadata and response fields are strongly typed.
5 | ///
6 | public sealed record UploadToFileSearchStoreOperation : BaseOperation
7 | {
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/GeminiAdditionalProperties.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.Extensions.AI;
2 |
3 | public static class GeminiAdditionalProperties
4 | {
5 | public const string ThinkingConfiguration = "thinkingConfig";
6 |
7 | public const string ResponseModalities = "responseModalities";
8 |
9 | public const string ImageConfiguration = "imageConfig";
10 | }
11 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/ErrorResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet;
4 |
5 | ///
6 | /// An error response from the Gemini API.
7 | ///
8 | public sealed record ErrorResponse
9 | {
10 | ///
11 | /// The error details.
12 | ///
13 | [JsonPropertyName("error")]
14 | public required ErrorDetails Error { get; init; }
15 | }
16 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/MediaResolution.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Media resolution for the input media.
7 | ///
8 | public sealed record MediaResolution
9 | {
10 | [JsonPropertyName("level")]
11 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
12 | public MediaResolutionLevel? Level { get; init; }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/Text/Json/JsonSerializerContextExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using System.Text.Json.Serialization.Metadata;
3 |
4 | namespace GeminiDotnet.Text.Json;
5 |
6 | internal static class JsonSerializerContextExtensions
7 | {
8 | public static JsonTypeInfo GetTypeInfo(this JsonSerializerContext context)
9 | {
10 | return (JsonTypeInfo)context.GetTypeInfo(typeof(T))!;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Testing/TestConfiguration.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.Testing;
2 |
3 | public static class TestConfiguration
4 | {
5 | private const string VariableName = "GEMINI_DOTNET_API_KEY";
6 |
7 | public static string GetApiKey()
8 | {
9 | return Environment.GetEnvironmentVariable(VariableName)
10 | ?? throw new InvalidOperationException($"Environment variable '{VariableName}' is not set.");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/CodeExecution.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta.CachedContents;
2 |
3 | ///
4 | /// Tool that executes code generated by the model, and automatically returns
5 | /// the result to the model.
6 | /// See also and which are only generated
7 | /// when using this tool.
8 | ///
9 | public sealed record CodeExecution
10 | {
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Empty.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | ///
4 | /// A generic empty message that you can re-use to avoid defining duplicated
5 | /// empty messages in your APIs. A typical example is to use it as the request
6 | /// or the response type of an API method. For instance:
7 | /// service Foo {
8 | /// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
9 | /// }
10 | ///
11 | public sealed record Empty
12 | {
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/GroundingChunk.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Grounding chunk.
7 | ///
8 | public sealed record GroundingChunk
9 | {
10 | ///
11 | /// Grounding chunk from the web.
12 | ///
13 | [JsonPropertyName("web")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Web? Web { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/GeminiClientOptions.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet;
2 |
3 | public sealed record GeminiClientOptions : IGeminiClientOptions
4 | {
5 | public required string ApiKey { get; set; }
6 |
7 | ///
8 | /// The model id to use unless overridden in by the caller.
9 | ///
10 | public string? ModelId { get; set; }
11 |
12 | public Uri? Endpoint { get; set; } = new Uri("https://generativelanguage.googleapis.com", UriKind.Absolute);
13 | }
14 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Empty.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta;
2 |
3 | ///
4 | /// A generic empty message that you can re-use to avoid defining duplicated
5 | /// empty messages in your APIs. A typical example is to use it as the request
6 | /// or the response type of an API method. For instance:
7 | /// service Foo {
8 | /// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
9 | /// }
10 | ///
11 | public sealed record Empty
12 | {
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/AdditionalPropertiesDictionaryExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 |
3 | namespace GeminiDotnet.Extensions.AI;
4 |
5 | internal static class AdditionalPropertiesDictionaryExtensions
6 | {
7 | public static T? GetValueOrDefault(
8 | this AdditionalPropertiesDictionary dictionary,
9 | string key)
10 | {
11 | return dictionary.TryGetValue(key, out var obj) && obj is T t
12 | ? t
13 | : default;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/CreateFileResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Response for CreateFile.
7 | ///
8 | public sealed record CreateFileResponse
9 | {
10 | ///
11 | /// Metadata for the created file.
12 | ///
13 | [JsonPropertyName("file")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public File? File { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/TextPrompt.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Text given to the model as a prompt.
7 | /// The Model will use this TextPrompt to Generate a text completion.
8 | ///
9 | public sealed record TextPrompt
10 | {
11 | ///
12 | /// Required. The prompt text.
13 | ///
14 | [JsonPropertyName("text")]
15 | public required string Text { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Embedding.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A list of floats representing the embedding.
7 | ///
8 | public sealed record Embedding
9 | {
10 | ///
11 | /// The embedding values.
12 | ///
13 | [JsonPropertyName("value")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public ReadOnlyMemory Value { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/AsyncBatchEmbedContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1.Batches;
3 |
4 | namespace GeminiDotnet.V1;
5 |
6 | ///
7 | /// Request for an AsyncBatchEmbedContent operation.
8 | ///
9 | public sealed record AsyncBatchEmbedContentRequest
10 | {
11 | ///
12 | /// Required. The batch to create.
13 | ///
14 | [JsonPropertyName("batch")]
15 | public required EmbedContentBatch Batch { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/BatchGenerateContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1.Batches;
3 |
4 | namespace GeminiDotnet.V1;
5 |
6 | ///
7 | /// Request for a BatchGenerateContent operation.
8 | ///
9 | public sealed record BatchGenerateContentRequest
10 | {
11 | ///
12 | /// Required. The batch to create.
13 | ///
14 | [JsonPropertyName("batch")]
15 | public required GenerateContentBatch Batch { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/CreateFileRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Request for CreateFile.
7 | ///
8 | public sealed record CreateFileRequest
9 | {
10 | ///
11 | /// Optional. Metadata for the file to create.
12 | ///
13 | [JsonPropertyName("file")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public File? File { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/IGeminiApiOptions.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet;
2 |
3 | ///
4 | /// A public view over the options for configuring a .
5 | ///
6 | public interface IGeminiClientOptions
7 | {
8 | ///
9 | /// The model id to use unless overridden in by the caller.
10 | ///
11 | public string? ModelId { get; }
12 |
13 | ///
14 | /// The endpoint to use for the Gemini API.
15 | ///
16 | public Uri? Endpoint { get; }
17 | }
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/BatchGenerateContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Batches;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// Request for a BatchGenerateContent operation.
8 | ///
9 | public sealed record BatchGenerateContentRequest
10 | {
11 | ///
12 | /// Required. The batch to create.
13 | ///
14 | [JsonPropertyName("batch")]
15 | public required GenerateContentBatch Batch { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GroundingPassages.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A repeated list of passages.
7 | ///
8 | public sealed record GroundingPassages
9 | {
10 | ///
11 | /// List of passages.
12 | ///
13 | [JsonPropertyName("passages")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Passages { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/UrlContextMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Metadata related to url context retrieval tool.
7 | ///
8 | public sealed record UrlContextMetadata
9 | {
10 | ///
11 | /// List of url context.
12 | ///
13 | [JsonPropertyName("urlMetadata")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? UrlMetadata { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/AsyncBatchEmbedContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Batches;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// Request for an AsyncBatchEmbedContent operation.
8 | ///
9 | public sealed record AsyncBatchEmbedContentRequest
10 | {
11 | ///
12 | /// Required. The batch to create.
13 | ///
14 | [JsonPropertyName("batch")]
15 | public required EmbedContentBatch Batch { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Media.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A proto encapsulate various type of media.
7 | ///
8 | public sealed record Media
9 | {
10 | ///
11 | /// Video as the only one for now. This is mimicking Vertex proto.
12 | ///
13 | [JsonPropertyName("video")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Video? Video { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/VideoFileMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Metadata for a video .
7 | ///
8 | public sealed record VideoFileMetadata
9 | {
10 | ///
11 | /// Duration of the video.
12 | ///
13 | [JsonPropertyName("videoDuration")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? VideoDuration { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/PrebuiltVoiceConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// The configuration for the prebuilt speaker to use.
7 | ///
8 | public sealed record PrebuiltVoiceConfiguration
9 | {
10 | ///
11 | /// The name of the preset voice to use.
12 | ///
13 | [JsonPropertyName("voiceName")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? VoiceName { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/Dataset.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Dataset for training or validation.
7 | ///
8 | public sealed record Dataset
9 | {
10 | ///
11 | /// Optional. Inline examples with simple input/output text.
12 | ///
13 | [JsonPropertyName("examples")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public TuningExamples? Examples { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/EmbedTextResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// The response to a EmbedTextRequest.
7 | ///
8 | public sealed record EmbedTextResponse
9 | {
10 | ///
11 | /// Output only. The embedding generated from the input text.
12 | ///
13 | [JsonPropertyName("embedding")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Embedding? Embedding { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/UrlContextMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Metadata related to url context retrieval tool.
7 | ///
8 | public sealed record UrlContextMetadata
9 | {
10 | ///
11 | /// List of url context.
12 | ///
13 | [JsonPropertyName("urlMetadata")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? UrlMetadata { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/MultiSpeakerVoiceConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// The configuration for the multi-speaker setup.
7 | ///
8 | public sealed record MultiSpeakerVoiceConfiguration
9 | {
10 | ///
11 | /// Required. All the enabled speaker voices.
12 | ///
13 | [JsonPropertyName("speakerVoiceConfigs")]
14 | public required IReadOnlyList SpeakerVoiceConfigurations { get; init; }
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedRequests.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// The requests to be processed in the batch if provided as part of the
7 | /// batch creation request.
8 | ///
9 | public sealed record InlinedRequests
10 | {
11 | ///
12 | /// Required. The requests to be processed in the batch.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Testing/IntegrationTestAttribute.cs:
--------------------------------------------------------------------------------
1 | using Xunit.v3;
2 |
3 | namespace GeminiDotnet.Testing;
4 |
5 | ///
6 | /// Used to mark tests which interact with the Gemini API.
7 | ///
8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
9 | public sealed class IntegrationTestAttribute : Attribute, ITraitAttribute
10 | {
11 | public IReadOnlyCollection> GetTraits()
12 | {
13 | return [new KeyValuePair("Category", "Integration")];
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/TopCandidates.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Candidates with top log probabilities at each decoding step.
7 | ///
8 | public sealed record TopCandidates
9 | {
10 | ///
11 | /// Sorted by log probability in descending order.
12 | ///
13 | [JsonPropertyName("candidates")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Candidates { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedRequests.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// The requests to be processed in the batch if provided as part of the
7 | /// batch creation request.
8 | ///
9 | public sealed record InlinedRequests
10 | {
11 | ///
12 | /// Required. The requests to be processed in the batch.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/CitationMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// A collection of source attributions for a piece of content.
7 | ///
8 | public sealed record CitationMetadata
9 | {
10 | ///
11 | /// Citations to sources for a specific response.
12 | ///
13 | [JsonPropertyName("citationSources")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? CitationSources { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/StringList.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// User provided string values assigned to a single metadata key.
7 | ///
8 | public sealed record StringList
9 | {
10 | ///
11 | /// The string values of the metadata to store.
12 | ///
13 | [JsonPropertyName("values")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Values { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TransferOwnershipRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Request to transfer the ownership of the tuned model.
7 | ///
8 | public sealed record TransferOwnershipRequest
9 | {
10 | ///
11 | /// Required. The email address of the user to whom the tuned model is being transferred
12 | /// to.
13 | ///
14 | [JsonPropertyName("emailAddress")]
15 | public required string EmailAddress { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/BatchEmbedTextResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// The response to a EmbedTextRequest.
7 | ///
8 | public sealed record BatchEmbedTextResponse
9 | {
10 | ///
11 | /// Output only. The embeddings generated from the input text.
12 | ///
13 | [JsonPropertyName("embeddings")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Embeddings { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/VoiceConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// The configuration for the voice to use.
7 | ///
8 | public sealed record VoiceConfiguration
9 | {
10 | ///
11 | /// The configuration for the prebuilt voice to use.
12 | ///
13 | [JsonPropertyName("prebuiltVoiceConfig")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public PrebuiltVoiceConfiguration? PrebuiltVoiceConfiguration { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/ErrorDetails.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Text.Json;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace GeminiDotnet;
6 |
7 | public sealed record ErrorDetails
8 | {
9 | [JsonPropertyName("code")]
10 | public required HttpStatusCode StatusCode { get; init; }
11 |
12 | [JsonPropertyName("message")]
13 | public required string Message { get; init; }
14 |
15 | [JsonPropertyName("status")]
16 | public required string Status { get; init; }
17 |
18 | [JsonPropertyName("details")]
19 | public JsonElement Details { get; init; }
20 | }
21 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedEmbedContentRequests.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// The requests to be processed in the batch if provided as part of the
7 | /// batch creation request.
8 | ///
9 | public sealed record InlinedEmbedContentRequests
10 | {
11 | ///
12 | /// Required. The requests to be processed in the batch.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedResponses.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// The responses to the requests in the batch.
7 | ///
8 | public sealed record InlinedResponses
9 | {
10 | ///
11 | /// Output only. The responses to the requests in the batch.
12 | ///
13 | [JsonPropertyName("inlinedResponses")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? InlinedResponsesValue { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/EmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// The response to an .
7 | ///
8 | public sealed record EmbedContentResponse
9 | {
10 | ///
11 | /// Output only. The embedding generated from the input content.
12 | ///
13 | [JsonPropertyName("embedding")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public ContentEmbedding? Embedding { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1Beta.Models;
5 |
6 | ///
7 | /// Response message for [PredictionService.Predict].
8 | ///
9 | public sealed record PredictResponse
10 | {
11 | ///
12 | /// The outputs of the prediction call.
13 | ///
14 | [JsonPropertyName("predictions")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public ReadOnlyMemory Predictions { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/TopCandidates.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Candidates with top log probabilities at each decoding step.
7 | ///
8 | public sealed record TopCandidates
9 | {
10 | ///
11 | /// Sorted by log probability in descending order.
12 | ///
13 | [JsonPropertyName("candidates")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Candidates { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/CitationMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A collection of source attributions for a piece of content.
7 | ///
8 | public sealed record CitationMetadata
9 | {
10 | ///
11 | /// Citations to sources for a specific response.
12 | ///
13 | [JsonPropertyName("citationSources")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? CitationSources { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedEmbedContentRequests.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// The requests to be processed in the batch if provided as part of the
7 | /// batch creation request.
8 | ///
9 | public sealed record InlinedEmbedContentRequests
10 | {
11 | ///
12 | /// Required. The requests to be processed in the batch.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedResponses.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// The responses to the requests in the batch.
7 | ///
8 | public sealed record InlinedResponses
9 | {
10 | ///
11 | /// Output only. The responses to the requests in the batch.
12 | ///
13 | [JsonPropertyName("inlinedResponses")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? InlinedResponsesValue { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/CachedContentUsageMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Metadata on the usage of the cached content.
7 | ///
8 | public sealed record CachedContentUsageMetadata
9 | {
10 | ///
11 | /// Total number of tokens that the cached content consumes.
12 | ///
13 | [JsonPropertyName("totalTokenCount")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public int? TotalTokenCount { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/EmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// The response to an .
7 | ///
8 | public sealed record EmbedContentResponse
9 | {
10 | ///
11 | /// Output only. The embedding generated from the input content.
12 | ///
13 | [JsonPropertyName("embedding")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public ContentEmbedding? Embedding { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/Contents/CodeExecutionContent.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 |
3 | namespace GeminiDotnet.Extensions.AI.Contents;
4 |
5 | ///
6 | /// Represents the result of a service-side code execution.
7 | ///
8 | public sealed class CodeExecutionContent : AIContent
9 | {
10 | ///
11 | /// The output of the code execution.
12 | ///
13 | public string? Output { get; init; }
14 |
15 | ///
16 | /// The status of the code execution.
17 | ///
18 | public CodeExecutionStatus Status { get; init; }
19 | }
20 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/AsyncBatchEmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1.Batches;
3 |
4 | namespace GeminiDotnet.V1;
5 |
6 | ///
7 | /// Response for a BatchGenerateContent operation.
8 | ///
9 | public sealed record AsyncBatchEmbedContentResponse
10 | {
11 | ///
12 | /// Output only. The output of the batch request.
13 | ///
14 | [JsonPropertyName("output")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public EmbedContentBatchOutput? Output { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/BatchGenerateContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1.Batches;
3 |
4 | namespace GeminiDotnet.V1;
5 |
6 | ///
7 | /// Response for a BatchGenerateContent operation.
8 | ///
9 | public sealed record BatchGenerateContentResponse
10 | {
11 | ///
12 | /// Output only. The output of the batch request.
13 | ///
14 | [JsonPropertyName("output")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public GenerateContentBatchOutput? Output { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/BatchGenerateContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Batches;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// Response for a BatchGenerateContent operation.
8 | ///
9 | public sealed record BatchGenerateContentResponse
10 | {
11 | ///
12 | /// Output only. The output of the batch request.
13 | ///
14 | [JsonPropertyName("output")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public GenerateContentBatchOutput? Output { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedEmbedContentResponses.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// The responses to the requests in the batch.
7 | ///
8 | public sealed record InlinedEmbedContentResponses
9 | {
10 | ///
11 | /// Output only. The responses to the requests in the batch.
12 | ///
13 | [JsonPropertyName("inlinedResponses")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? InlinedResponses { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/AsyncBatchEmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Batches;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// Response for a BatchGenerateContent operation.
8 | ///
9 | public sealed record AsyncBatchEmbedContentResponse
10 | {
11 | ///
12 | /// Output only. The output of the batch request.
13 | ///
14 | [JsonPropertyName("output")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public EmbedContentBatchOutput? Output { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedEmbedContentResponses.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// The responses to the requests in the batch.
7 | ///
8 | public sealed record InlinedEmbedContentResponses
9 | {
10 | ///
11 | /// Output only. The responses to the requests in the batch.
12 | ///
13 | [JsonPropertyName("inlinedResponses")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? InlinedResponses { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictLongRunningResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Response message for [PredictionService.PredictLongRunning]
7 | ///
8 | public sealed record PredictLongRunningResponse
9 | {
10 | ///
11 | /// The response of the video generation prediction.
12 | ///
13 | [JsonPropertyName("generateVideoResponse")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public PredictLongRunningGeneratedVideoResponse? GenerateVideoResponse { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/Contents/ExecutableCodeContent.cs:
--------------------------------------------------------------------------------
1 | using GeminiDotnet.V1Beta;
2 | using Microsoft.Extensions.AI;
3 |
4 | namespace GeminiDotnet.Extensions.AI.Contents;
5 |
6 | ///
7 | /// Represents service-side executable code content.
8 | ///
9 | public sealed class ExecutableCodeContent : AIContent
10 | {
11 | ///
12 | /// The language of the code.
13 | ///
14 | public required ExecutableCodeLanguage Language { get; set; }
15 |
16 | ///
17 | /// The code the model will execute.
18 | ///
19 | public required string Code { get; set; }
20 | }
21 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/CountMessageTokensRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Counts the number of tokens in the sent to a model.
7 | /// Models may tokenize text differently, so each model may return a different
8 | /// token_count.
9 | ///
10 | public sealed record CountMessageTokensRequest
11 | {
12 | ///
13 | /// Required. The prompt, whose token count is to be returned.
14 | ///
15 | [JsonPropertyName("prompt")]
16 | public required MessagePrompt Prompt { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/CountTextTokensRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Counts the number of tokens in the sent to a model.
7 | /// Models may tokenize text differently, so each model may return a different
8 | /// token_count.
9 | ///
10 | public sealed record CountTextTokensRequest
11 | {
12 | ///
13 | /// Required. The free-form input text given to the model as a prompt.
14 | ///
15 | [JsonPropertyName("prompt")]
16 | public required TextPrompt Prompt { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/BatchEmbedContentsRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// Batch request to get embeddings from the model for a list of prompts.
7 | ///
8 | public sealed record BatchEmbedContentsRequest
9 | {
10 | ///
11 | /// Required. Embed requests for the batch. The model in each of these requests must
12 | /// match the model specified BatchEmbedContentsRequest.model.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/BatchEmbedContentsRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Batch request to get embeddings from the model for a list of prompts.
7 | ///
8 | public sealed record BatchEmbedContentsRequest
9 | {
10 | ///
11 | /// Required. Embed requests for the batch. The model in each of these requests must
12 | /// match the model specified BatchEmbedContentsRequest.model.
13 | ///
14 | [JsonPropertyName("requests")]
15 | public required IReadOnlyList Requests { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TuningExamples.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// A set of tuning examples. Can be training or validation data.
7 | ///
8 | public sealed record TuningExamples
9 | {
10 | ///
11 | /// The examples. Example input can be for text or discuss, but all examples
12 | /// in a set must be of the same type.
13 | ///
14 | [JsonPropertyName("examples")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? Examples { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/BatchEmbedContentsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// The response to a .
7 | ///
8 | public sealed record BatchEmbedContentsResponse
9 | {
10 | ///
11 | /// Output only. The embeddings for each request, in the same order as provided in the batch
12 | /// request.
13 | ///
14 | [JsonPropertyName("embeddings")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? Embeddings { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/GoogleSearchRetrieval.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Tool to retrieve public web data for grounding, powered by Google.
7 | ///
8 | public sealed record GoogleSearchRetrieval
9 | {
10 | ///
11 | /// Specifies the dynamic retrieval configuration for the given source.
12 | ///
13 | [JsonPropertyName("dynamicRetrievalConfig")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public DynamicRetrievalConfiguration? DynamicRetrievalConfiguration { get; init; }
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileData.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// URI based data.
7 | ///
8 | public sealed record FileData
9 | {
10 | ///
11 | /// Required. URI.
12 | ///
13 | [JsonPropertyName("fileUri")]
14 | public required string FileUri { get; init; }
15 |
16 | ///
17 | /// Optional. The IANA standard MIME type of the source data.
18 | ///
19 | [JsonPropertyName("mimeType")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public string? MimeType { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Web.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Chunk from the web.
7 | ///
8 | public sealed record Web
9 | {
10 | ///
11 | /// Title of the chunk.
12 | ///
13 | [JsonPropertyName("title")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? Title { get; init; }
16 |
17 | ///
18 | /// URI reference of the chunk.
19 | ///
20 | [JsonPropertyName("uri")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? Uri { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/BatchEmbedContentsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// The response to a .
7 | ///
8 | public sealed record BatchEmbedContentsResponse
9 | {
10 | ///
11 | /// Output only. The embeddings for each request, in the same order as provided in the batch
12 | /// request.
13 | ///
14 | [JsonPropertyName("embeddings")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? Embeddings { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/CountTextTokensResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A response from CountTextTokens.
7 | /// It returns the model's token_count for the prompt.
8 | ///
9 | public sealed record CountTextTokensResponse
10 | {
11 | ///
12 | /// The number of tokens that the model tokenizes the prompt into.
13 | /// Always non-negative.
14 | ///
15 | [JsonPropertyName("tokenCount")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public int? TokenCount { get; init; }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/JsonContext.cs:
--------------------------------------------------------------------------------
1 | using GeminiDotnet.Extensions.AI.Contents;
2 | using System.Text.Json;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace GeminiDotnet.Extensions.AI;
6 |
7 | [JsonSourceGenerationOptions(
8 | JsonSerializerDefaults.Web,
9 | UseStringEnumConverter = true,
10 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
11 | WriteIndented = true)]
12 | [JsonSerializable(typeof(ExecutableCodeContent))]
13 | [JsonSerializable(typeof(CodeExecutionContent))]
14 | [JsonSerializable(typeof(IDictionary))]
15 | [JsonSerializable(typeof(JsonElement))]
16 | internal sealed partial class JsonContext : JsonSerializerContext;
17 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/CountMessageTokensResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A response from CountMessageTokens.
7 | /// It returns the model's token_count for the prompt.
8 | ///
9 | public sealed record CountMessageTokensResponse
10 | {
11 | ///
12 | /// The number of tokens that the model tokenizes the prompt into.
13 | /// Always non-negative.
14 | ///
15 | [JsonPropertyName("tokenCount")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public int? TokenCount { get; init; }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/ComputerUseEnvironment.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Required. The environment being operated.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum ComputerUseEnvironment
10 | {
11 | ///
12 | /// Defaults to browser.
13 | ///
14 | [JsonStringEnumMemberName("ENVIRONMENT_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Operates in a web browser.
19 | ///
20 | [JsonStringEnumMemberName("ENVIRONMENT_BROWSER")]
21 | Browser,
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Web.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Chunk from the web.
7 | ///
8 | public sealed record Web
9 | {
10 | ///
11 | /// Title of the chunk.
12 | ///
13 | [JsonPropertyName("title")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? Title { get; init; }
16 |
17 | ///
18 | /// URI reference of the chunk.
19 | ///
20 | [JsonPropertyName("uri")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? Uri { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Video.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Representation of a video.
7 | ///
8 | public sealed record Video
9 | {
10 | ///
11 | /// Path to another storage.
12 | ///
13 | [JsonPropertyName("uri")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? Uri { get; init; }
16 |
17 | ///
18 | /// Raw bytes.
19 | ///
20 | [JsonPropertyName("video")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? VideoValue { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TuningExample.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// A single example for tuning.
7 | ///
8 | public sealed record TuningExample
9 | {
10 | ///
11 | /// Required. The expected model output.
12 | ///
13 | [JsonPropertyName("output")]
14 | public required string Output { get; init; }
15 |
16 | ///
17 | /// Optional. Text model input.
18 | ///
19 | [JsonPropertyName("textInput")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public string? TextInput { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/IGeminiRequester.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet;
2 |
3 | internal interface IGeminiRequester
4 | {
5 | Task ExecuteAsync(
6 | HttpMethod method,
7 | string path,
8 | CancellationToken cancellationToken = default);
9 |
10 | Task ExecuteAsync(
11 | HttpMethod method,
12 | string path,
13 | TRequest request,
14 | CancellationToken cancellationToken = default);
15 |
16 | IAsyncEnumerable ExecuteStreamingAsync(
17 | HttpMethod method,
18 | string path,
19 | TRequest request,
20 | CancellationToken cancellationToken = default);
21 | }
22 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/GoogleSearch.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// GoogleSearch tool type.
7 | /// Tool to support Google Search in Model. Powered by Google.
8 | ///
9 | public sealed record GoogleSearch
10 | {
11 | ///
12 | /// Optional. Filter search results to a specific time range.
13 | /// If customers set a start time, they must set an end time (and vice
14 | /// versa).
15 | ///
16 | [JsonPropertyName("timeRangeFilter")]
17 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18 | public Interval? TimeRangeFilter { get; init; }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ChunkingConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Parameters for telling the service how to chunk the file.
7 | /// inspired by
8 | /// google3/cloud/ai/platform/extension/lib/retrieval/config/chunker_config.proto
9 | ///
10 | public sealed record ChunkingConfiguration
11 | {
12 | ///
13 | /// White space chunking configuration.
14 | ///
15 | [JsonPropertyName("whiteSpaceConfig")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public WhiteSpaceConfiguration? WhiteSpaceConfiguration { get; init; }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Examples/StreamingExample.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 |
3 | namespace GeminiDotnet.Extensions.AI.Examples;
4 |
5 | public sealed class StreamingExample
6 | {
7 | public static async Task ExecuteAsync(IChatClient client, CancellationToken cancellationToken)
8 | {
9 | var chatOptions = new ChatOptions();
10 |
11 | IList messages =
12 | [
13 | new(ChatRole.User, "Explain Wittgenstein's Philosophical Investigations")
14 | ];
15 |
16 | await foreach (var update in client.GetStreamingResponseAsync(messages, chatOptions, cancellationToken))
17 | {
18 | Console.Write(update.Text);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Build and Test
2 |
3 | on:
4 | push:
5 | branches: ["main"]
6 | pull_request:
7 | branches: ["main"]
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - uses: actions/checkout@v5
15 |
16 | - name: Setup .NET
17 | uses: actions/setup-dotnet@v5
18 | with:
19 | dotnet-version: |
20 | 10.0.x
21 | 9.0.x
22 | 8.0.x
23 |
24 | - name: Restore dependencies
25 | run: dotnet restore
26 |
27 | - name: Build
28 | run: dotnet build --no-restore
29 |
30 | - name: Test
31 | run: dotnet test --no-build -- --filter-query "/[Category!=Integration]" --ignore-exit-code 8
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/DynamicRetrievalConfigMode.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// The mode of the predictor to be used in dynamic retrieval.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum DynamicRetrievalConfigMode
10 | {
11 | ///
12 | /// Always trigger retrieval.
13 | ///
14 | [JsonStringEnumMemberName("MODE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Run retrieval only when system decides it is necessary.
19 | ///
20 | [JsonStringEnumMemberName("MODE_DYNAMIC")]
21 | Dynamic,
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Examples/GeminiDotnet.Extensions.AI.Examples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | true
6 | true
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ExecutableCodeLanguage.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Required. Programming language of the `code`.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum ExecutableCodeLanguage
10 | {
11 | ///
12 | /// Unspecified language. This value should not be used.
13 | ///
14 | [JsonStringEnumMemberName("LANGUAGE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Python >= 3.10, with numpy and simpy available.
19 | /// Python is the default language.
20 | ///
21 | [JsonStringEnumMemberName("PYTHON")]
22 | Python,
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/GeminiMappingException.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace GeminiDotnet.Extensions.AI;
4 |
5 | ///
6 | /// An exception that is thrown when mapping fails between GeminiDotnet and Microsoft.Extensions.AI types.
7 | ///
8 | public sealed class GeminiMappingException : Exception
9 | {
10 | private GeminiMappingException(string message) : base(message)
11 | {
12 | }
13 |
14 | [DoesNotReturn]
15 | internal static void Throw(string fromPropertyName, string toPropertyName, string reason)
16 | {
17 | var message = $"Mapping from '{fromPropertyName}' to '{toPropertyName}' failed. Reason: {reason}";
18 | throw new GeminiMappingException(message);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/SpeakerVoiceConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// The configuration for a single speaker in a multi speaker setup.
7 | ///
8 | public sealed record SpeakerVoiceConfiguration
9 | {
10 | ///
11 | /// Required. The name of the speaker to use. Should be the same as in the prompt.
12 | ///
13 | [JsonPropertyName("speaker")]
14 | public required string Speaker { get; init; }
15 |
16 | ///
17 | /// Required. The configuration for the voice to use.
18 | ///
19 | [JsonPropertyName("voiceConfig")]
20 | public required VoiceConfiguration VoiceConfiguration { get; init; }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/UrlMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Context of the a single url retrieval.
7 | ///
8 | public sealed record UrlMetadata
9 | {
10 | ///
11 | /// Retrieved url by the tool.
12 | ///
13 | [JsonPropertyName("retrievedUrl")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? RetrievedUrl { get; init; }
16 |
17 | ///
18 | /// Status of the url retrieval.
19 | ///
20 | [JsonPropertyName("urlRetrievalStatus")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public UrlMetadataUrlRetrievalStatus? UrlRetrievalStatus { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/EmbedTextRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Request to get a text embedding from the model.
7 | ///
8 | public sealed record EmbedTextRequest
9 | {
10 | ///
11 | /// Required. The model name to use with the format model=models/{model}.
12 | ///
13 | [JsonPropertyName("model")]
14 | public required string Model { get; init; }
15 |
16 | ///
17 | /// Optional. The free-form input text that the model will turn into an embedding.
18 | ///
19 | [JsonPropertyName("text")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public string? Text { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1.Batches;
5 |
6 | ///
7 | /// The request to be processed in the batch.
8 | ///
9 | public sealed record InlinedRequest
10 | {
11 | ///
12 | /// Optional. The metadata to be associated with the request.
13 | ///
14 | [JsonPropertyName("metadata")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public JsonElement Metadata { get; init; }
17 |
18 | ///
19 | /// Required. The request to be processed in the batch.
20 | ///
21 | [JsonPropertyName("request")]
22 | public required GenerateContentRequest Request { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Example.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// An input/output example used to instruct the Model.
7 | /// It demonstrates how the model should respond or format its response.
8 | ///
9 | public sealed record Example
10 | {
11 | ///
12 | /// Required. An example of an input from the user.
13 | ///
14 | [JsonPropertyName("input")]
15 | public required Message Input { get; init; }
16 |
17 | ///
18 | /// Required. An example of what the model should output given the input.
19 | ///
20 | [JsonPropertyName("output")]
21 | public required Message Output { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1Beta.Batches;
5 |
6 | ///
7 | /// The request to be processed in the batch.
8 | ///
9 | public sealed record InlinedRequest
10 | {
11 | ///
12 | /// Optional. The metadata to be associated with the request.
13 | ///
14 | [JsonPropertyName("metadata")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public JsonElement Metadata { get; init; }
17 |
18 | ///
19 | /// Required. The request to be processed in the batch.
20 | ///
21 | [JsonPropertyName("request")]
22 | public required GenerateContentRequest Request { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/ModalityTokenCount.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// Represents token counting info for a single modality.
7 | ///
8 | public sealed record ModalityTokenCount
9 | {
10 | ///
11 | /// The modality associated with this token count.
12 | ///
13 | [JsonPropertyName("modality")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public GenerativeLanguageModality? Modality { get; init; }
16 |
17 | ///
18 | /// Number of tokens.
19 | ///
20 | [JsonPropertyName("tokenCount")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public int? TokenCount { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/UrlMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Context of the a single url retrieval.
7 | ///
8 | public sealed record UrlMetadata
9 | {
10 | ///
11 | /// Retrieved url by the tool.
12 | ///
13 | [JsonPropertyName("retrievedUrl")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? RetrievedUrl { get; init; }
16 |
17 | ///
18 | /// Status of the url retrieval.
19 | ///
20 | [JsonPropertyName("urlRetrievalStatus")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public UrlMetadataUrlRetrievalStatus? UrlRetrievalStatus { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/SafetySetting.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Safety setting, affecting the safety-blocking behavior.
7 | /// Passing a safety setting for a category changes the allowed probability that
8 | /// content is blocked.
9 | ///
10 | public sealed record SafetySetting
11 | {
12 | ///
13 | /// Required. The category for this setting.
14 | ///
15 | [JsonPropertyName("category")]
16 | public required HarmCategory Category { get; init; }
17 |
18 | ///
19 | /// Required. Controls the probability threshold at which harm is blocked.
20 | ///
21 | [JsonPropertyName("threshold")]
22 | public required SafetySettingThreshold Threshold { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ModalityTokenCount.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Represents token counting info for a single modality.
7 | ///
8 | public sealed record ModalityTokenCount
9 | {
10 | ///
11 | /// The modality associated with this token count.
12 | ///
13 | [JsonPropertyName("modality")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public GenerativeLanguageModality? Modality { get; init; }
16 |
17 | ///
18 | /// Number of tokens.
19 | ///
20 | [JsonPropertyName("tokenCount")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public int? TokenCount { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InputConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// Configures the input to the batch request.
7 | ///
8 | public sealed record InputConfiguration
9 | {
10 | ///
11 | /// The name of the File containing the input requests.
12 | ///
13 | [JsonPropertyName("fileName")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? FileName { get; init; }
16 |
17 | ///
18 | /// The requests to be processed in the batch.
19 | ///
20 | [JsonPropertyName("requests")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public InlinedRequests? Requests { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/GoogleMaps.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// The GoogleMaps Tool that provides geospatial context for the user's query.
7 | ///
8 | public sealed record GoogleMaps
9 | {
10 | ///
11 | /// Optional. Whether to return a widget context token in the GroundingMetadata of the
12 | /// response. Developers can use the widget context token to render a Google
13 | /// Maps widget with geospatial context related to the places that the model
14 | /// references in the response.
15 | ///
16 | [JsonPropertyName("enableWidget")]
17 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18 | public bool? EnableWidget { get; init; }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GroundingPassage.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Passage included inline with a grounding configuration.
7 | ///
8 | public sealed record GroundingPassage
9 | {
10 | ///
11 | /// Content of the passage.
12 | ///
13 | [JsonPropertyName("content")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Content? Content { get; init; }
16 |
17 | ///
18 | /// Identifier for the passage for attributing this passage in grounded
19 | /// answers.
20 | ///
21 | [JsonPropertyName("id")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? Id { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/SearchEntryPoint.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Google search entry point.
7 | ///
8 | public sealed record SearchEntryPoint
9 | {
10 | ///
11 | /// Optional. Web content snippet that can be embedded in a web page or an app webview.
12 | ///
13 | [JsonPropertyName("renderedContent")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? RenderedContent { get; init; }
16 |
17 | ///
18 | /// Optional. Base64 encoded JSON representing array of tuple.
19 | ///
20 | [JsonPropertyName("sdkBlob")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? SdkBlob { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1Beta.Models;
5 |
6 | ///
7 | /// Request message for PredictionService.Predict.
8 | ///
9 | public sealed record PredictRequest
10 | {
11 | ///
12 | /// Required. The instances that are the input to the prediction call.
13 | ///
14 | [JsonPropertyName("instances")]
15 | public required ReadOnlyMemory Instances { get; init; }
16 |
17 | ///
18 | /// Optional. The parameters that govern the prediction call.
19 | ///
20 | [JsonPropertyName("parameters")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public JsonElement Parameters { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/SafetySetting.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Safety setting, affecting the safety-blocking behavior.
7 | /// Passing a safety setting for a category changes the allowed probability that
8 | /// content is blocked.
9 | ///
10 | public sealed record SafetySetting
11 | {
12 | ///
13 | /// Required. The category for this setting.
14 | ///
15 | [JsonPropertyName("category")]
16 | public required HarmCategory Category { get; init; }
17 |
18 | ///
19 | /// Required. Controls the probability threshold at which harm is blocked.
20 | ///
21 | [JsonPropertyName("threshold")]
22 | public required SafetySettingThreshold Threshold { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedEmbedContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 | using GeminiDotnet.V1.Models;
4 |
5 | namespace GeminiDotnet.V1.Batches;
6 |
7 | ///
8 | /// The request to be processed in the batch.
9 | ///
10 | public sealed record InlinedEmbedContentRequest
11 | {
12 | ///
13 | /// Optional. The metadata to be associated with the request.
14 | ///
15 | [JsonPropertyName("metadata")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public JsonElement Metadata { get; init; }
18 |
19 | ///
20 | /// Required. The request to be processed in the batch.
21 | ///
22 | [JsonPropertyName("request")]
23 | public required EmbedContentRequest Request { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InputConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// Configures the input to the batch request.
7 | ///
8 | public sealed record InputConfiguration
9 | {
10 | ///
11 | /// The name of the containing the input requests.
12 | ///
13 | [JsonPropertyName("fileName")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? FileName { get; init; }
16 |
17 | ///
18 | /// The requests to be processed in the batch.
19 | ///
20 | [JsonPropertyName("requests")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public InlinedRequests? Requests { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/SearchEntryPoint.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Google search entry point.
7 | ///
8 | public sealed record SearchEntryPoint
9 | {
10 | ///
11 | /// Optional. Web content snippet that can be embedded in a web page or an app webview.
12 | ///
13 | [JsonPropertyName("renderedContent")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? RenderedContent { get; init; }
16 |
17 | ///
18 | /// Optional. Base64 encoded JSON representing array of tuple.
19 | ///
20 | [JsonPropertyName("sdkBlob")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? SdkBlob { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InputEmbedContentConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Batches;
4 |
5 | ///
6 | /// Configures the input to the batch request.
7 | ///
8 | public sealed record InputEmbedContentConfiguration
9 | {
10 | ///
11 | /// The name of the File containing the input requests.
12 | ///
13 | [JsonPropertyName("fileName")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? FileName { get; init; }
16 |
17 | ///
18 | /// The requests to be processed in the batch.
19 | ///
20 | [JsonPropertyName("requests")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public InlinedEmbedContentRequests? Requests { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/CorporaClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | internal sealed class CorporaClient : ICorporaClient
4 | {
5 | private readonly IGeminiRequester _requester;
6 |
7 | internal CorporaClient(IGeminiRequester requester)
8 | {
9 | ArgumentNullException.ThrowIfNull(requester);
10 | _requester = requester;
11 | }
12 |
13 | public Task GetOperationByCorpusAndOperationAsync(
14 | string corpus,
15 | string operation,
16 | CancellationToken cancellationToken = default)
17 | {
18 | ArgumentNullException.ThrowIfNull(corpus);
19 | ArgumentNullException.ThrowIfNull(operation);
20 | var path = $"/v1/corpora/{corpus}/operations/{operation}";
21 | return _requester.ExecuteAsync(HttpMethod.Get, path, cancellationToken);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedEmbedContentRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 | using GeminiDotnet.V1Beta.Models;
4 |
5 | namespace GeminiDotnet.V1Beta.Batches;
6 |
7 | ///
8 | /// The request to be processed in the batch.
9 | ///
10 | public sealed record InlinedEmbedContentRequest
11 | {
12 | ///
13 | /// Optional. The metadata to be associated with the request.
14 | ///
15 | [JsonPropertyName("metadata")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public JsonElement Metadata { get; init; }
18 |
19 | ///
20 | /// Required. The request to be processed in the batch.
21 | ///
22 | [JsonPropertyName("request")]
23 | public required EmbedContentRequest Request { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/ListFilesResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Response for ListFiles.
7 | ///
8 | public sealed record ListFilesResponse
9 | {
10 | ///
11 | /// The list of s.
12 | ///
13 | [JsonPropertyName("files")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Files { get; init; }
16 |
17 | ///
18 | /// A token that can be sent as a page_token into a subsequent ListFiles
19 | /// call.
20 | ///
21 | [JsonPropertyName("nextPageToken")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? NextPageToken { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictLongRunningRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1Beta.Models;
5 |
6 | ///
7 | /// Request message for [PredictionService.PredictLongRunning].
8 | ///
9 | public sealed record PredictLongRunningRequest
10 | {
11 | ///
12 | /// Required. The instances that are the input to the prediction call.
13 | ///
14 | [JsonPropertyName("instances")]
15 | public required ReadOnlyMemory Instances { get; init; }
16 |
17 | ///
18 | /// Optional. The parameters that govern the prediction call.
19 | ///
20 | [JsonPropertyName("parameters")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public JsonElement Parameters { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GroundingAttribution.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Attribution for a source that contributed to an answer.
7 | ///
8 | public sealed record GroundingAttribution
9 | {
10 | ///
11 | /// Grounding source content that makes up this attribution.
12 | ///
13 | [JsonPropertyName("content")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Content? Content { get; init; }
16 |
17 | ///
18 | /// Output only. Identifier for the source contributing to this attribution.
19 | ///
20 | [JsonPropertyName("sourceId")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public AttributionSourceId? SourceId { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InputEmbedContentConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Batches;
4 |
5 | ///
6 | /// Configures the input to the batch request.
7 | ///
8 | public sealed record InputEmbedContentConfiguration
9 | {
10 | ///
11 | /// The name of the containing the input requests.
12 | ///
13 | [JsonPropertyName("fileName")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? FileName { get; init; }
16 |
17 | ///
18 | /// The requests to be processed in the batch.
19 | ///
20 | [JsonPropertyName("requests")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public InlinedEmbedContentRequests? Requests { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ContentFilterReason.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// The reason content was blocked during request processing.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum ContentFilterReason
10 | {
11 | ///
12 | /// A blocked reason was not specified.
13 | ///
14 | [JsonStringEnumMemberName("BLOCKED_REASON_UNSPECIFIED")]
15 | BlockedReasonUnspecified,
16 |
17 | ///
18 | /// Content was blocked by safety settings.
19 | ///
20 | [JsonStringEnumMemberName("SAFETY")]
21 | Safety,
22 |
23 | ///
24 | /// Content was blocked, but the reason is uncategorized.
25 | ///
26 | [JsonStringEnumMemberName("OTHER")]
27 | Other,
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/GeminiClientExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 |
3 | namespace GeminiDotnet.Extensions.AI;
4 |
5 | public static class GeminiClientExtensions
6 | {
7 | ///
8 | /// Gets an using this instance.
9 | ///
10 | public static IChatClient AsChatClient(this IGeminiClient client)
11 | {
12 | ArgumentNullException.ThrowIfNull(client);
13 | return new GeminiChatClient(client);
14 | }
15 |
16 | ///
17 | /// Gets an using this instance.
18 | ///
19 | public static IEmbeddingGenerator AsEmbeddingGenerator(this IGeminiClient client)
20 | {
21 | ArgumentNullException.ThrowIfNull(client);
22 | return new GeminiEmbeddingGenerator(client);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/AttributionSourceId.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Identifier for the source contributing to this attribution.
7 | ///
8 | public sealed record AttributionSourceId
9 | {
10 | ///
11 | /// Identifier for an inline passage.
12 | ///
13 | [JsonPropertyName("groundingPassage")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public GroundingPassageId? GroundingPassage { get; init; }
16 |
17 | ///
18 | /// Identifier for a Chunk fetched via Semantic Retriever.
19 | ///
20 | [JsonPropertyName("semanticRetrieverChunk")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public SemanticRetrieverChunk? SemanticRetrieverChunk { get; init; }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/ContentEmbedding.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// A list of floats representing an embedding.
7 | ///
8 | public sealed record ContentEmbedding
9 | {
10 | ///
11 | /// This field stores the soft tokens tensor frame shape
12 | /// (e.g. [1, 1, 256, 2048]).
13 | ///
14 | [JsonPropertyName("shape")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public ReadOnlyMemory Shape { get; init; }
17 |
18 | ///
19 | /// The embedding values. This is for 3P users only and will not be populated
20 | /// for 1P calls.
21 | ///
22 | [JsonPropertyName("values")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public ReadOnlyMemory Values { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/ListModelsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// Response from ListModel containing a paginated list of Models.
7 | ///
8 | public sealed record ListModelsResponse
9 | {
10 | ///
11 | /// The returned Models.
12 | ///
13 | [JsonPropertyName("models")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Models { get; init; }
16 |
17 | ///
18 | /// A token, which can be sent as page_token to retrieve the next page.
19 | /// If this field is omitted, there are no more pages.
20 | ///
21 | [JsonPropertyName("nextPageToken")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? NextPageToken { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/GeminiClientException.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 |
3 | namespace GeminiDotnet;
4 |
5 | ///
6 | /// An exception thrown by the when a client or server error (status code 4xx or 5xx) is returned from the Gemini API.
7 | ///
8 | public sealed class GeminiClientException : Exception
9 | {
10 | private GeminiClientException(ErrorDetails response, string message) : base(message)
11 | {
12 | Response = response;
13 | }
14 |
15 | ///
16 | /// The error response returned by the Gemini API.
17 | ///
18 | public ErrorDetails Response { get; set; }
19 |
20 | [DoesNotReturn]
21 | internal static void Throw(ErrorDetails response)
22 | {
23 | var message = $"Error {response.StatusCode}: {response.Message}";
24 | throw new GeminiClientException(response, message);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/GeneratedFilesClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | internal sealed class GeneratedFilesClient : IGeneratedFilesClient
4 | {
5 | private readonly IGeminiRequester _requester;
6 |
7 | internal GeneratedFilesClient(IGeminiRequester requester)
8 | {
9 | ArgumentNullException.ThrowIfNull(requester);
10 | _requester = requester;
11 | }
12 |
13 | public Task GetOperationByGeneratedFileAndOperationAsync(
14 | string generatedFile,
15 | string operation,
16 | CancellationToken cancellationToken = default)
17 | {
18 | ArgumentNullException.ThrowIfNull(generatedFile);
19 | ArgumentNullException.ThrowIfNull(operation);
20 | var path = $"/v1/generatedFiles/{generatedFile}/operations/{operation}";
21 | return _requester.ExecuteAsync(HttpMethod.Get, path, cancellationToken);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ContentEmbedding.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// A list of floats representing an embedding.
7 | ///
8 | public sealed record ContentEmbedding
9 | {
10 | ///
11 | /// This field stores the soft tokens tensor frame shape
12 | /// (e.g. [1, 1, 256, 2048]).
13 | ///
14 | [JsonPropertyName("shape")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public ReadOnlyMemory Shape { get; init; }
17 |
18 | ///
19 | /// The embedding values. This is for 3P users only and will not be populated
20 | /// for 1P calls.
21 | ///
22 | [JsonPropertyName("values")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public ReadOnlyMemory Values { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ListModelsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Response from ListModel containing a paginated list of Models.
7 | ///
8 | public sealed record ListModelsResponse
9 | {
10 | ///
11 | /// The returned Models.
12 | ///
13 | [JsonPropertyName("models")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Models { get; init; }
16 |
17 | ///
18 | /// A token, which can be sent as page_token to retrieve the next page.
19 | /// If this field is omitted, there are no more pages.
20 | ///
21 | [JsonPropertyName("nextPageToken")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? NextPageToken { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/RetrievalConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Retrieval config.
7 | ///
8 | public sealed record RetrievalConfiguration
9 | {
10 | ///
11 | /// Optional. The language code of the user.
12 | /// Language code for content. Use language tags defined by
13 | /// [BCP47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt).
14 | ///
15 | [JsonPropertyName("languageCode")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? LanguageCode { get; init; }
18 |
19 | ///
20 | /// Optional. The location of the user.
21 | ///
22 | [JsonPropertyName("latLng")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public LatLng? LatLng { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/RetrievalMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Metadata related to retrieval in the grounding flow.
7 | ///
8 | public sealed record RetrievalMetadata
9 | {
10 | ///
11 | /// Optional. Score indicating how likely information from google search could help
12 | /// answer the prompt. The score is in the range [0, 1], where 0 is the least
13 | /// likely and 1 is the most likely. This score is only populated when
14 | /// google search grounding and dynamic retrieval is enabled. It will be
15 | /// compared to the threshold to determine whether to trigger google search.
16 | ///
17 | [JsonPropertyName("googleSearchDynamicRetrievalScore")]
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
19 | public float? GoogleSearchDynamicRetrievalScore { get; init; }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/DynamicRetrievalConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Describes the options to customize dynamic retrieval.
7 | ///
8 | public sealed record DynamicRetrievalConfiguration
9 | {
10 | ///
11 | /// The threshold to be used in dynamic retrieval.
12 | /// If not set, a system default value is used.
13 | ///
14 | [JsonPropertyName("dynamicThreshold")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public float? DynamicThreshold { get; init; }
17 |
18 | ///
19 | /// The mode of the predictor to be used in dynamic retrieval.
20 | ///
21 | [JsonPropertyName("mode")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public DynamicRetrievalConfigMode? Mode { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/ListCachedContentsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Response with CachedContents list.
7 | ///
8 | public sealed record ListCachedContentsResponse
9 | {
10 | ///
11 | /// List of cached contents.
12 | ///
13 | [JsonPropertyName("cachedContents")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? CachedContents { get; init; }
16 |
17 | ///
18 | /// A token, which can be sent as page_token to retrieve the next page.
19 | /// If this field is omitted, there are no subsequent pages.
20 | ///
21 | [JsonPropertyName("nextPageToken")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? NextPageToken { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ListPermissionsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Response from ListPermissions containing a paginated list of
7 | /// permissions.
8 | ///
9 | public sealed record ListPermissionsResponse
10 | {
11 | ///
12 | /// A token, which can be sent as page_token to retrieve the next page.
13 | /// If this field is omitted, there are no more pages.
14 | ///
15 | [JsonPropertyName("nextPageToken")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? NextPageToken { get; init; }
18 |
19 | ///
20 | /// Returned permissions.
21 | ///
22 | [JsonPropertyName("permissions")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public IReadOnlyList? Permissions { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/Contents/CodeExecutionStatus.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.Extensions.AI.Contents;
4 |
5 | ///
6 | /// Represents the outcome of a code execution.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum CodeExecutionStatus
10 | {
11 | ///
12 | /// No status.
13 | ///
14 | [JsonStringEnumMemberName("none")]
15 | None,
16 |
17 | ///
18 | /// The code execution was successful.
19 | ///
20 | [JsonStringEnumMemberName("success")]
21 | Success,
22 |
23 | ///
24 | /// The code execution failed.
25 | ///
26 | [JsonStringEnumMemberName("error")]
27 | Error,
28 |
29 | ///
30 | /// The code execution timed out.
31 | ///
32 | [JsonStringEnumMemberName("timeout")]
33 | Timeout
34 | }
35 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/RetrievalMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Metadata related to retrieval in the grounding flow.
7 | ///
8 | public sealed record RetrievalMetadata
9 | {
10 | ///
11 | /// Optional. Score indicating how likely information from google search could help
12 | /// answer the prompt. The score is in the range [0, 1], where 0 is the least
13 | /// likely and 1 is the most likely. This score is only populated when
14 | /// google search grounding and dynamic retrieval is enabled. It will be
15 | /// compared to the threshold to determine whether to trigger google search.
16 | ///
17 | [JsonPropertyName("googleSearchDynamicRetrievalScore")]
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
19 | public float? GoogleSearchDynamicRetrievalScore { get; init; }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/GeneratedFiles/ListGeneratedFilesResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.GeneratedFiles;
4 |
5 | ///
6 | /// Response for ListGeneratedFiles.
7 | ///
8 | public sealed record ListGeneratedFilesResponse
9 | {
10 | ///
11 | /// The list of s.
12 | ///
13 | [JsonPropertyName("generatedFiles")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? GeneratedFiles { get; init; }
16 |
17 | ///
18 | /// A token that can be sent as a page_token into a subsequent
19 | /// ListGeneratedFiles call.
20 | ///
21 | [JsonPropertyName("nextPageToken")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? NextPageToken { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/ListTunedModelsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Response from ListTunedModels containing a paginated list of Models.
7 | ///
8 | public sealed record ListTunedModelsResponse
9 | {
10 | ///
11 | /// A token, which can be sent as page_token to retrieve the next page.
12 | /// If this field is omitted, there are no more pages.
13 | ///
14 | [JsonPropertyName("nextPageToken")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public string? NextPageToken { get; init; }
17 |
18 | ///
19 | /// The returned Models.
20 | ///
21 | [JsonPropertyName("tunedModels")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public IReadOnlyList? TunedModels { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/ToolConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// The Tool configuration containing parameters for specifying use
7 | /// in the request.
8 | ///
9 | public sealed record ToolConfiguration
10 | {
11 | ///
12 | /// Optional. Function calling config.
13 | ///
14 | [JsonPropertyName("functionCallingConfig")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public FunctionCallingConfiguration? FunctionCallingConfiguration { get; init; }
17 |
18 | ///
19 | /// Optional. Retrieval config.
20 | ///
21 | [JsonPropertyName("retrievalConfig")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public RetrievalConfiguration? RetrievalConfiguration { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ExecutableCode.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Code generated by the model that is meant to be executed, and the result
7 | /// returned to the model.
8 | /// Only generated when using the tool, in which the code will
9 | /// be automatically executed, and a corresponding will
10 | /// also be generated.
11 | ///
12 | public sealed record ExecutableCode
13 | {
14 | ///
15 | /// Required. The code to be executed.
16 | ///
17 | [JsonPropertyName("code")]
18 | public required string Code { get; init; }
19 |
20 | ///
21 | /// Required. Programming language of the .
22 | ///
23 | [JsonPropertyName("language")]
24 | public required ExecutableCodeLanguage Language { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ContentFilter.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Content filtering metadata associated with processing a single request.
7 | /// ContentFilter contains a reason and an optional supporting string. The reason
8 | /// may be unspecified.
9 | ///
10 | public sealed record ContentFilter
11 | {
12 | ///
13 | /// A string that describes the filtering behavior in more detail.
14 | ///
15 | [JsonPropertyName("message")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? Message { get; init; }
18 |
19 | ///
20 | /// The reason content was blocked during request processing.
21 | ///
22 | [JsonPropertyName("reason")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public ContentFilterReason? Reason { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/Directory.Packages.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TunedModelState.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Output only. The state of the tuned model.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum TunedModelState
10 | {
11 | ///
12 | /// The default value. This value is unused.
13 | ///
14 | [JsonStringEnumMemberName("STATE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// The model is being created.
19 | ///
20 | [JsonStringEnumMemberName("CREATING")]
21 | Creating,
22 |
23 | ///
24 | /// The model is ready to be used.
25 | ///
26 | [JsonStringEnumMemberName("ACTIVE")]
27 | Active,
28 |
29 | ///
30 | /// The model failed to be created.
31 | ///
32 | [JsonStringEnumMemberName("FAILED")]
33 | Failed,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/PromptFeedback.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// A set of the feedback metadata the prompt specified in
7 | /// GenerateContentRequest.content.
8 | ///
9 | public sealed record PromptFeedback
10 | {
11 | ///
12 | /// Optional. If set, the prompt was blocked and no candidates are returned.
13 | /// Rephrase the prompt.
14 | ///
15 | [JsonPropertyName("blockReason")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public PromptFeedbackBlockReason? BlockReason { get; init; }
18 |
19 | ///
20 | /// Ratings for safety of the prompt.
21 | /// There is at most one rating per category.
22 | ///
23 | [JsonPropertyName("safetyRatings")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public IReadOnlyList? SafetyRatings { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/PermissionRole.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Required. The role granted by this permission.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum PermissionRole
10 | {
11 | ///
12 | /// The default value. This value is unused.
13 | ///
14 | [JsonStringEnumMemberName("ROLE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Owner can use, update, share and delete the resource.
19 | ///
20 | [JsonStringEnumMemberName("OWNER")]
21 | Owner,
22 |
23 | ///
24 | /// Writer can use, update and share the resource.
25 | ///
26 | [JsonStringEnumMemberName("WRITER")]
27 | Writer,
28 |
29 | ///
30 | /// Reader can use the resource.
31 | ///
32 | [JsonStringEnumMemberName("READER")]
33 | Reader,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CodeExecutionResult.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Result of executing the .
7 | /// Only generated when using the , and always follows a part
8 | /// containing the .
9 | ///
10 | public sealed record CodeExecutionResult
11 | {
12 | ///
13 | /// Required. Outcome of the code execution.
14 | ///
15 | [JsonPropertyName("outcome")]
16 | public required CodeExecutionResultOutcome Outcome { get; init; }
17 |
18 | ///
19 | /// Optional. Contains stdout when code execution is successful, stderr or other
20 | /// description otherwise.
21 | ///
22 | [JsonPropertyName("output")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public string? Output { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Corpora/ListCorporaResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Corpora;
4 |
5 | ///
6 | /// Response from ListCorpora containing a paginated list of Corpora.
7 | /// The results are sorted by ascending corpus.create_time.
8 | ///
9 | public sealed record ListCorporaResponse
10 | {
11 | ///
12 | /// The returned corpora.
13 | ///
14 | [JsonPropertyName("corpora")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? Corpora { get; init; }
17 |
18 | ///
19 | /// A token, which can be sent as page_token to retrieve the next page.
20 | /// If this field is omitted, there are no more pages.
21 | ///
22 | [JsonPropertyName("nextPageToken")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public string? NextPageToken { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/FileSource.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Source of the File.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum FileSource
10 | {
11 | ///
12 | /// Used if source is not specified.
13 | ///
14 | [JsonStringEnumMemberName("SOURCE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Indicates the file is uploaded by the user.
19 | ///
20 | [JsonStringEnumMemberName("UPLOADED")]
21 | Uploaded,
22 |
23 | ///
24 | /// Indicates the file is generated by Google.
25 | ///
26 | [JsonStringEnumMemberName("GENERATED")]
27 | Generated,
28 |
29 | ///
30 | /// Indicates the file is a registered, i.e. a Google Cloud Storage file.
31 | ///
32 | [JsonStringEnumMemberName("REGISTERED")]
33 | Registered,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/InputFeedbackBlockReason.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Optional. If set, the input was blocked and no candidates are returned.
7 | /// Rephrase the input.
8 | ///
9 | [JsonConverter(typeof(JsonStringEnumConverter))]
10 | public enum InputFeedbackBlockReason
11 | {
12 | ///
13 | /// Default value. This value is unused.
14 | ///
15 | [JsonStringEnumMemberName("BLOCK_REASON_UNSPECIFIED")]
16 | Unspecified,
17 |
18 | ///
19 | /// Input was blocked due to safety reasons. Inspect
20 | /// `safety_ratings` to understand which safety category blocked it.
21 | ///
22 | [JsonStringEnumMemberName("SAFETY")]
23 | Safety,
24 |
25 | ///
26 | /// Input was blocked due to other reasons.
27 | ///
28 | [JsonStringEnumMemberName("OTHER")]
29 | Other,
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/ICorporaClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | public interface ICorporaClient
4 | {
5 | ///
6 | /// Gets the latest state of a long-running operation. Clients can use this
7 | /// method to poll the operation result at intervals as recommended by the API
8 | /// service.
9 | ///
10 | ///
11 | /// Resource ID segment making up resource name. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
12 | ///
13 | ///
14 | /// Resource ID segment making up resource name. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
15 | ///
16 | ///
17 | Task GetOperationByCorpusAndOperationAsync(
18 | string corpus,
19 | string operation,
20 | CancellationToken cancellationToken = default);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FunctionResponsePart.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// A datatype containing media that is part of a message.
7 | /// A consists of data which has an associated datatype. A
8 | /// can only contain one of the accepted types in
9 | /// FunctionResponsePart.data.
10 | /// A must have a fixed IANA MIME type identifying the
11 | /// type and subtype of the media if the inline_data field is filled with raw
12 | /// bytes.
13 | ///
14 | public sealed record FunctionResponsePart
15 | {
16 | ///
17 | /// Inline media bytes.
18 | ///
19 | [JsonPropertyName("inlineData")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public FunctionResponseBlob? InlineData { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Examples/YouTubeExample.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 |
3 | namespace GeminiDotnet.Extensions.AI.Examples;
4 |
5 | public sealed class YouTubeExample
6 | {
7 | public static async Task ExecuteAsync(IChatClient geminiClient, CancellationToken cancellationToken)
8 | {
9 | var chatOptions = new ChatOptions { ModelId = "gemini-2.5-flash-lite", };
10 |
11 | IList messages =
12 | [
13 | new(ChatRole.User, [
14 | new TextContent(
15 | "Summarize the following YouTube video. Pay particular attention to the parts about the future of software development."),
16 | new UriContent("https://www.youtube.com/watch?v=En5cSXgGvZM", "video/mp4"),
17 | ])
18 | ];
19 |
20 | await foreach (var update in geminiClient.GetStreamingResponseAsync(messages, chatOptions, cancellationToken))
21 | {
22 | Console.Write(update.Text);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Files/FileState.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Files;
4 |
5 | ///
6 | /// Output only. Processing state of the File.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum FileState
10 | {
11 | ///
12 | /// The default value. This value is used if the state is omitted.
13 | ///
14 | [JsonStringEnumMemberName("STATE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// File is being processed and cannot be used for inference yet.
19 | ///
20 | [JsonStringEnumMemberName("PROCESSING")]
21 | Processing,
22 |
23 | ///
24 | /// File is processed and available for inference.
25 | ///
26 | [JsonStringEnumMemberName("ACTIVE")]
27 | Active,
28 |
29 | ///
30 | /// File failed processing.
31 | ///
32 | [JsonStringEnumMemberName("FAILED")]
33 | Failed,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GroundingPassageId.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Identifier for a part within a .
7 | ///
8 | public sealed record GroundingPassageId
9 | {
10 | ///
11 | /// Output only. Index of the part within the 's
12 | /// GroundingPassage.content.
13 | ///
14 | [JsonPropertyName("partIndex")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public int? PartIndex { get; init; }
17 |
18 | ///
19 | /// Output only. ID of the passage matching the 's
20 | /// GroundingPassage.id.
21 | ///
22 | [JsonPropertyName("passageId")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public string? PassageId { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/LogprobsResultCandidate.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Candidate for the logprobs token and score.
7 | ///
8 | public sealed record LogprobsResultCandidate
9 | {
10 | ///
11 | /// The candidate's log probability.
12 | ///
13 | [JsonPropertyName("logProbability")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public float? LogProbability { get; init; }
16 |
17 | ///
18 | /// The candidate’s token string value.
19 | ///
20 | [JsonPropertyName("token")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? Token { get; init; }
23 |
24 | ///
25 | /// The candidate’s token id value.
26 | ///
27 | [JsonPropertyName("tokenId")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public int? TokenId { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ResponseModality.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Optional. The requested modalities of the response. Represents the set of modalities
7 | /// that the model can return, and should be expected in the response. This is
8 | /// an exact match to the modalities of the response.
9 | /// A model may have multiple combinations of supported modalities. If the
10 | /// requested modalities do not match any of the supported combinations, an
11 | /// error will be returned.
12 | /// An empty list is equivalent to requesting only text.
13 | ///
14 | [JsonConverter(typeof(JsonStringEnumConverter))]
15 | public enum ResponseModality
16 | {
17 | [JsonStringEnumMemberName("MODALITY_UNSPECIFIED")]
18 | Unspecified,
19 |
20 | [JsonStringEnumMemberName("TEXT")]
21 | Text,
22 |
23 | [JsonStringEnumMemberName("IMAGE")]
24 | Image,
25 |
26 | [JsonStringEnumMemberName("AUDIO")]
27 | Audio,
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/BatchEmbedTextRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Batch request to get a text embedding from the model.
7 | ///
8 | public sealed record BatchEmbedTextRequest
9 | {
10 | ///
11 | /// Optional. Embed requests for the batch. Only one of or can be set.
12 | ///
13 | [JsonPropertyName("requests")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? Requests { get; init; }
16 |
17 | ///
18 | /// Optional. The free-form input texts that the model will turn into an embedding. The
19 | /// current limit is 100 texts, over which an error will be thrown.
20 | ///
21 | [JsonPropertyName("texts")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public IReadOnlyList? Texts { get; init; }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PlaceAnswerSources.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Collection of sources that provide answers about the features of a given
7 | /// place in Google Maps. Each PlaceAnswerSources message corresponds to a
8 | /// specific place in Google Maps. The Google Maps tool used these sources in
9 | /// order to answer questions about features of the place (e.g: "does Bar Foo
10 | /// have Wifi" or "is Foo Bar wheelchair accessible?"). Currently we only
11 | /// support review snippets as sources.
12 | ///
13 | public sealed record PlaceAnswerSources
14 | {
15 | ///
16 | /// Snippets of reviews that are used to generate answers about the
17 | /// features of a given place in Google Maps.
18 | ///
19 | [JsonPropertyName("reviewSnippets")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public IReadOnlyList? ReviewSnippets { get; init; }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/GeneratedFiles/GeneratedFileState.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.GeneratedFiles;
4 |
5 | ///
6 | /// Output only. The state of the GeneratedFile.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum GeneratedFileState
10 | {
11 | ///
12 | /// The default value. This value is used if the state is omitted.
13 | ///
14 | [JsonStringEnumMemberName("STATE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Being generated.
19 | ///
20 | [JsonStringEnumMemberName("GENERATING")]
21 | Generating,
22 |
23 | ///
24 | /// Generated and is ready for download.
25 | ///
26 | [JsonStringEnumMemberName("GENERATED")]
27 | Generated,
28 |
29 | ///
30 | /// Failed to generate the GeneratedFile.
31 | ///
32 | [JsonStringEnumMemberName("FAILED")]
33 | Failed,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/InputFeedback.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Feedback related to the input data used to answer the question, as opposed
7 | /// to the model-generated response to the question.
8 | ///
9 | public sealed record InputFeedback
10 | {
11 | ///
12 | /// Optional. If set, the input was blocked and no candidates are returned.
13 | /// Rephrase the input.
14 | ///
15 | [JsonPropertyName("blockReason")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public InputFeedbackBlockReason? BlockReason { get; init; }
18 |
19 | ///
20 | /// Ratings for safety of the input.
21 | /// There is at most one rating per category.
22 | ///
23 | [JsonPropertyName("safetyRatings")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public IReadOnlyList? SafetyRatings { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/PromptFeedback.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Models;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// A set of the feedback metadata the prompt specified in
8 | /// GenerateContentRequest.content.
9 | ///
10 | public sealed record PromptFeedback
11 | {
12 | ///
13 | /// Optional. If set, the prompt was blocked and no candidates are returned.
14 | /// Rephrase the prompt.
15 | ///
16 | [JsonPropertyName("blockReason")]
17 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18 | public PromptFeedbackBlockReason? BlockReason { get; init; }
19 |
20 | ///
21 | /// Ratings for safety of the prompt.
22 | /// There is at most one rating per category.
23 | ///
24 | [JsonPropertyName("safetyRatings")]
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26 | public IReadOnlyList? SafetyRatings { get; init; }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | Copyright 2025 Ryan Buckley
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
9 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/IGeneratedFilesClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | public interface IGeneratedFilesClient
4 | {
5 | ///
6 | /// Gets the latest state of a long-running operation. Clients can use this
7 | /// method to poll the operation result at intervals as recommended by the API
8 | /// service.
9 | ///
10 | ///
11 | /// Resource ID segment making up resource name. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
12 | ///
13 | ///
14 | /// Resource ID segment making up resource name. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
15 | ///
16 | ///
17 | Task GetOperationByGeneratedFileAndOperationAsync(
18 | string generatedFile,
19 | string operation,
20 | CancellationToken cancellationToken = default);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/LogprobsResultCandidate.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Candidate for the logprobs token and score.
7 | ///
8 | public sealed record LogprobsResultCandidate
9 | {
10 | ///
11 | /// The candidate's log probability.
12 | ///
13 | [JsonPropertyName("logProbability")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public float? LogProbability { get; init; }
16 |
17 | ///
18 | /// The candidate’s token string value.
19 | ///
20 | [JsonPropertyName("token")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public string? Token { get; init; }
23 |
24 | ///
25 | /// The candidate’s token id value.
26 | ///
27 | [JsonPropertyName("tokenId")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public int? TokenId { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/Condition.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Filter condition applicable to a single key.
7 | ///
8 | public sealed record Condition
9 | {
10 | ///
11 | /// The numeric value to filter the metadata on.
12 | ///
13 | [JsonPropertyName("numericValue")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public float? NumericValue { get; init; }
16 |
17 | ///
18 | /// Required. Operator applied to the given key-value pair to trigger the condition.
19 | ///
20 | [JsonPropertyName("operation")]
21 | public required ConditionOperation Operation { get; init; }
22 |
23 | ///
24 | /// The string value to filter the metadata on.
25 | ///
26 | [JsonPropertyName("stringValue")]
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
28 | public string? StringValue { get; init; }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GroundingChunk.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Grounding chunk.
7 | ///
8 | public sealed record GroundingChunk
9 | {
10 | ///
11 | /// Optional. Grounding chunk from Google Maps.
12 | ///
13 | [JsonPropertyName("maps")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public Maps? Maps { get; init; }
16 |
17 | ///
18 | /// Optional. Grounding chunk from context retrieved by the file search tool.
19 | ///
20 | [JsonPropertyName("retrievedContext")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public RetrievedContext? RetrievedContext { get; init; }
23 |
24 | ///
25 | /// Grounding chunk from the web.
26 | ///
27 | [JsonPropertyName("web")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public Web? Web { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/LatLng.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// An object that represents a latitude/longitude pair. This is expressed as a
7 | /// pair of doubles to represent degrees latitude and degrees longitude. Unless
8 | /// specified otherwise, this object must conform to the
9 | /// WGS84 standard. Values must be within normalized ranges.
10 | ///
11 | public sealed record LatLng
12 | {
13 | ///
14 | /// The latitude in degrees. It must be in the range [-90.0, +90.0].
15 | ///
16 | [JsonPropertyName("latitude")]
17 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18 | public double? Latitude { get; init; }
19 |
20 | ///
21 | /// The longitude in degrees. It must be in the range [-180.0, +180.0].
22 | ///
23 | [JsonPropertyName("longitude")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public double? Longitude { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/GenerativeLanguageModality.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | [JsonConverter(typeof(JsonStringEnumConverter))]
6 | public enum GenerativeLanguageModality
7 | {
8 | ///
9 | /// Unspecified modality.
10 | ///
11 | [JsonStringEnumMemberName("MODALITY_UNSPECIFIED")]
12 | Unspecified,
13 |
14 | ///
15 | /// Plain text.
16 | ///
17 | [JsonStringEnumMemberName("TEXT")]
18 | Text,
19 |
20 | ///
21 | /// Image.
22 | ///
23 | [JsonStringEnumMemberName("IMAGE")]
24 | Image,
25 |
26 | ///
27 | /// Video.
28 | ///
29 | [JsonStringEnumMemberName("VIDEO")]
30 | Video,
31 |
32 | ///
33 | /// Audio.
34 | ///
35 | [JsonStringEnumMemberName("AUDIO")]
36 | Audio,
37 |
38 | ///
39 | /// Document, e.g. PDF.
40 | ///
41 | [JsonStringEnumMemberName("DOCUMENT")]
42 | Document,
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ListFileSearchStoresResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Response from ListFileSearchStores containing a paginated list of
7 | /// FileSearchStores. The results are sorted by ascending
8 | /// file_search_store.create_time.
9 | ///
10 | public sealed record ListFileSearchStoresResponse
11 | {
12 | ///
13 | /// The returned rag_stores.
14 | ///
15 | [JsonPropertyName("fileSearchStores")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public IReadOnlyList? FileSearchStores { get; init; }
18 |
19 | ///
20 | /// A token, which can be sent as page_token to retrieve the next page.
21 | /// If this field is omitted, there are no more pages.
22 | ///
23 | [JsonPropertyName("nextPageToken")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public string? NextPageToken { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/ComputerUse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Computer Use tool type.
7 | ///
8 | public sealed record ComputerUse
9 | {
10 | ///
11 | /// Required. The environment being operated.
12 | ///
13 | [JsonPropertyName("environment")]
14 | public required ComputerUseEnvironment Environment { get; init; }
15 |
16 | ///
17 | /// Optional. By default, predefined functions are included in the final model
18 | /// call.
19 | /// Some of them can be explicitly excluded from being automatically
20 | /// included. This can serve two purposes:
21 | /// 1. Using a more restricted / different action space.
22 | /// 2. Improving the definitions / instructions of predefined functions.
23 | ///
24 | [JsonPropertyName("excludedPredefinedFunctions")]
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26 | public IReadOnlyList? ExcludedPredefinedFunctions { get; init; }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GenerativeLanguageModality.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | [JsonConverter(typeof(JsonStringEnumConverter))]
6 | public enum GenerativeLanguageModality
7 | {
8 | ///
9 | /// Unspecified modality.
10 | ///
11 | [JsonStringEnumMemberName("MODALITY_UNSPECIFIED")]
12 | Unspecified,
13 |
14 | ///
15 | /// Plain text.
16 | ///
17 | [JsonStringEnumMemberName("TEXT")]
18 | Text,
19 |
20 | ///
21 | /// Image.
22 | ///
23 | [JsonStringEnumMemberName("IMAGE")]
24 | Image,
25 |
26 | ///
27 | /// Video.
28 | ///
29 | [JsonStringEnumMemberName("VIDEO")]
30 | Video,
31 |
32 | ///
33 | /// Audio.
34 | ///
35 | [JsonStringEnumMemberName("AUDIO")]
36 | Audio,
37 |
38 | ///
39 | /// Document, e.g. PDF.
40 | ///
41 | [JsonStringEnumMemberName("DOCUMENT")]
42 | Document,
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TunedModelSource.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Tuned model as a source for training a new model.
7 | ///
8 | public sealed record TunedModelSource
9 | {
10 | ///
11 | /// Output only. The name of the base this was tuned from.
12 | /// Example: models/gemini-1.5-flash-001
13 | ///
14 | [JsonPropertyName("baseModel")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public string? BaseModel { get; init; }
17 |
18 | ///
19 | /// Immutable. The name of the to use as the starting point for
20 | /// training the new model.
21 | /// Example: tunedModels/my-tuned-model
22 | ///
23 | [JsonPropertyName("tunedModel")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public string? TunedModel { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/PermissionGranteeType.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Optional. Immutable. The type of the grantee.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum PermissionGranteeType
10 | {
11 | ///
12 | /// The default value. This value is unused.
13 | ///
14 | [JsonStringEnumMemberName("GRANTEE_TYPE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Represents a user. When set, you must provide email_address for the user.
19 | ///
20 | [JsonStringEnumMemberName("USER")]
21 | User,
22 |
23 | ///
24 | /// Represents a group. When set, you must provide email_address for the
25 | /// group.
26 | ///
27 | [JsonStringEnumMemberName("GROUP")]
28 | Group,
29 |
30 | ///
31 | /// Represents access to everyone. No extra information is required.
32 | ///
33 | [JsonStringEnumMemberName("EVERYONE")]
34 | Everyone,
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Blob.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Raw media bytes.
7 | /// Text should not be sent as raw bytes, use the 'text' field.
8 | ///
9 | public sealed record Blob
10 | {
11 | ///
12 | /// Raw bytes for media formats.
13 | ///
14 | [JsonPropertyName("data")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public ReadOnlyMemory Data { get; init; }
17 |
18 | ///
19 | /// The IANA standard MIME type of the source data.
20 | /// Examples:
21 | /// - image/png
22 | /// - image/jpeg
23 | /// If an unsupported MIME type is provided, an error will be returned. For a
24 | /// complete list of supported types, see [Supported file
25 | /// formats](https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats).
26 | ///
27 | [JsonPropertyName("mimeType")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public string? MimeType { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/ReviewSnippet.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Encapsulates a snippet of a user review that answers a question about
7 | /// the features of a specific place in Google Maps.
8 | ///
9 | public sealed record ReviewSnippet
10 | {
11 | ///
12 | /// A link that corresponds to the user review on Google Maps.
13 | ///
14 | [JsonPropertyName("googleMapsUri")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public string? GoogleMapsUri { get; init; }
17 |
18 | ///
19 | /// The ID of the review snippet.
20 | ///
21 | [JsonPropertyName("reviewId")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? ReviewId { get; init; }
24 |
25 | ///
26 | /// Title of the review.
27 | ///
28 | [JsonPropertyName("title")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public string? Title { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1.Batches;
5 |
6 | ///
7 | /// The response to a single request in the batch.
8 | ///
9 | public sealed record InlinedResponse
10 | {
11 | ///
12 | /// Output only. The error encountered while processing the request.
13 | ///
14 | [JsonPropertyName("error")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public Status? Error { get; init; }
17 |
18 | ///
19 | /// Output only. The metadata associated with the request.
20 | ///
21 | [JsonPropertyName("metadata")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public JsonElement Metadata { get; init; }
24 |
25 | ///
26 | /// Output only. The response to the request.
27 | ///
28 | [JsonPropertyName("response")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public GenerateContentResponse? Response { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/Blob.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// Raw media bytes.
7 | /// Text should not be sent as raw bytes, use the 'text' field.
8 | ///
9 | public sealed record Blob
10 | {
11 | ///
12 | /// Raw bytes for media formats.
13 | ///
14 | [JsonPropertyName("data")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public ReadOnlyMemory Data { get; init; }
17 |
18 | ///
19 | /// The IANA standard MIME type of the source data.
20 | /// Examples:
21 | /// - image/png
22 | /// - image/jpeg
23 | /// If an unsupported MIME type is provided, an error will be returned. For a
24 | /// complete list of supported types, see [Supported file
25 | /// formats](https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats).
26 | ///
27 | [JsonPropertyName("mimeType")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public string? MimeType { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/GeminiV1Client.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | public sealed partial class GeminiV1Client : IGeminiV1Client
4 | {
5 | private readonly IGeminiRequester _requester;
6 |
7 | internal GeminiV1Client(IGeminiRequester requester)
8 | {
9 | ArgumentNullException.ThrowIfNull(requester);
10 | _requester = requester;
11 | }
12 |
13 | public IBatchesClient Batches => field ??= new BatchesClient(_requester);
14 |
15 | public ICorporaClient Corpora => field ??= new CorporaClient(_requester);
16 |
17 | public IDynamicClient Dynamic => field ??= new DynamicClient(_requester);
18 |
19 | public IFileSearchStoresClient FileSearchStores => field ??= new FileSearchStoresClient(_requester);
20 |
21 | public IGeneratedFilesClient GeneratedFiles => field ??= new GeneratedFilesClient(_requester);
22 |
23 | public IModelsClient Models => field ??= new ModelsClient(_requester);
24 |
25 | public IOperationsClient Operations => field ??= new OperationsClient(_requester);
26 |
27 | public ITunedModelsClient TunedModels => field ??= new TunedModelsClient(_requester);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/GenerationConfigMediaResolution.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Optional. If specified, the media resolution specified will be used.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum GenerationConfigMediaResolution
10 | {
11 | ///
12 | /// Media resolution has not been set.
13 | ///
14 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Media resolution set to low (64 tokens).
19 | ///
20 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_LOW")]
21 | Low,
22 |
23 | ///
24 | /// Media resolution set to medium (256 tokens).
25 | ///
26 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_MEDIUM")]
27 | Medium,
28 |
29 | ///
30 | /// Media resolution set to high (zoomed reframing with 256 tokens).
31 | ///
32 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_HIGH")]
33 | High,
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ImageConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Config for image generation features.
7 | ///
8 | public sealed record ImageConfiguration
9 | {
10 | ///
11 | /// Optional. The aspect ratio of the image to generate. Supported aspect ratios: 1:1,
12 | /// 2:3, 3:2, 3:4, 4:3, 9:16, 16:9, 21:9.
13 | /// If not specified, the model will choose a default aspect ratio based on any
14 | /// reference images provided.
15 | ///
16 | [JsonPropertyName("aspectRatio")]
17 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18 | public string? AspectRatio { get; init; }
19 |
20 | ///
21 | /// Optional. Specifies the size of generated images. Supported values are 1K, 2K,
22 | /// 4K. If not specified, the model will use default value 1K.
23 | ///
24 | [JsonPropertyName("imageSize")]
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26 | public string? ImageSize { get; init; }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace GeminiDotnet.V1Beta.Batches;
5 |
6 | ///
7 | /// The response to a single request in the batch.
8 | ///
9 | public sealed record InlinedResponse
10 | {
11 | ///
12 | /// Output only. The error encountered while processing the request.
13 | ///
14 | [JsonPropertyName("error")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public Status? Error { get; init; }
17 |
18 | ///
19 | /// Output only. The metadata associated with the request.
20 | ///
21 | [JsonPropertyName("metadata")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public JsonElement Metadata { get; init; }
24 |
25 | ///
26 | /// Output only. The response to the request.
27 | ///
28 | [JsonPropertyName("response")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public GenerateContentResponse? Response { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/MetadataFilter.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// User provided filter to limit retrieval based on Chunk or level
7 | /// metadata values.
8 | /// Example (genre = drama OR genre = action):
9 | /// key = "document.custom_metadata.genre"
10 | /// conditions = [{string_value = "drama", operation = EQUAL},
11 | /// {string_value = "action", operation = EQUAL}]
12 | ///
13 | public sealed record MetadataFilter
14 | {
15 | ///
16 | /// Required. The s for the given key that will trigger this filter. Multiple
17 | /// s are joined by logical ORs.
18 | ///
19 | [JsonPropertyName("conditions")]
20 | public required IReadOnlyList Conditions { get; init; }
21 |
22 | ///
23 | /// Required. The key of the metadata to filter on.
24 | ///
25 | [JsonPropertyName("key")]
26 | public required string Key { get; init; }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ListDocumentsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Response from ListDocuments containing a paginated list of s.
7 | /// The s are sorted by ascending document.create_time.
8 | ///
9 | public sealed record ListDocumentsResponse
10 | {
11 | ///
12 | /// The returned s.
13 | ///
14 | [JsonPropertyName("documents")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? Documents { get; init; }
17 |
18 | ///
19 | /// A token, which can be sent as page_token to retrieve the next page.
20 | /// If this field is omitted, there are no more pages.
21 | ///
22 | [JsonPropertyName("nextPageToken")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public string? NextPageToken { get; init; }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/VideoMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Metadata describes the input video content.
7 | ///
8 | public sealed record VideoMetadata
9 | {
10 | ///
11 | /// Optional. The end offset of the video.
12 | ///
13 | [JsonPropertyName("endOffset")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? EndOffset { get; init; }
16 |
17 | ///
18 | /// Optional. The frame rate of the video sent to the model. If not specified, the
19 | /// default value will be 1.0.
20 | /// The fps range is (0.0, 24.0].
21 | ///
22 | [JsonPropertyName("fps")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public double? Fps { get; init; }
25 |
26 | ///
27 | /// Optional. The start offset of the video.
28 | ///
29 | [JsonPropertyName("startOffset")]
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
31 | public string? StartOffset { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/VideoMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// Metadata describes the input video content.
7 | ///
8 | public sealed record VideoMetadata
9 | {
10 | ///
11 | /// Optional. The end offset of the video.
12 | ///
13 | [JsonPropertyName("endOffset")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? EndOffset { get; init; }
16 |
17 | ///
18 | /// Optional. The frame rate of the video sent to the model. If not specified, the
19 | /// default value will be 1.0.
20 | /// The fps range is (0.0, 24.0].
21 | ///
22 | [JsonPropertyName("fps")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public double? Fps { get; init; }
25 |
26 | ///
27 | /// Optional. The start offset of the video.
28 | ///
29 | [JsonPropertyName("startOffset")]
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
31 | public string? StartOffset { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/DocumentState.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Output only. Current state of the `Document`.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum DocumentState
10 | {
11 | ///
12 | /// The default value. This value is used if the state is omitted.
13 | ///
14 | [JsonStringEnumMemberName("STATE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Some `Chunks` of the `Document` are being processed (embedding and vector
19 | /// storage).
20 | ///
21 | [JsonStringEnumMemberName("STATE_PENDING")]
22 | Pending,
23 |
24 | ///
25 | /// All `Chunks` of the `Document` is processed and available for querying.
26 | ///
27 | [JsonStringEnumMemberName("STATE_ACTIVE")]
28 | Active,
29 |
30 | ///
31 | /// Some `Chunks` of the `Document` failed processing.
32 | ///
33 | [JsonStringEnumMemberName("STATE_FAILED")]
34 | Failed,
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Tests/GeminiDotnet.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | enable
5 | Exe
6 | GeminiDotnet
7 | true
8 | true
9 | true
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/GenerateAnswerRequestAnswerStyle.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Required. Style in which answers should be returned.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum GenerateAnswerRequestAnswerStyle
10 | {
11 | ///
12 | /// Unspecified answer style.
13 | ///
14 | [JsonStringEnumMemberName("ANSWER_STYLE_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Succinct but abstract style.
19 | ///
20 | [JsonStringEnumMemberName("ABSTRACTIVE")]
21 | Abstractive,
22 |
23 | ///
24 | /// Very brief and extractive style.
25 | ///
26 | [JsonStringEnumMemberName("EXTRACTIVE")]
27 | Extractive,
28 |
29 | ///
30 | /// Verbose style including extra details. The response may be formatted as a
31 | /// sentence, paragraph, multiple paragraphs, or bullet points, etc.
32 | ///
33 | [JsonStringEnumMemberName("VERBOSE")]
34 | Verbose,
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/PredictLongRunningGeneratedVideoResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Veo response.
7 | ///
8 | public sealed record PredictLongRunningGeneratedVideoResponse
9 | {
10 | ///
11 | /// The generated samples.
12 | ///
13 | [JsonPropertyName("generatedSamples")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public IReadOnlyList? GeneratedSamples { get; init; }
16 |
17 | ///
18 | /// Returns if any videos were filtered due to RAI policies.
19 | ///
20 | [JsonPropertyName("raiMediaFilteredCount")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public int? RaiMediaFilteredCount { get; init; }
23 |
24 | ///
25 | /// Returns rai failure reasons if any.
26 | ///
27 | [JsonPropertyName("raiMediaFilteredReasons")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public IReadOnlyList? RaiMediaFilteredReasons { get; init; }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/SafetyFeedback.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 | using GeminiDotnet.V1Beta.Models;
3 |
4 | namespace GeminiDotnet.V1Beta;
5 |
6 | ///
7 | /// Safety feedback for an entire request.
8 | /// This field is populated if content in the input and/or response is blocked
9 | /// due to safety settings. SafetyFeedback may not exist for every HarmCategory.
10 | /// Each SafetyFeedback will return the safety settings used by the request as
11 | /// well as the lowest HarmProbability that should be allowed in order to return
12 | /// a result.
13 | ///
14 | public sealed record SafetyFeedback
15 | {
16 | ///
17 | /// Safety rating evaluated from content.
18 | ///
19 | [JsonPropertyName("rating")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public SafetyRating? Rating { get; init; }
22 |
23 | ///
24 | /// Safety settings applied to the request.
25 | ///
26 | [JsonPropertyName("setting")]
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
28 | public SafetySetting? Setting { get; init; }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/LogprobsResult.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Logprobs Result
7 | ///
8 | public sealed record LogprobsResult
9 | {
10 | ///
11 | /// Length = total number of decoding steps.
12 | /// The chosen candidates may or may not be in top_candidates.
13 | ///
14 | [JsonPropertyName("chosenCandidates")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? ChosenCandidates { get; init; }
17 |
18 | ///
19 | /// Sum of log probabilities for all tokens.
20 | ///
21 | [JsonPropertyName("logProbabilitySum")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public float? LogProbabilitySum { get; init; }
24 |
25 | ///
26 | /// Length = total number of decoding steps.
27 | ///
28 | [JsonPropertyName("topCandidates")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public IReadOnlyList? TopCandidates { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/SemanticRetrieverChunk.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Identifier for a Chunk retrieved via Semantic Retriever specified in the
7 | /// using .
8 | ///
9 | public sealed record SemanticRetrieverChunk
10 | {
11 | ///
12 | /// Output only. Name of the Chunk containing the attributed text.
13 | /// Example: corpora/123/documents/abc/chunks/xyz
14 | ///
15 | [JsonPropertyName("chunk")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? Chunk { get; init; }
18 |
19 | ///
20 | /// Output only. Name of the source matching the request's
21 | /// SemanticRetrieverConfig.source. Example: corpora/123 or
22 | /// corpora/123/documents/abc
23 | ///
24 | [JsonPropertyName("source")]
25 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26 | public string? Source { get; init; }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Batches/InlinedEmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 | using GeminiDotnet.V1.Models;
4 |
5 | namespace GeminiDotnet.V1.Batches;
6 |
7 | ///
8 | /// The response to a single request in the batch.
9 | ///
10 | public sealed record InlinedEmbedContentResponse
11 | {
12 | ///
13 | /// Output only. The error encountered while processing the request.
14 | ///
15 | [JsonPropertyName("error")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public Status? Error { get; init; }
18 |
19 | ///
20 | /// Output only. The metadata associated with the request.
21 | ///
22 | [JsonPropertyName("metadata")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public JsonElement Metadata { get; init; }
25 |
26 | ///
27 | /// Output only. The response to the request.
28 | ///
29 | [JsonPropertyName("response")]
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
31 | public EmbedContentResponse? Response { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CodeExecutionResultOutcome.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Required. Outcome of the code execution.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum CodeExecutionResultOutcome
10 | {
11 | ///
12 | /// Unspecified status. This value should not be used.
13 | ///
14 | [JsonStringEnumMemberName("OUTCOME_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Code execution completed successfully.
19 | ///
20 | [JsonStringEnumMemberName("OUTCOME_OK")]
21 | Ok,
22 |
23 | ///
24 | /// Code execution finished but with a failure. `stderr` should contain the
25 | /// reason.
26 | ///
27 | [JsonStringEnumMemberName("OUTCOME_FAILED")]
28 | Failed,
29 |
30 | ///
31 | /// Code execution ran for too long, and was cancelled. There may or may not
32 | /// be a partial output present.
33 | ///
34 | [JsonStringEnumMemberName("OUTCOME_DEADLINE_EXCEEDED")]
35 | DeadlineExceeded,
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/MediaResolutionLevel.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | [JsonConverter(typeof(JsonStringEnumConverter))]
6 | public enum MediaResolutionLevel
7 | {
8 | ///
9 | /// Media resolution has not been set.
10 | ///
11 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_UNSPECIFIED")]
12 | MediaResolutionUnspecified,
13 |
14 | ///
15 | /// Media resolution set to low.
16 | ///
17 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_LOW")]
18 | MediaResolutionLow,
19 |
20 | ///
21 | /// Media resolution set to medium.
22 | ///
23 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_MEDIUM")]
24 | MediaResolutionMedium,
25 |
26 | ///
27 | /// Media resolution set to high.
28 | ///
29 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_HIGH")]
30 | MediaResolutionHigh,
31 |
32 | ///
33 | /// Media resolution set to ultra high.
34 | ///
35 | [JsonStringEnumMemberName("MEDIA_RESOLUTION_ULTRA_HIGH")]
36 | MediaResolutionUltraHigh,
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/LogprobsResult.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Logprobs Result
7 | ///
8 | public sealed record LogprobsResult
9 | {
10 | ///
11 | /// Length = total number of decoding steps.
12 | /// The chosen candidates may or may not be in top_candidates.
13 | ///
14 | [JsonPropertyName("chosenCandidates")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? ChosenCandidates { get; init; }
17 |
18 | ///
19 | /// Sum of log probabilities for all tokens.
20 | ///
21 | [JsonPropertyName("logProbabilitySum")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public float? LogProbabilitySum { get; init; }
24 |
25 | ///
26 | /// Length = total number of decoding steps.
27 | ///
28 | [JsonPropertyName("topCandidates")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public IReadOnlyList? TopCandidates { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FunctionResponseBlob.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Raw media bytes for function response.
7 | /// Text should not be sent as raw bytes, use the 'FunctionResponse.response'
8 | /// field.
9 | ///
10 | public sealed record FunctionResponseBlob
11 | {
12 | ///
13 | /// Raw bytes for media formats.
14 | ///
15 | [JsonPropertyName("data")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? Data { get; init; }
18 |
19 | ///
20 | /// The IANA standard MIME type of the source data.
21 | /// Examples:
22 | /// - image/png
23 | /// - image/jpeg
24 | /// If an unsupported MIME type is provided, an error will be returned. For a
25 | /// complete list of supported types, see [Supported file
26 | /// formats](https://ai.google.dev/gemini-api/docs/prompting_with_media#supported_file_formats).
27 | ///
28 | [JsonPropertyName("mimeType")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public string? MimeType { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Batches/InlinedEmbedContentResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Text.Json.Serialization;
3 | using GeminiDotnet.V1Beta.Models;
4 |
5 | namespace GeminiDotnet.V1Beta.Batches;
6 |
7 | ///
8 | /// The response to a single request in the batch.
9 | ///
10 | public sealed record InlinedEmbedContentResponse
11 | {
12 | ///
13 | /// Output only. The error encountered while processing the request.
14 | ///
15 | [JsonPropertyName("error")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public Status? Error { get; init; }
18 |
19 | ///
20 | /// Output only. The metadata associated with the request.
21 | ///
22 | [JsonPropertyName("metadata")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public JsonElement Metadata { get; init; }
25 |
26 | ///
27 | /// Output only. The response to the request.
28 | ///
29 | [JsonPropertyName("response")]
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
31 | public EmbedContentResponse? Response { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/GeminiDotnet.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 | true
6 | GeminiDotnet
7 | 0.18.1
8 | Ryan Buckley
9 | A lightweight, modern C# library for direct interaction with the Google Gemini API.
10 | AI, Gemini, Google Gemini, Google AI
11 | https://github.com/rabuckley/GeminiDotnet
12 | https://github.com/rabuckley/GeminiDotnet
13 | readme.md
14 | LICENCE
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/SafetyRatingProbability.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Required. The probability of harm for this content.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum SafetyRatingProbability
10 | {
11 | ///
12 | /// Probability is unspecified.
13 | ///
14 | [JsonStringEnumMemberName("HARM_PROBABILITY_UNSPECIFIED")]
15 | HarmProbabilityUnspecified,
16 |
17 | ///
18 | /// Content has a negligible chance of being unsafe.
19 | ///
20 | [JsonStringEnumMemberName("NEGLIGIBLE")]
21 | Negligible,
22 |
23 | ///
24 | /// Content has a low chance of being unsafe.
25 | ///
26 | [JsonStringEnumMemberName("LOW")]
27 | Low,
28 |
29 | ///
30 | /// Content has a medium chance of being unsafe.
31 | ///
32 | [JsonStringEnumMemberName("MEDIUM")]
33 | Medium,
34 |
35 | ///
36 | /// Content has a high chance of being unsafe.
37 | ///
38 | [JsonStringEnumMemberName("HIGH")]
39 | High,
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/SafetyRating.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Safety rating for a piece of content.
7 | /// The safety rating contains the category of harm and the
8 | /// harm probability level in that category for a piece of content.
9 | /// Content is classified for safety across a number of
10 | /// harm categories and the probability of the harm classification is included
11 | /// here.
12 | ///
13 | public sealed record SafetyRating
14 | {
15 | ///
16 | /// Was this content blocked because of this rating?
17 | ///
18 | [JsonPropertyName("blocked")]
19 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
20 | public bool? Blocked { get; init; }
21 |
22 | ///
23 | /// Required. The category for this rating.
24 | ///
25 | [JsonPropertyName("category")]
26 | public required HarmCategory Category { get; init; }
27 |
28 | ///
29 | /// Required. The probability of harm for this content.
30 | ///
31 | [JsonPropertyName("probability")]
32 | public required SafetyRatingProbability Probability { get; init; }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/FunctionDeclarationBehavior.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Optional. Specifies the function Behavior.
7 | /// Currently only supported by the BidiGenerateContent method.
8 | ///
9 | [JsonConverter(typeof(JsonStringEnumConverter))]
10 | public enum FunctionDeclarationBehavior
11 | {
12 | ///
13 | /// This value is unused.
14 | ///
15 | [JsonStringEnumMemberName("UNSPECIFIED")]
16 | Unspecified,
17 |
18 | ///
19 | /// If set, the system will wait to receive the function response before
20 | /// continuing the conversation.
21 | ///
22 | [JsonStringEnumMemberName("BLOCKING")]
23 | Blocking,
24 |
25 | ///
26 | /// If set, the system will not wait to receive the function response.
27 | /// Instead, it will attempt to handle function responses as they become
28 | /// available while maintaining the conversation between the user and the
29 | /// model.
30 | ///
31 | [JsonStringEnumMemberName("NON_BLOCKING")]
32 | NonBlocking,
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/OperationsClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1;
2 |
3 | internal sealed class OperationsClient : IOperationsClient
4 | {
5 | private readonly IGeminiRequester _requester;
6 |
7 | internal OperationsClient(IGeminiRequester requester)
8 | {
9 | ArgumentNullException.ThrowIfNull(requester);
10 | _requester = requester;
11 | }
12 |
13 | public Task ListOperationsAsync(
14 | string? filter = null,
15 | int? pageSize = null,
16 | string? pageToken = null,
17 | bool? returnPartialSuccess = null,
18 | CancellationToken cancellationToken = default)
19 | {
20 | const string path = "/v1/operations";
21 | return _requester.ExecuteAsync(HttpMethod.Get, path, cancellationToken);
22 | }
23 |
24 | public Task DeleteOperationByOperationsIdAsync(
25 | string operationsId,
26 | CancellationToken cancellationToken = default)
27 | {
28 | ArgumentNullException.ThrowIfNull(operationsId);
29 | var path = $"/v1/operations/{operationsId}";
30 | return _requester.ExecuteAsync(HttpMethod.Delete, path, cancellationToken);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ImportFileResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Response for ImportFile to import a File API file with a .
7 | ///
8 | public sealed record ImportFileResponse
9 | {
10 | ///
11 | /// Immutable. Identifier. The identifier for the imported.
12 | /// Example:
13 | /// fileSearchStores/my-file-search-store-123/documents/my-awesome-doc-123a456b789c
14 | ///
15 | [JsonPropertyName("documentName")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public string? DocumentName { get; init; }
18 |
19 | ///
20 | /// The name of the containing s.
21 | /// Example: fileSearchStores/my-file-search-store-123
22 | ///
23 | [JsonPropertyName("parent")]
24 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25 | public string? Parent { get; init; }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/SafetyRatingProbability.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Required. The probability of harm for this content.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum SafetyRatingProbability
10 | {
11 | ///
12 | /// Probability is unspecified.
13 | ///
14 | [JsonStringEnumMemberName("HARM_PROBABILITY_UNSPECIFIED")]
15 | HarmProbabilityUnspecified,
16 |
17 | ///
18 | /// Content has a negligible chance of being unsafe.
19 | ///
20 | [JsonStringEnumMemberName("NEGLIGIBLE")]
21 | Negligible,
22 |
23 | ///
24 | /// Content has a low chance of being unsafe.
25 | ///
26 | [JsonStringEnumMemberName("LOW")]
27 | Low,
28 |
29 | ///
30 | /// Content has a medium chance of being unsafe.
31 | ///
32 | [JsonStringEnumMemberName("MEDIUM")]
33 | Medium,
34 |
35 | ///
36 | /// Content has a high chance of being unsafe.
37 | ///
38 | [JsonStringEnumMemberName("HIGH")]
39 | High,
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Tests/ErrorResponseTests.cs:
--------------------------------------------------------------------------------
1 | using GeminiDotnet.Text.Json;
2 | using System.Diagnostics.CodeAnalysis;
3 | using System.Net;
4 | using System.Text.Json;
5 |
6 | namespace GeminiDotnet;
7 |
8 | public sealed class ErrorResponseTests
9 | {
10 | [Fact]
11 | public void Deserialize_WithErrorResponse()
12 | {
13 | // Arrange
14 | var typeInfo = V1BetaJsonContext.Default.GetTypeInfo();
15 |
16 | // Act
17 | var errorResponse = JsonSerializer.Deserialize(ErrorResponseJson, typeInfo);
18 |
19 | // Assert
20 | Assert.NotNull(errorResponse);
21 | Assert.Equal(HttpStatusCode.BadRequest, errorResponse.Error.StatusCode);
22 | Assert.Equal("Please use a valid role: user, model.", errorResponse.Error.Message);
23 | Assert.Equal("INVALID_ARGUMENT", errorResponse.Error.Status);
24 | }
25 |
26 | [StringSyntax(StringSyntaxAttribute.Json)]
27 | private const string ErrorResponseJson =
28 | """
29 | {
30 | "error": {
31 | "code": 400,
32 | "message": "Please use a valid role: user, model.",
33 | "status": "INVALID_ARGUMENT"
34 | }
35 | }
36 | """;
37 | }
38 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Content.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// The base structured datatype containing multi-part content of a message.
7 | /// A includes a field designating the producer of the
8 | /// and a field containing multi-part data that contains the content of
9 | /// the message turn.
10 | ///
11 | public sealed record Content
12 | {
13 | ///
14 | /// Ordered Parts that constitute a single message. Parts may have different
15 | /// MIME types.
16 | ///
17 | [JsonPropertyName("parts")]
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
19 | public IReadOnlyList? Parts { get; init; }
20 |
21 | ///
22 | /// Optional. The producer of the content. Must be either 'user' or 'model'.
23 | /// Useful to set for multi-turn conversations, otherwise can be left blank
24 | /// or unset.
25 | ///
26 | [JsonPropertyName("role")]
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
28 | public string? Role { get; init; }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/GeminiV1BetaClient.cs:
--------------------------------------------------------------------------------
1 | namespace GeminiDotnet.V1Beta;
2 |
3 | public sealed partial class GeminiV1BetaClient : IGeminiV1BetaClient
4 | {
5 | private readonly IGeminiRequester _requester;
6 |
7 | internal GeminiV1BetaClient(IGeminiRequester requester)
8 | {
9 | ArgumentNullException.ThrowIfNull(requester);
10 | _requester = requester;
11 | }
12 |
13 | public IBatchesClient Batches => field ??= new BatchesClient(_requester);
14 |
15 | public ICachedContentsClient CachedContents => field ??= new CachedContentsClient(_requester);
16 |
17 | public ICorporaClient Corpora => field ??= new CorporaClient(_requester);
18 |
19 | public IDynamicClient Dynamic => field ??= new DynamicClient(_requester);
20 |
21 | public IFilesClient Files => field ??= new FilesClient(_requester);
22 |
23 | public IFileSearchStoresClient FileSearchStores => field ??= new FileSearchStoresClient(_requester);
24 |
25 | public IGeneratedFilesClient GeneratedFiles => field ??= new GeneratedFilesClient(_requester);
26 |
27 | public IModelsClient Models => field ??= new ModelsClient(_requester);
28 |
29 | public ITunedModelsClient TunedModels => field ??= new TunedModelsClient(_requester);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/SafetyRating.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Safety rating for a piece of content.
7 | /// The safety rating contains the category of harm and the
8 | /// harm probability level in that category for a piece of content.
9 | /// Content is classified for safety across a number of
10 | /// harm categories and the probability of the harm classification is included
11 | /// here.
12 | ///
13 | public sealed record SafetyRating
14 | {
15 | ///
16 | /// Was this content blocked because of this rating?
17 | ///
18 | [JsonPropertyName("blocked")]
19 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
20 | public bool? Blocked { get; init; }
21 |
22 | ///
23 | /// Required. The category for this rating.
24 | ///
25 | [JsonPropertyName("category")]
26 | public required HarmCategory Category { get; init; }
27 |
28 | ///
29 | /// Required. The probability of harm for this content.
30 | ///
31 | [JsonPropertyName("probability")]
32 | public required SafetyRatingProbability Probability { get; init; }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/Content.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// The base structured datatype containing multi-part content of a message.
7 | /// A includes a field designating the producer of the
8 | /// and a field containing multi-part data that contains the content of
9 | /// the message turn.
10 | ///
11 | public sealed record Content
12 | {
13 | ///
14 | /// Ordered Parts that constitute a single message. Parts may have different
15 | /// MIME types.
16 | ///
17 | [JsonPropertyName("parts")]
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
19 | public IReadOnlyList? Parts { get; init; }
20 |
21 | ///
22 | /// Optional. The producer of the content. Must be either 'user' or 'model'.
23 | /// Useful to set for multi-turn conversations, otherwise can be left blank
24 | /// or unset.
25 | ///
26 | [JsonPropertyName("role")]
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
28 | public string? Role { get; init; }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/FunctionCallingConfiguration.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Configuration for specifying function calling behavior.
7 | ///
8 | public sealed record FunctionCallingConfiguration
9 | {
10 | ///
11 | /// Optional. A set of function names that, when provided, limits the functions the model
12 | /// will call.
13 | /// This should only be set when the Mode is ANY or VALIDATED. Function names
14 | /// should match [FunctionDeclaration.name]. When set, model will
15 | /// predict a function call from only allowed function names.
16 | ///
17 | [JsonPropertyName("allowedFunctionNames")]
18 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
19 | public IReadOnlyList? AllowedFunctionNames { get; init; }
20 |
21 | ///
22 | /// Optional. Specifies the mode in which function calling should execute. If
23 | /// unspecified, the default value will be set to AUTO.
24 | ///
25 | [JsonPropertyName("mode")]
26 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
27 | public FunctionCallingConfigMode? Mode { get; init; }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Examples/LoggingExample.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.AI;
2 | using Microsoft.Extensions.Logging;
3 |
4 | namespace GeminiDotnet.Extensions.AI.Examples;
5 |
6 | public sealed class LoggingExample
7 | {
8 | public static async Task ExecuteAsync(IChatClient geminiClient, CancellationToken cancellationToken)
9 | {
10 | var loggerFactory = LoggerFactory.Create(builder =>
11 | {
12 | builder.SetMinimumLevel(LogLevel.Trace);
13 | builder.AddConsole();
14 | });
15 |
16 | IChatClient client = new ChatClientBuilder(geminiClient)
17 | .UseLogging(loggerFactory,
18 | client => client.JsonSerializerOptions = GeminiJsonUtilities.DefaultOptions)
19 | .Build();
20 |
21 | var chatOptions = new ChatOptions { Tools = [new HostedCodeInterpreterTool()] };
22 |
23 | IList messages =
24 | [
25 | new(ChatRole.User,
26 | "What is the sum of the first 42 numbers of the fibonacci sequence? Write and execute a program to figure it out.")
27 | ];
28 |
29 | var response = await client.GetResponseAsync(messages, chatOptions, cancellationToken);
30 |
31 | Console.WriteLine(response.Text);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/UrlMetadataUrlRetrievalStatus.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Status of the url retrieval.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum UrlMetadataUrlRetrievalStatus
10 | {
11 | ///
12 | /// Default value. This value is unused.
13 | ///
14 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Url retrieval is successful.
19 | ///
20 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_SUCCESS")]
21 | Success,
22 |
23 | ///
24 | /// Url retrieval is failed due to error.
25 | ///
26 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_ERROR")]
27 | Error,
28 |
29 | ///
30 | /// Url retrieval is failed because the content is behind paywall.
31 | ///
32 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_PAYWALL")]
33 | Paywall,
34 |
35 | ///
36 | /// Url retrieval is failed because the content is unsafe.
37 | ///
38 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_UNSAFE")]
39 | Unsafe,
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/ThinkingConfigThinkingLevel.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta;
4 |
5 | ///
6 | /// Optional. Controls the maximum depth of the model's internal reasoning process before
7 | /// it produces a response. If not specified, the default is HIGH. Recommended
8 | /// for Gemini 3 or later models. Use with earlier models results in an error.
9 | ///
10 | [JsonConverter(typeof(JsonStringEnumConverter))]
11 | public enum ThinkingConfigThinkingLevel
12 | {
13 | ///
14 | /// Default value.
15 | ///
16 | [JsonStringEnumMemberName("THINKING_LEVEL_UNSPECIFIED")]
17 | Unspecified,
18 |
19 | ///
20 | /// Little to no thinking.
21 | ///
22 | [JsonStringEnumMemberName("MINIMAL")]
23 | Minimal,
24 |
25 | ///
26 | /// Low thinking level.
27 | ///
28 | [JsonStringEnumMemberName("LOW")]
29 | Low,
30 |
31 | ///
32 | /// Medium thinking level.
33 | ///
34 | [JsonStringEnumMemberName("MEDIUM")]
35 | Medium,
36 |
37 | ///
38 | /// High thinking level.
39 | ///
40 | [JsonStringEnumMemberName("HIGH")]
41 | High,
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/FileSearch.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// The FileSearch tool that retrieves knowledge from Semantic Retrieval corpora.
7 | /// Files are imported to Semantic Retrieval corpora using the ImportFile API.
8 | ///
9 | public sealed record FileSearch
10 | {
11 | ///
12 | /// Required. The names of the file_search_stores to retrieve from.
13 | /// Example: fileSearchStores/my-file-search-store-123
14 | ///
15 | [JsonPropertyName("fileSearchStoreNames")]
16 | public required IReadOnlyList FileSearchStoreNames { get; init; }
17 |
18 | ///
19 | /// Optional. Metadata filter to apply to the semantic retrieval documents and chunks.
20 | ///
21 | [JsonPropertyName("metadataFilter")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public string? MetadataFilter { get; init; }
24 |
25 | ///
26 | /// Optional. The number of semantic retrieval chunks to retrieve.
27 | ///
28 | [JsonPropertyName("topK")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public int? TopK { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/TuningSnapshot.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// Record for a single tuning step.
7 | ///
8 | public sealed record TuningSnapshot
9 | {
10 | ///
11 | /// Output only. The timestamp when this metric was computed.
12 | ///
13 | [JsonPropertyName("computeTime")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public DateTimeOffset? ComputeTime { get; init; }
16 |
17 | ///
18 | /// Output only. The epoch this step was part of.
19 | ///
20 | [JsonPropertyName("epoch")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public int? Epoch { get; init; }
23 |
24 | ///
25 | /// Output only. The mean loss of the training examples for this step.
26 | ///
27 | [JsonPropertyName("meanLoss")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public float? MeanLoss { get; init; }
30 |
31 | ///
32 | /// Output only. The tuning step.
33 | ///
34 | [JsonPropertyName("step")]
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
36 | public int? Step { get; init; }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/Interval.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | ///
6 | /// Represents a time interval, encoded as a Timestamp start (inclusive) and a
7 | /// Timestamp end (exclusive).
8 | /// The start must be less than or equal to the end.
9 | /// When the start equals the end, the interval is empty (matches no time).
10 | /// When both start and end are unspecified, the interval matches any time.
11 | ///
12 | public sealed record Interval
13 | {
14 | ///
15 | /// Optional. Exclusive end of the interval.
16 | /// If specified, a Timestamp matching this interval will have to be before the
17 | /// end.
18 | ///
19 | [JsonPropertyName("endTime")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public DateTimeOffset? EndTime { get; init; }
22 |
23 | ///
24 | /// Optional. Inclusive start of the interval.
25 | /// If specified, a Timestamp matching this interval will have to be the same
26 | /// or after the start.
27 | ///
28 | [JsonPropertyName("startTime")]
29 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30 | public DateTimeOffset? StartTime { get; init; }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/CustomMetadata.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// User provided metadata stored as key-value pairs.
7 | ///
8 | public sealed record CustomMetadata
9 | {
10 | ///
11 | /// Required. The key of the metadata to store.
12 | ///
13 | [JsonPropertyName("key")]
14 | public required string Key { get; init; }
15 |
16 | ///
17 | /// The numeric value of the metadata to store.
18 | ///
19 | [JsonPropertyName("numericValue")]
20 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21 | public float? NumericValue { get; init; }
22 |
23 | ///
24 | /// The StringList value of the metadata to store.
25 | ///
26 | [JsonPropertyName("stringListValue")]
27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
28 | public StringList? StringListValue { get; init; }
29 |
30 | ///
31 | /// The string value of the metadata to store.
32 | ///
33 | [JsonPropertyName("stringValue")]
34 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
35 | public string? StringValue { get; init; }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/tests/GeminiDotnet.Extensions.AI.Tests/GeminiEmbeddingGeneratorTests.cs:
--------------------------------------------------------------------------------
1 | using GeminiDotnet.Testing;
2 | using Microsoft.Extensions.AI;
3 |
4 | namespace GeminiDotnet.Extensions.AI;
5 |
6 | [IntegrationTest]
7 | public sealed class GeminiEmbeddingGeneratorTests
8 | {
9 | private readonly ITestOutputHelper _output;
10 |
11 | public GeminiEmbeddingGeneratorTests(ITestOutputHelper output)
12 | {
13 | _output = output;
14 | }
15 |
16 | [Theory]
17 | [InlineData("text-embedding-004")]
18 | [InlineData("gemini-embedding-001")]
19 | public async Task GenerateAsync_ShouldDoReturnEmbeddings(string model)
20 | {
21 | // Arrange
22 | var cancellationToken = TestContext.Current.CancellationToken;
23 | var options = new GeminiClientOptions { ApiKey = TestConfiguration.GetApiKey() };
24 | var client = new GeminiEmbeddingGenerator(options);
25 |
26 | var embeddingOptions = new EmbeddingGenerationOptions { ModelId = model };
27 |
28 | // Act
29 | var embeddings = await client.GenerateAsync(["Hello, world!"], embeddingOptions, cancellationToken);
30 |
31 | // Assert
32 | Assert.NotNull(embeddings);
33 | Assert.NotEmpty(embeddings);
34 | Assert.Equal(768, embeddings.First().Vector.Span.Length);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/Models/UrlMetadataUrlRetrievalStatus.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.Models;
4 |
5 | ///
6 | /// Status of the url retrieval.
7 | ///
8 | [JsonConverter(typeof(JsonStringEnumConverter))]
9 | public enum UrlMetadataUrlRetrievalStatus
10 | {
11 | ///
12 | /// Default value. This value is unused.
13 | ///
14 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_UNSPECIFIED")]
15 | Unspecified,
16 |
17 | ///
18 | /// Url retrieval is successful.
19 | ///
20 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_SUCCESS")]
21 | Success,
22 |
23 | ///
24 | /// Url retrieval is failed due to error.
25 | ///
26 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_ERROR")]
27 | Error,
28 |
29 | ///
30 | /// Url retrieval is failed because the content is behind paywall.
31 | ///
32 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_PAYWALL")]
33 | Paywall,
34 |
35 | ///
36 | /// Url retrieval is failed because the content is unsafe.
37 | ///
38 | [JsonStringEnumMemberName("URL_RETRIEVAL_STATUS_UNSAFE")]
39 | Unsafe,
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/TunedModels/TuningSnapshot.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.TunedModels;
4 |
5 | ///
6 | /// Record for a single tuning step.
7 | ///
8 | public sealed record TuningSnapshot
9 | {
10 | ///
11 | /// Output only. The timestamp when this metric was computed.
12 | ///
13 | [JsonPropertyName("computeTime")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public DateTimeOffset? ComputeTime { get; init; }
16 |
17 | ///
18 | /// Output only. The epoch this step was part of.
19 | ///
20 | [JsonPropertyName("epoch")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public int? Epoch { get; init; }
23 |
24 | ///
25 | /// Output only. The mean loss of the training examples for this step.
26 | ///
27 | [JsonPropertyName("meanLoss")]
28 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
29 | public float? MeanLoss { get; init; }
30 |
31 | ///
32 | /// Output only. The tuning step.
33 | ///
34 | [JsonPropertyName("step")]
35 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
36 | public int? Step { get; init; }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/ListOperationsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1;
4 |
5 | ///
6 | /// The response message for Operations.ListOperations.
7 | ///
8 | public sealed record ListOperationsResponse
9 | {
10 | ///
11 | /// The standard List next-page token.
12 | ///
13 | [JsonPropertyName("nextPageToken")]
14 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
15 | public string? NextPageToken { get; init; }
16 |
17 | ///
18 | /// A list of operations that matches the specified filter in the request.
19 | ///
20 | [JsonPropertyName("operations")]
21 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22 | public IReadOnlyList? Operations { get; init; }
23 |
24 | ///
25 | /// Unordered list. Unreachable resources. Populated when the request sets
26 | /// ListOperationsRequest.return_partial_success and reads across
27 | /// collections. For example, when attempting to list all resources across all
28 | /// supported locations.
29 | ///
30 | [JsonPropertyName("unreachable")]
31 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
32 | public IReadOnlyList? Unreachable { get; init; }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/FileSearchStores/ImportFileRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.FileSearchStores;
4 |
5 | ///
6 | /// Request for ImportFile to import a File API file with a .
7 | /// LINT.IfChange(ImportFileRequest)
8 | ///
9 | public sealed record ImportFileRequest
10 | {
11 | ///
12 | /// Optional. Config for telling the service how to chunk the file.
13 | /// If not provided, the service will use default parameters.
14 | ///
15 | [JsonPropertyName("chunkingConfig")]
16 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
17 | public ChunkingConfiguration? ChunkingConfiguration { get; init; }
18 |
19 | ///
20 | /// Custom metadata to be associated with the file.
21 | ///
22 | [JsonPropertyName("customMetadata")]
23 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24 | public IReadOnlyList? CustomMetadata { get; init; }
25 |
26 | ///
27 | /// Required. The name of the to import.
28 | /// Example: files/abc-123
29 | ///
30 | [JsonPropertyName("fileName")]
31 | public required string FileName { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet.Extensions.AI/GeminiDotnet.Extensions.AI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 | true
6 | GeminiDotnet.Extensions.AI
7 | 0.18.1
8 | Ryan Buckley
9 | A lightweight, modern implementation of the Microsoft.Extensions.AI.Abstractions APIs for interacting with Google Gemini models.
10 | AI, Gemini, Microsoft.Extensions.AI
11 | https://github.com/rabuckley/GeminiDotnet
12 | https://github.com/rabuckley/GeminiDotnet
13 | readme.md
14 | LICENCE
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1/Models/CountTokensResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1.Models;
4 |
5 | ///
6 | /// A response from CountTokens.
7 | /// It returns the model's token_count for the prompt.
8 | ///
9 | public sealed record CountTokensResponse
10 | {
11 | ///
12 | /// Output only. List of modalities that were processed in the cached content.
13 | ///
14 | [JsonPropertyName("cacheTokensDetails")]
15 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
16 | public IReadOnlyList? CacheTokensDetails { get; init; }
17 |
18 | ///
19 | /// Output only. List of modalities that were processed in the request input.
20 | ///
21 | [JsonPropertyName("promptTokensDetails")]
22 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23 | public IReadOnlyList? PromptTokensDetails { get; init; }
24 |
25 | ///
26 | /// The number of tokens that the tokenizes the prompt into. Always
27 | /// non-negative.
28 | ///
29 | [JsonPropertyName("totalTokens")]
30 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
31 | public int? TotalTokens { get; init; }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/src/GeminiDotnet/V1Beta/CachedContents/Type.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace GeminiDotnet.V1Beta.CachedContents;
4 |
5 | [JsonConverter(typeof(JsonStringEnumConverter))]
6 | public enum Type
7 | {
8 | ///
9 | /// Not specified, should not be used.
10 | ///
11 | [JsonStringEnumMemberName("TYPE_UNSPECIFIED")]
12 | Unspecified,
13 |
14 | ///
15 | /// String type.
16 | ///
17 | [JsonStringEnumMemberName("STRING")]
18 | String,
19 |
20 | ///
21 | /// Number type.
22 | ///
23 | [JsonStringEnumMemberName("NUMBER")]
24 | Number,
25 |
26 | ///
27 | /// Integer type.
28 | ///
29 | [JsonStringEnumMemberName("INTEGER")]
30 | Integer,
31 |
32 | ///
33 | /// Boolean type.
34 | ///
35 | [JsonStringEnumMemberName("BOOLEAN")]
36 | Boolean,
37 |
38 | ///
39 | /// Array type.
40 | ///
41 | [JsonStringEnumMemberName("ARRAY")]
42 | Array,
43 |
44 | ///
45 | /// Object type.
46 | ///
47 | [JsonStringEnumMemberName("OBJECT")]
48 | Object,
49 |
50 | ///
51 | /// Null type.
52 | ///
53 | [JsonStringEnumMemberName("NULL")]
54 | Null,
55 | }
56 |
57 |
--------------------------------------------------------------------------------