Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with createDataset #7614

Open
cluttgue opened this issue Aug 20, 2024 · 0 comments
Open

Problem with createDataset #7614

cluttgue opened this issue Aug 20, 2024 · 0 comments

Comments

@cluttgue
Copy link

cluttgue commented Aug 20, 2024

Environment details

  • OS: Windows 10
  • PHP version: 8.2.12
  • Package name and version: cloud-ai-platform v.1.3

Steps to reproduce

  1. I'm use the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php for create a Dataset for Tabular data, when I called the example I have the next error:
foreach() argument must be of type array|object, null given

  at vendor\google\gax\src\RequestBuilder.php:174
    170▕
    171▕         $body = null;
    172▕         $queryParams = [];
    173▕         $messageData = json_decode($messageDataJson, true);
  ➜ 174▕         foreach ($messageData as $name => $value) {
    175▕             if (array_key_exists($name, $config['placeholders'])) {
    176▕                 continue;
    177▕             }
    178▕

  1   vendor\google\gax\src\RequestBuilder.php:174
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("foreach() argument must be of type array|object, null given", "C:\...\vendor\google\gax\src\RequestBuilder.php")

  2   vendor\google\gax\src\RequestBuilder.php:110
      Google\ApiCore\RequestBuilder::constructBodyAndQueryParameters(Object(Google\Cloud\AIPlatform\V1\CreateDatasetRequest), ["post", "/v1/{parent=projects/*/locations/*}/datasets", "dataset"])

The code it's the same of the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php.

Code example

// The called to function are:

 $formattedParent = DatasetServiceClient::locationName('lab-ia-430919', 'us-central1');
        $this->create_dataset(
            $formattedParent,
            'example-ventas',
            'gs://bucket-ia-example/schemaDatasetVertexAI.yaml'
        );


    function create_dataset(
        string $formattedParent,
        string $datasetDisplayName,
        string $datasetMetadataSchemaUri
    ): void {
        // Create a client.
        $datasetServiceClient = new DatasetServiceClient();

        // Prepare the request message.
        $datasetMetadata = new Value();
        $dataset = (new Dataset())
            ->setName($datasetDisplayName)
            ->setDisplayName($datasetDisplayName)
            ->setMetadataSchemaUri($datasetMetadataSchemaUri)
            ->setMetadata($datasetMetadata);
        $request = (new CreateDatasetRequest())
            ->setParent($formattedParent)
            ->setDataset($dataset);


        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $datasetServiceClient->createDataset($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var Dataset $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant