G-gen ã®å åã§ãã ChatGPT (GPT-4) ã䜿ã£ãŠã»ãŒé ã䜿ãããšãªããCloud Functions ãäœæããŠã¿ãã®ã§ããã®éçšã玹ä»ããŸãã ã¯ããã« äºåæºå äºåæºåã ChatGPT ãäœ¿çš Cloud Functions ã³ãŒãçæ äžçºã§ Python ã³ãŒãçæ ãšã©ãŒä¿®æ£ãå¯èœ åäœç¢ºèª ãããã« ã¯ããã« ä»ãç¥ããªã人ã¯ããªãã§ããããOpenAI 瀟ãå
¬éããŠãã AI ãã£ãããµãŒãã¹ã§ãã ChatGPTã察話èœåãããããšãªãããã³ãŒãçæèœåã®é«ããæ³šç®ãããŠããŸãã G-gen ã§ã¯ ChatGPT ã®å©çšãäŒç€Ÿã§è£å©ãããŠããããšããããæ©é䜿ã£ãŠã¿ãŸããã prtimes.jp åœèšäºã§ã¯ ChatGPT ã䜿ã£ãŠã以äžã®ãããªä»æ§ã® Cloud Functions ãäœæããããã€ããŠã¿ãŸããã èšèªã¯ Pythonã Google Cloud Storage (GCS) ã« CSV ãã¡ã€ã«ãã¢ããããŒããããããšãããªã¬ãŒã«å®è¡ãããã GCS ãããã¢ããããŒã CSV ãã¡ã€ã«ãèªã¿åãã èªã¿åã£ãããŒã¿ã¯ BigQuery ã®ããŒãã«ã«ä¿åããã äºåæºå ä»åãäºåæºåãšããŠä»¥äžã®ããšã宿œããŸããã ãµã³ãã«ã® CSV ãã¡ã€ã«çæ GCS ãã±ããäœæ BigQuery ããŒã¿ã»ããäœæ BigQuery ããŒãã«äœæ çæãããã³ãŒãçã«ã¯äžèŠã§ãããä»åã¯äºåã«çšæããŸããã äºåæºåã ChatGPT ãäœ¿çš ãµã³ãã«ãšãªã CSV ãã¡ã€ã«ãšãããã«å¯Ÿå¿ããããŒãã«äœæã«ã€ããŠã ChatGPT ã«ããŸããããŸããã [ è³ªåæ ] Please create a sample CSV file. ãããšä»¥äžã®ãã㪠CSV ãåºåããŠãããŸããã id,name,category,price 1,Wireless Mouse,Electronics,25.99 2,Bluetooth Keyboard,Electronics,49.99 3,32GB USB Flash Drive,Electronics,15.99 4,Portable Charger,Electronics,29.99 5,Water Bottle,Sports,12.99 6,Yoga Mat,Sports,21.99 7,Dumbbell Set,Sports,59.99 8,Running Shoes,Sports,89.99 ç¶ããŠãäžèš CSV ã«å¯Ÿå¿ãã BigQuery ããŒãã«ãäœæããŠããããŸãã [ è³ªåæ ] Please tell me the query to create a BigQuery table for this CSV file. ãããšä»¥äžã®ãããªã¯ãšãªãåºåããŠãããŸããã CREATE TABLE your_dataset.products ( id INT64, name STRING, category STRING, price FLOAT64 ); ã¡ãªã¿ã«ã³ã³ãœãŒã«ã§ã©ããã£ãŠãã®ã¯ãšãªãå®è¡ãããã解説ããŠãããŠãŸãã BigQuery ããŒãã«ã®äœææ¹æ³ã«ã€ããŠã®åçæ Cloud Functions ã³ãŒãçæ äžçºã§ Python ã³ãŒãçæ ã§ã¯ãæ¬åœã§ããã³ãŒãçæãå®è¡ããŠããããŸãã [ è³ªåæ ] I would like to deploy a function on Google Cloud Functions that retrieves CSV files from Google Cloud Storage and stores their data in BigQuery. Please provide me with the corresponding code and a requirements.txt file. ãããšä»¥äžã®ãããªã³ãŒããrequirements.txt åã³ Cloud Functions ããããã€ãã gcloud ã³ãã³ããåºåããŠãããŸããã requirements.txt google-cloud-storage==1.42.3 google-cloud-bigquery==2.28.1 main.py import os import tempfile from google.cloud import storage from google.cloud import bigquery def csv_to_bigquery (event, context): """Triggered by a change to a Cloud Storage bucket. Args: event (dict): Event payload. context (google.cloud.functions.Context): Metadata for the event. """ bucket_name = event[ 'bucket' ] file_name = event[ 'name' ] dataset_id = os.environ.get( 'BIGQUERY_DATASET_ID' ) table_id = os.environ.get( 'BIGQUERY_TABLE_ID' ) # Create BigQuery client bigquery_client = bigquery.Client() # Create Storage client storage_client = storage.Client() bucket = storage_client.get_bucket(bucket_name) blob = storage.Blob(file_name, bucket) # Download the CSV file to a temporary file with tempfile.NamedTemporaryFile(mode= 'wb' , delete= True ) as temp_csv: blob.download_to_file(temp_csv) temp_csv.flush() # Load CSV into BigQuery dataset_ref = bigquery_client.dataset(dataset_id) table_ref = dataset_ref.table(table_id) job_config = bigquery.LoadJobConfig() job_config.source_format = bigquery.SourceFormat.CSV job_config.autodetect = True with open (temp_csv.name, "rb" ) as source_file: job = bigquery_client.load_table_from_file(source_file, table_ref, job_config=job_config) job.result() # Wait for the job to complete print (f "Loaded {job.output_rows} rows into {dataset_id}:{table_id} from {file_name}." ) gcloud ã³ãã³ã gcloud functions deploy csv_to_bigquery \ --runtime python310 \ --trigger-resource YOUR_TRIGGER_BUCKET_NAME \ --trigger-event google.storage.object.finalize \ --set-env-vars BIGQUERY_DATASET_ID=YOUR_DATASET_ID,BIGQUERY_TABLE_ID=YOUR_TABLE_ID requirements.txt ãš main.py ãã«ã¬ã³ããã£ã¬ã¯ããªã«èšçœ®ãã YOUR_TRIGGER_BUCKET_NAME ã YOUR_DATASET_ID åã³ YOUR_TABLE_ID ã«é©åãªå€ãèšå®ããŠã³ãã³ããå®è¡ããŸãã ãšã©ãŒä¿®æ£ãå¯èœ ããããã³ãã³ããå®è¡ãããš google-cloud-bigquery ã®ããŒãžã§ã³ãšã©ãŒã衚瀺ãããŠããŸããŸããã ããã§ãšã©ãŒæããã®ãŸãŸèšèŒããŠãå¯ŸåŠæ³ãèããŠã¿ãŸãã [ è³ªåæ ] I encounterd the following error: """ ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Collecting google-cloud-storage==1.42.3 Downloading google_cloud_storage-1.42.3-py2.py3-none-any.whl (105 kB) âââââââââââââââââââââââââââââââââââââââ 106.0/106.0 kB 3.0 MB/s eta 0:00:00 ERROR: Ignored the following versions that require a different python version: 2.10.0 Requires-Python >=3.6, <3.10; 2.11.0 Requires-Python >=3.6, <3.10; 2.12.0 Requires-Python >=3.6, <3.10; 2.13.0 Requires-Python >=3.6, <3.10; 2.13.1 Requires-Python >=3.6, <3.10; 2.14.0 Requires-Python >=3.6, <3.10; 2.15.0 Requires-Python >=3.6, <3.10; 2.16.0 Requires-Python >=3.6, <3.10; 2.16.1 Requires-Python >=3.6, <3.10; 2.17.0 Requires-Python >=3.6, <3.10; 2.18.0 Requires-Python >=3.6, <3.10; 2.19.0 Requires-Python >=3.6, <3.10; 2.20.0 Requires-Python >=3.6, <3.10; 2.21.0 Requires-Python >=3.6, <3.10; 2.22.0 Requires-Python >=3.6, <3.10; 2.22.1 Requires-Python >=3.6, <3.10; 2.23.0 Requires-Python >=3.6, <3.10; 2.23.1 Requires-Python >=3.6, <3.10; 2.23.2 Requires-Python >=3.6, <3.10; 2.23.3 Requires-Python >=3.6, <3.10; 2.24.0 Requires-Python >=3.6, <3.10; 2.24.1 Requires-Python >=3.6, <3.10; 2.25.0 Requires-Python >=3.6, <3.10; 2.25.1 Requires-Python >=3.6, <3.10; 2.25.2 Requires-Python >=3.6, <3.10; 2.26.0 Requires-Python >=3.6, <3.10; 2.27.0 Requires-Python >=3.6, <3.10; 2.27.1 Requires-Python >=3.6, <3.10; 2.28.0 Requires-Python >=3.6, <3.10; 2.28.1 Requires-Python >=3.6, <3.10; 2.29.0 Requires-Python >=3.6, <3.10; 2.6.2 Requires-Python >=3.6, <3.9; 2.7.0 Requires-Python >=3.6, <3.10; 2.8.0 Requires-Python >=3.6, <3.10; 2.9.0 Requires-Python >=3.6, <3.10 ERROR: Could not find a version that satisfies the requirement google-cloud-bigquery==2.28.1 (from versions: 0.20.0, 0.21.0, 0.22.0, 0.22.1, 0.23.0, 0.24.0, 0.25.0, 0.26.0, 0.27.0, 0.28.0, 0.29.0, 0.30.0, 0.31.0, 0.32.0, 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.12.0, 1.12.1, 1.12.2, 1.13.0, 1.13.1, 1.14.0, 1.14.1, 1.15.0, 1.15.1, 1.16.0, 1.16.1, 1.17.0, 1.17.1, 1.18.0, 1.18.1, 1.19.0, 1.19.1, 1.20.0, 1.21.0, 1.22.0, 1.23.0, 1.23.1, 1.24.0, 1.25.0, 1.26.0, 1.26.1, 1.27.2, 1.28.0, 1.28.1, 1.28.2, 1.28.3, 2.0.0, 2.1.0, 2.2.0, 2.3.1, 2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.30.0, 2.30.1, 2.31.0, 2.32.0, 2.33.0, 2.34.0, 2.34.1, 2.34.2, 2.34.3, 2.34.4, 3.0.0b1, 3.0.0, 3.0.1, 3.1.0, 3.2.0, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.5, 3.3.6, 3.4.0, 3.4.1, 3.4.2, 3.5.0, 3.6.0, 3.7.0, 3.8.0, 3.9.0, 3.10.0) ERROR: No matching distribution found for google-cloud-bigquery==2.28.1; Error ID: 656dd225 """ How can I resolve this issue? ãããš requirements.txt ãæ¬¡ã®ããã«ä¿®æ£ããŠãã ãããšè¿ä¿¡ãããŸããã requirements.txt google-cloud-storage==1.43.0 google-cloud-bigquery==3.10.0 ãšããããšã§ãäžèšã®éãä¿®æ£ã gcloud ã³ãã³ããåå®è¡ãããšãä»åºŠã¯ã¡ãããšãããã€ããããšãã§ããŸããã åäœç¢ºèª äºåæºåã§ ChatGPT ã«äœã£ãŠããã£ã CSV ãã¡ã€ã«ãããªã¬ãŒæå®ãã GCS ãã±ããã«ã¢ããããŒãããŠã¿ãŸãã ãããšæ°åãããªããã¡ã« BigQuery ããŒãã«ã«ããŒã¿ã远å ãããŸããã BigQuery ããŒãã«ã«æ ŒçŽãããããŒã¿ ãããã« ã³ãŒãã«é¢ããŠãäžåãããã¯ãšã©ãŒä¿®æ£ãå¿
èŠã«ãªãã®ããªãšæã£ãŠããã®ã§ããããŸããã®äžçºæåã§ããã ä»åã¯æ€èšŒãšããŠã·ã³ãã«ãªã³ãŒããçæããŠããããŸããã ãã®ã³ãŒããããšã«èªèº«ã§æ©èœã远å ããŠãã£ãŠãè¯ãã§ããã远å ãããæ©èœããã®ãŸãŸãŸã ChatGPT ã«ãé¡ãããã®ãè¯ããšæããŸãã æè¿æ¥æ¬ã§ãå
¬éããã Google ã® AI ãã£ãããµãŒãã¹ã§ãããBardãã§ãã ã³ãŒãçææ©èœãã€ãå
é±å®è£
ããã ãšããããšã§ããã¡ãã®ã»ããè¿æ¥æ€èšŒããŠã¿ãããšæããŸãã å å ç«åž (èšäºäžèЧ) ããŒã¿ã¢ããªãã£ã¯ã¹æºå宀ã2023幎4æãããG-genã«ãžã§ã€ã³ã Google Cloud Partner Top Engineer 2023, 2024ã«éžåº (2024幎ã¯Rookie of the yearã«ãéžåº)ãäŒã¿ã®æ¥ã¯ã ãããã²ãŒã ãããŠããããæã
èªè»¢è»ã§é åºãããŠããŸãã Follow @matayuuuu