public abstract class PredictionServiceClient
Reference documentation and code samples for the Recommendations AI v1beta1 API class PredictionServiceClient.
PredictionService client wrapper, for convenient use.
Derived Types
Namespace
Google.Cloud.RecommendationEngine.V1Beta1Assembly
Google.Cloud.RecommendationEngine.V1Beta1.dll
Remarks
Service for making recommendation prediction.
Properties
DefaultEndpoint
public static string DefaultEndpoint { get; }
The default endpoint for the PredictionService service, which is a host of "recommendationengine.googleapis.com" and a port of 443.
Property Value | |
---|---|
Type | Description |
String |
DefaultScopes
public static IReadOnlyList<string> DefaultScopes { get; }
The default PredictionService scopes.
Property Value | |
---|---|
Type | Description |
IReadOnlyList<String> |
The default PredictionService scopes are:
GrpcClient
public virtual PredictionService.PredictionServiceClient GrpcClient { get; }
The underlying gRPC PredictionService client
Property Value | |
---|---|
Type | Description |
PredictionService.PredictionServiceClient |
ServiceMetadata
public static ServiceMetadata ServiceMetadata { get; }
The service metadata associated with this client type.
Property Value | |
---|---|
Type | Description |
ServiceMetadata |
Methods
Create()
public static PredictionServiceClient Create()
Synchronously creates a PredictionServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use PredictionServiceClientBuilder.
Returns | |
---|---|
Type | Description |
PredictionServiceClient | The created PredictionServiceClient. |
CreateAsync(CancellationToken)
public static Task<PredictionServiceClient> CreateAsync(CancellationToken cancellationToken = default(CancellationToken))
Asynchronously creates a PredictionServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use PredictionServiceClientBuilder.
Parameter | |
---|---|
Name | Description |
cancellationToken | CancellationToken The CancellationToken to use while creating the client. |
Returns | |
---|---|
Type | Description |
Task<PredictionServiceClient> | The task representing the created PredictionServiceClient. |
Predict(PlacementName, UserEvent, String, Nullable<Int32>, CallSettings)
public virtual PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> Predict(PlacementName name, UserEvent userEvent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
name | PlacementName Required. Full resource name of the format:
We currently support three placements with the following IDs by default:
The full list of available placements can be seen at https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard |
userEvent | UserEvent Required. Context about the user, what they are looking at and what action they took to trigger the predict request. Note that this user event detail won't be ingested to userEvent logs. Thus, a separate userEvent write request is required for event logging. |
pageToken | String The token returned from the previous request. A value of |
pageSize | Nullable<Int32> The size of page to request. The response will not be larger than this, but may be smaller. A value of
|
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
// Initialize request argument(s)
PlacementName name = PlacementName.FromProjectLocationCatalogEventStorePlacement("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]");
UserEvent userEvent = new UserEvent();
// Make the request
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.Predict(name, userEvent);
// Iterate over all response items, lazily performing RPCs as required
foreach (PredictResponse.Types.PredictionResult item in response)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (PredictResponse page in response.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
Predict(PredictRequest, CallSettings)
public virtual PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> Predict(PredictRequest request, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
request | PredictRequest 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 |
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
// Initialize request argument(s)
PredictRequest request = new PredictRequest
{
PlacementName = PlacementName.FromProjectLocationCatalogEventStorePlacement("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"),
UserEvent = new UserEvent(),
Filter = "",
DryRun = false,
Params = { { "", new Value() }, },
Labels = { { "", "" }, },
};
// Make the request
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.Predict(request);
// Iterate over all response items, lazily performing RPCs as required
foreach (PredictResponse.Types.PredictionResult item in response)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (PredictResponse page in response.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
Predict(String, UserEvent, String, Nullable<Int32>, CallSettings)
public virtual PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> Predict(string name, UserEvent userEvent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
name | String Required. Full resource name of the format:
We currently support three placements with the following IDs by default:
The full list of available placements can be seen at https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard |
userEvent | UserEvent Required. Context about the user, what they are looking at and what action they took to trigger the predict request. Note that this user event detail won't be ingested to userEvent logs. Thus, a separate userEvent write request is required for event logging. |
pageToken | String The token returned from the previous request. A value of |
pageSize | Nullable<Int32> The size of page to request. The response will not be larger than this, but may be smaller. A value of
|
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
// Initialize request argument(s)
string name = "projects/[PROJECT]/locations/[LOCATION]/catalogs/[CATALOG]/eventStores/[EVENT_STORE]/placements/[PLACEMENT]";
UserEvent userEvent = new UserEvent();
// Make the request
PagedEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.Predict(name, userEvent);
// Iterate over all response items, lazily performing RPCs as required
foreach (PredictResponse.Types.PredictionResult item in response)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (PredictResponse page in response.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
PredictAsync(PlacementName, UserEvent, String, Nullable<Int32>, CallSettings)
public virtual PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> PredictAsync(PlacementName name, UserEvent userEvent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
name | PlacementName Required. Full resource name of the format:
We currently support three placements with the following IDs by default:
The full list of available placements can be seen at https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard |
userEvent | UserEvent Required. Context about the user, what they are looking at and what action they took to trigger the predict request. Note that this user event detail won't be ingested to userEvent logs. Thus, a separate userEvent write request is required for event logging. |
pageToken | String The token returned from the previous request. A value of |
pageSize | Nullable<Int32> The size of page to request. The response will not be larger than this, but may be smaller. A value of
|
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable asynchronous sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();
// Initialize request argument(s)
PlacementName name = PlacementName.FromProjectLocationCatalogEventStorePlacement("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]");
UserEvent userEvent = new UserEvent();
// Make the request
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.PredictAsync(name, userEvent);
// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((PredictResponse.Types.PredictionResult item) =>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((PredictResponse page) =>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
PredictAsync(PredictRequest, CallSettings)
public virtual PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> PredictAsync(PredictRequest request, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
request | PredictRequest 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 |
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable asynchronous sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();
// Initialize request argument(s)
PredictRequest request = new PredictRequest
{
PlacementName = PlacementName.FromProjectLocationCatalogEventStorePlacement("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"),
UserEvent = new UserEvent(),
Filter = "",
DryRun = false,
Params = { { "", new Value() }, },
Labels = { { "", "" }, },
};
// Make the request
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.PredictAsync(request);
// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((PredictResponse.Types.PredictionResult item) =>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((PredictResponse page) =>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
PredictAsync(String, UserEvent, String, Nullable<Int32>, CallSettings)
public virtual PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> PredictAsync(string name, UserEvent userEvent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)
Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the [PredictionApiKeyRegistry][google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry] service. Learn more.
Parameters | |
---|---|
Name | Description |
name | String Required. Full resource name of the format:
We currently support three placements with the following IDs by default:
The full list of available placements can be seen at https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard |
userEvent | UserEvent Required. Context about the user, what they are looking at and what action they took to trigger the predict request. Note that this user event detail won't be ingested to userEvent logs. Thus, a separate userEvent write request is required for event logging. |
pageToken | String The token returned from the previous request. A value of |
pageSize | Nullable<Int32> The size of page to request. The response will not be larger than this, but may be smaller. A value of
|
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> | A pageable asynchronous sequence of PredictResponse.Types.PredictionResult resources. |
// Create client
PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();
// Initialize request argument(s)
string name = "projects/[PROJECT]/locations/[LOCATION]/catalogs/[CATALOG]/eventStores/[EVENT_STORE]/placements/[PLACEMENT]";
UserEvent userEvent = new UserEvent();
// Make the request
PagedAsyncEnumerable<PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.PredictAsync(name, userEvent);
// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((PredictResponse.Types.PredictionResult item) =>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((PredictResponse page) =>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach (PredictResponse.Types.PredictionResult item in page)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<PredictResponse.Types.PredictionResult> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (PredictResponse.Types.PredictionResult item in singlePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;
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. |
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.