use of com.google.type.Money in project java-aiplatform by googleapis.
the class CreateDataLabelingJobImageSample method createDataLabelingJobImage.
static void createDataLabelingJobImage(String project, String displayName, String datasetId, String instructionUri, String annotationSpec) throws IOException {
JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
// the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
String location = "us-central1";
LocationName locationName = LocationName.of(project, location);
String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
Value.Builder annotationSpecValue = Value.newBuilder();
JsonFormat.parser().merge(jsonString, annotationSpecValue);
DatasetName datasetName = DatasetName.of(project, location, datasetId);
DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "image_classification.yaml").addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
System.out.println("Create Data Labeling Job Image Response");
System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
System.out.println("\tAnnotation Level");
System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
}
Money money = dataLabelingJobResponse.getCurrentSpend();
System.out.println("\tCurrent Spend");
System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
System.out.format("\t\tUnits: %s\n", money.getUnits());
System.out.format("\t\tNanos: %s\n", money.getNanos());
}
}
use of com.google.type.Money in project java-aiplatform by googleapis.
the class CreateDataLabelingJobSample method createDataLabelingJob.
static void createDataLabelingJob(String project, String displayName, String datasetId, String instructionUri, String inputsSchemaUri, String annotationSpec) throws IOException {
JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
// the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
String location = "us-central1";
LocationName locationName = LocationName.of(project, location);
String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
Value.Builder annotationSpecValue = Value.newBuilder();
JsonFormat.parser().merge(jsonString, annotationSpecValue);
DatasetName datasetName = DatasetName.of(project, location, datasetId);
DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri(inputsSchemaUri).addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
System.out.println("Create Data Labeling Job Response");
System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
System.out.println("\tAnnotation Level");
System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
}
Money money = dataLabelingJobResponse.getCurrentSpend();
System.out.println("\tCurrent Spend");
System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
System.out.format("\t\tUnits: %s\n", money.getUnits());
System.out.format("\t\tNanos: %s\n", money.getNanos());
}
}
use of com.google.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyResponseTransformer_mismatchedTypes.
@Test
public void testAnyResponseTransformer_mismatchedTypes() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Status status = Status.newBuilder().setCode(Code.OK.value()).build();
OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(Color.getDefaultInstance())).setError(status).build());
Exception exception = assertThrows(UnknownException.class, () -> transformer.apply(operationSnapshot));
Truth.assertThat(exception).hasMessageThat().contains("encountered a problem unpacking it");
}
use of com.google.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyResponseTransformer_exception.
@Test
public void testAnyResponseTransformer_exception() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.value()).build();
OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build());
Exception exception = assertThrows(UnavailableException.class, () -> transformer.apply(operationSnapshot));
Truth.assertThat(exception).hasMessageThat().contains("failed with status = GrpcStatusCode{transportCode=UNAVAILABLE}");
}
use of com.google.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyMetadataTransformer.
@Test
public void testAnyMetadataTransformer() {
MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create(Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build());
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
Aggregations