-
Notifications
You must be signed in to change notification settings - Fork 2k
chore(ci): migrate ai-platform/snippets via ESM #4102
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
base: main
Are you sure you want to change the base?
Changes from all commits
9cc6ab0
d6c0efd
1236464
4b44369
1b2a2b8
f04c5a3
cef133f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"timeout-minutes": 20, | ||
"secrets": { | ||
"CAIP_PROJECT_ID": "nodejs-docs-samples-tests/nodejs-docs-samples-ai-platform-caip-project-id" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,8 @@ async function main() { | |
const predictionServiceClient = new PredictionServiceClient(clientOptions); | ||
|
||
async function editImageInpaintingInsertMask() { | ||
const fs = require('fs'); | ||
const util = require('util'); | ||
const fs = require('node:fs'); | ||
const util = require('node:util'); | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These This pattern is present in several other import fs from 'node:fs';
import util from 'node:util'; |
||
// Configure the parent resource | ||
const endpoint = `projects/${projectId}/locations/${location}/publishers/google/models/imagegeneration@006`; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ async function main( | |
// Configure the parent resource | ||
const endpoint = `projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`; | ||
|
||
const fs = require('fs'); | ||
const fs = require('node:fs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const imageFile = fs.readFileSync(baseImagePath); | ||
|
||
// Convert the image data to a Buffer and base64 encode it. | ||
|
@@ -95,4 +95,4 @@ async function main( | |
// [END generativeaionvertexai_sdk_text_image_embedding] | ||
} | ||
|
||
exports.predictImageFromImageAndText = main; | ||
export {main as predictImageFromImageAndText}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,13 @@ | |
|
||
'use strict'; | ||
|
||
const {assert} = require('chai'); | ||
const {after, describe, it} = require('mocha'); | ||
const uuid = require('uuid').v4; | ||
const cp = require('child_process'); | ||
import {assert} from 'chai'; | ||
import {after, describe, it} from 'mocha'; | ||
import {v4 as uuid} from 'uuid'; | ||
import cp from 'node:child_process'; | ||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const aiplatform = require('@google-cloud/aiplatform'); | ||
import aiplatform from '@google-cloud/aiplatform'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import Other files (e.g., |
||
const clientOptions = { | ||
apiEndpoint: 'us-central1-aiplatform.googleapis.com', | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
__dirname
variable is not available by default in ES modules, leading to aReferenceError
at runtime. Refactor to determine the current directory path in an ESM context.This issue applies to many other test files using
__dirname
:ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js
ai-platform/snippets/expensive-test/create-data-labeling-job.test.js
ai-platform/snippets/test/create-batch-prediction-job-video-classification.test.js
Update these files to use the ESM-compatible way of getting the directory name?