Search in sources :

Example 26 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class EndpointServiceClientTest method listEndpointsTest.

@Test
public void listEndpointsTest() throws Exception {
    Endpoint responsesElement = Endpoint.newBuilder().build();
    ListEndpointsResponse expectedResponse = ListEndpointsResponse.newBuilder().setNextPageToken("").addAllEndpoints(Arrays.asList(responsesElement)).build();
    mockEndpointService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent);
    List<Endpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEndpointsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockEndpointService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEndpointsRequest actualRequest = ((ListEndpointsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListEndpointsPagedResponse(com.google.cloud.aiplatform.v1beta1.EndpointServiceClient.ListEndpointsPagedResponse) Test(org.junit.Test)

Example 27 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class JobServiceClientTest method listCustomJobsTest.

@Test
public void listCustomJobsTest() throws Exception {
    CustomJob responsesElement = CustomJob.newBuilder().build();
    ListCustomJobsResponse expectedResponse = ListCustomJobsResponse.newBuilder().setNextPageToken("").addAllCustomJobs(Arrays.asList(responsesElement)).build();
    mockJobService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListCustomJobsPagedResponse pagedListResponse = client.listCustomJobs(parent);
    List<CustomJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCustomJobsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockJobService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCustomJobsRequest actualRequest = ((ListCustomJobsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListCustomJobsPagedResponse(com.google.cloud.aiplatform.v1beta1.JobServiceClient.ListCustomJobsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 28 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project java-aiplatform by googleapis.

the class FeaturestoreServiceClientTest method searchFeaturesTest.

@Test
public void searchFeaturesTest() throws Exception {
    Feature responsesElement = Feature.newBuilder().build();
    SearchFeaturesResponse expectedResponse = SearchFeaturesResponse.newBuilder().setNextPageToken("").addAllFeatures(Arrays.asList(responsesElement)).build();
    mockFeaturestoreService.addResponse(expectedResponse);
    LocationName location = LocationName.of("[PROJECT]", "[LOCATION]");
    SearchFeaturesPagedResponse pagedListResponse = client.searchFeatures(location);
    List<Feature> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFeaturesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFeaturestoreService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SearchFeaturesRequest actualRequest = ((SearchFeaturesRequest) actualRequests.get(0));
    Assert.assertEquals(location.toString(), actualRequest.getLocation());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SearchFeaturesPagedResponse(com.google.cloud.aiplatform.v1beta1.FeaturestoreServiceClient.SearchFeaturesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 29 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method translateTextWithGlossary.

// [END translate_get_glossary_beta]
/**
 * Translates a given text using a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 * @param text - Text to be translated. e.g. "Hello World!"
 * @param sourceLanguageCode - Language code of text. e.g. "en"
 * @param targetLanguageCode - Language code for translation. e.g. "sr"
 */
// [START translate_translate_text_with_glossary_beta]
static TranslateTextResponse translateTextWithGlossary(String projectId, String location, String name, String text, String sourceLanguageCode, String targetLanguageCode) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        TranslateTextGlossaryConfig translateTextGlossaryConfig = TranslateTextGlossaryConfig.newBuilder().setGlossary(glossaryName.toString()).build();
        TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).setGlossaryConfig(translateTextGlossaryConfig).build();
        // Call the API
        TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
        System.out.format("Translated text: %s", response.getGlossaryTranslationsList().get(0).getTranslatedText());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) BatchTranslateTextRequest(com.google.cloud.translate.v3beta1.BatchTranslateTextRequest) TranslateTextRequest(com.google.cloud.translate.v3beta1.TranslateTextRequest) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName) TranslateTextGlossaryConfig(com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig) TranslateTextResponse(com.google.cloud.translate.v3beta1.TranslateTextResponse) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 30 with LocationName

use of com.google.cloud.aiplatform.v1beta1.LocationName in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method detectLanguageOfText.

// [END translate_list_language_names_beta]
/**
 * Detects the language of a given text.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param text - Text for detection
 */
// [START translate_detect_language_beta]
static DetectLanguageResponse detectLanguageOfText(String projectId, String location, String text) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        DetectLanguageRequest detectLanguageRequest = DetectLanguageRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setContent(text).build();
        // Call the API
        DetectLanguageResponse response = translationServiceClient.detectLanguage(detectLanguageRequest);
        System.out.format("Detected Language Code: %s", response.getLanguages(0).getLanguageCode());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) DetectLanguageResponse(com.google.cloud.translate.v3beta1.DetectLanguageResponse) DetectLanguageRequest(com.google.cloud.translate.v3beta1.DetectLanguageRequest) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Aggregations

Test (org.junit.Test)54 AbstractMessage (com.google.protobuf.AbstractMessage)37 LocationName (com.google.cloud.aiplatform.v1.LocationName)36 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 LocationName (com.google.cloud.translate.v3beta1.LocationName)18 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)15 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)15 Value (com.google.protobuf.Value)15 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)14 Model (com.google.cloud.aiplatform.v1.Model)14 StatusRuntimeException (io.grpc.StatusRuntimeException)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)13 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)13 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13