Discovery Engine v1 API - Class GroundedGenerationServiceClient (1.5.0)

public abstract class GroundedGenerationServiceClient

Reference documentation and code samples for the Discovery Engine v1 API class GroundedGenerationServiceClient.

GroundedGenerationService client wrapper, for convenient use.

Inheritance

object > GroundedGenerationServiceClient

Namespace

Google.Cloud.DiscoveryEngine.V1

Assembly

Google.Cloud.DiscoveryEngine.V1.dll

Remarks

Service for grounded generation.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the GroundedGenerationService service, which is a host of "discoveryengine.googleapis.com" and a port of 443.

Property Value
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default GroundedGenerationService scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

The default GroundedGenerationService scopes are:

GrpcClient

public virtual GroundedGenerationService.GroundedGenerationServiceClient GrpcClient { get; }

The underlying gRPC GroundedGenerationService client

Property Value
Type Description
GroundedGenerationServiceGroundedGenerationServiceClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
Type Description
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
ServiceMetadata

Methods

CheckGrounding(CheckGroundingRequest, CallSettings)

public virtual CheckGroundingResponse CheckGrounding(CheckGroundingRequest request, CallSettings callSettings = null)

Performs a grounding check.

Parameters
Name Description
request CheckGroundingRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
CheckGroundingResponse

The RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = GroundedGenerationServiceClient.Create();
// Initialize request argument(s)
CheckGroundingRequest request = new CheckGroundingRequest
{
    GroundingConfigAsGroundingConfigName = GroundingConfigName.FromProjectLocationGroundingConfig("[PROJECT]", "[LOCATION]", "[GROUNDING_CONFIG]"),
    AnswerCandidate = "",
    Facts =
    {
        new GroundingFact(),
    },
    GroundingSpec = new CheckGroundingSpec(),
    UserLabels = { { "", "" }, },
};
// Make the request
CheckGroundingResponse response = groundedGenerationServiceClient.CheckGrounding(request);

CheckGroundingAsync(CheckGroundingRequest, CallSettings)

public virtual Task<CheckGroundingResponse> CheckGroundingAsync(CheckGroundingRequest request, CallSettings callSettings = null)

Performs a grounding check.

Parameters
Name Description
request CheckGroundingRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskCheckGroundingResponse

A Task containing the RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = await GroundedGenerationServiceClient.CreateAsync();
// Initialize request argument(s)
CheckGroundingRequest request = new CheckGroundingRequest
{
    GroundingConfigAsGroundingConfigName = GroundingConfigName.FromProjectLocationGroundingConfig("[PROJECT]", "[LOCATION]", "[GROUNDING_CONFIG]"),
    AnswerCandidate = "",
    Facts =
    {
        new GroundingFact(),
    },
    GroundingSpec = new CheckGroundingSpec(),
    UserLabels = { { "", "" }, },
};
// Make the request
CheckGroundingResponse response = await groundedGenerationServiceClient.CheckGroundingAsync(request);

CheckGroundingAsync(CheckGroundingRequest, CancellationToken)

public virtual Task<CheckGroundingResponse> CheckGroundingAsync(CheckGroundingRequest request, CancellationToken cancellationToken)

Performs a grounding check.

Parameters
Name Description
request CheckGroundingRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskCheckGroundingResponse

A Task containing the RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = await GroundedGenerationServiceClient.CreateAsync();
// Initialize request argument(s)
CheckGroundingRequest request = new CheckGroundingRequest
{
    GroundingConfigAsGroundingConfigName = GroundingConfigName.FromProjectLocationGroundingConfig("[PROJECT]", "[LOCATION]", "[GROUNDING_CONFIG]"),
    AnswerCandidate = "",
    Facts =
    {
        new GroundingFact(),
    },
    GroundingSpec = new CheckGroundingSpec(),
    UserLabels = { { "", "" }, },
};
// Make the request
CheckGroundingResponse response = await groundedGenerationServiceClient.CheckGroundingAsync(request);

Create()

public static GroundedGenerationServiceClient Create()

Synchronously creates a GroundedGenerationServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use GroundedGenerationServiceClientBuilder.

Returns
Type Description
GroundedGenerationServiceClient

The created GroundedGenerationServiceClient.

CreateAsync(CancellationToken)

public static Task<GroundedGenerationServiceClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a GroundedGenerationServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use GroundedGenerationServiceClientBuilder.

Parameter
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
TaskGroundedGenerationServiceClient

The task representing the created GroundedGenerationServiceClient.

GenerateGroundedContent(GenerateGroundedContentRequest, CallSettings)

public virtual GenerateGroundedContentResponse GenerateGroundedContent(GenerateGroundedContentRequest request, CallSettings callSettings = null)

Generates grounded content.

Parameters
Name Description
request GenerateGroundedContentRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
GenerateGroundedContentResponse

The RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = GroundedGenerationServiceClient.Create();
// Initialize request argument(s)
GenerateGroundedContentRequest request = new GenerateGroundedContentRequest
{
    LocationAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
    Contents =
    {
        new GroundedGenerationContent(),
    },
    GenerationSpec = new GenerateGroundedContentRequest.Types.GenerationSpec(),
    GroundingSpec = new GenerateGroundedContentRequest.Types.GroundingSpec(),
    SystemInstruction = new GroundedGenerationContent(),
    UserLabels = { { "", "" }, },
};
// Make the request
GenerateGroundedContentResponse response = groundedGenerationServiceClient.GenerateGroundedContent(request);

GenerateGroundedContentAsync(GenerateGroundedContentRequest, CallSettings)

public virtual Task<GenerateGroundedContentResponse> GenerateGroundedContentAsync(GenerateGroundedContentRequest request, CallSettings callSettings = null)

Generates grounded content.

Parameters
Name Description
request GenerateGroundedContentRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskGenerateGroundedContentResponse

A Task containing the RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = await GroundedGenerationServiceClient.CreateAsync();
// Initialize request argument(s)
GenerateGroundedContentRequest request = new GenerateGroundedContentRequest
{
    LocationAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
    Contents =
    {
        new GroundedGenerationContent(),
    },
    GenerationSpec = new GenerateGroundedContentRequest.Types.GenerationSpec(),
    GroundingSpec = new GenerateGroundedContentRequest.Types.GroundingSpec(),
    SystemInstruction = new GroundedGenerationContent(),
    UserLabels = { { "", "" }, },
};
// Make the request
GenerateGroundedContentResponse response = await groundedGenerationServiceClient.GenerateGroundedContentAsync(request);

GenerateGroundedContentAsync(GenerateGroundedContentRequest, CancellationToken)

public virtual Task<GenerateGroundedContentResponse> GenerateGroundedContentAsync(GenerateGroundedContentRequest request, CancellationToken cancellationToken)

Generates grounded content.

Parameters
Name Description
request GenerateGroundedContentRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskGenerateGroundedContentResponse

A Task containing the RPC response.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = await GroundedGenerationServiceClient.CreateAsync();
// Initialize request argument(s)
GenerateGroundedContentRequest request = new GenerateGroundedContentRequest
{
    LocationAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
    Contents =
    {
        new GroundedGenerationContent(),
    },
    GenerationSpec = new GenerateGroundedContentRequest.Types.GenerationSpec(),
    GroundingSpec = new GenerateGroundedContentRequest.Types.GroundingSpec(),
    SystemInstruction = new GroundedGenerationContent(),
    UserLabels = { { "", "" }, },
};
// Make the request
GenerateGroundedContentResponse response = await groundedGenerationServiceClient.GenerateGroundedContentAsync(request);

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
Type Description
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.

StreamGenerateGroundedContent(CallSettings, BidirectionalStreamingSettings)

public virtual GroundedGenerationServiceClient.StreamGenerateGroundedContentStream StreamGenerateGroundedContent(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Generates grounded content in a streaming fashion.

Parameters
Name Description
callSettings CallSettings

If not null, applies overrides to this RPC call.

streamingSettings BidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
Type Description
GroundedGenerationServiceClientStreamGenerateGroundedContentStream

The client-server stream.

Example
// Create client
GroundedGenerationServiceClient groundedGenerationServiceClient = GroundedGenerationServiceClient.Create();
// Initialize streaming call, retrieving the stream object
using GroundedGenerationServiceClient.StreamGenerateGroundedContentStream response = groundedGenerationServiceClient.StreamGenerateGroundedContent();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<GenerateGroundedContentResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        GenerateGroundedContentResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    GenerateGroundedContentRequest request = new GenerateGroundedContentRequest
    {
        LocationAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
        Contents =
        {
            new GroundedGenerationContent(),
        },
        GenerationSpec = new GenerateGroundedContentRequest.Types.GenerationSpec(),
        GroundingSpec = new GenerateGroundedContentRequest.Types.GroundingSpec(),
        SystemInstruction = new GroundedGenerationContent(),
        UserLabels = { { "", "" }, },
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;