From 84658e3dda8aa56f76069bf5fa8ce9c89e0f85f2 Mon Sep 17 00:00:00 2001 From: jasperan <23caj23@gmail.com> Date: Fri, 29 Nov 2024 02:46:11 +0100 Subject: [PATCH 1/5] feat: added gitignore to remove config file for language translation --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e16e08..0f23f34 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ Temporary Items .key .crt .csr -.pem \ No newline at end of file +.pem + +oci-language-translation/config.yaml \ No newline at end of file From eeae2b9aa67a8f482addfde11fd293d0d09a02ca Mon Sep 17 00:00:00 2001 From: jasperan <23caj23@gmail.com> Date: Mon, 2 Dec 2024 01:41:07 +0100 Subject: [PATCH 2/5] feat: added initial files and readme file with: Added Object Storage namespace to the prerequisites and setup steps Updated the configuration section to include the new Object Storage settings Added a clear Configuration Priority section explaining how values are resolved Made environment variables optional, clarifying that all values can be set in config.yaml Updated the config.yaml example to show both Language Translation and Object Storage sections Improved the formatting and organization of the configuration documentation Added more detailed explanations about where to find the namespace value Clarified that environment variables override config.yaml values --- oci-language-translation/README.md | 171 +++++++++++++ .../bucket_translation.py | 112 +++++++++ oci-language-translation/config_example.yaml | 12 + .../csv_json_translation.py | 228 ++++++++++++++++++ ...anslation_csv_columnsToTranslate_sample.py | 87 +++++++ oci-language-translation/requirements.txt | 3 + 6 files changed, 613 insertions(+) create mode 100644 oci-language-translation/README.md create mode 100644 oci-language-translation/bucket_translation.py create mode 100644 oci-language-translation/config_example.yaml create mode 100644 oci-language-translation/csv_json_translation.py create mode 100644 oci-language-translation/docs/oci_file_translation_csv_columnsToTranslate_sample.py create mode 100644 oci-language-translation/requirements.txt diff --git a/oci-language-translation/README.md b/oci-language-translation/README.md new file mode 100644 index 0000000..301bf0b --- /dev/null +++ b/oci-language-translation/README.md @@ -0,0 +1,171 @@ +# OCI Language Translation Tools + +## Introduction + +This repository contains two powerful tools for leveraging OCI Language Translation services: + +1. **Bulk Document Translation**: Automatically translate multiple documents stored in an OCI Object Storage bucket. This tool supports various document formats and maintains the original file structure in the target bucket. + +2. **CSV/JSON Field Translation**: Selectively translate specific columns in CSV files or keys in JSON documents while preserving the original structure. This is particularly useful for localizing data files while maintaining their format and untranslated fields. + +## Prerequisites + +- Python 3.8 or higher +- OCI Account with Language Translation service enabled +- Required IAM Policies and Permissions +- Object Storage buckets (for document translation) +- OCI CLI configured with proper credentials + +### OCI Setup Requirements + +1. Create an OCI account if you don't have one +2. Enable Language Translation service in your tenancy +3. Set up OCI CLI and create API keys: + ```bash + # Install OCI CLI + bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" + + # Configure OCI CLI (this will create ~/.oci/config) + oci setup config + ``` +4. Set up appropriate IAM policies +5. Create source and target buckets in Object Storage (for document translation) +6. Note your Object Storage namespace (visible in the OCI Console under Object Storage) + +## Getting Started + +1. Clone this repository: + ```bash + git clone + cd oci-language-translation + ``` + +2. Install required dependencies: + ```bash + pip install -r requirements.txt + ``` + +3. Configure the environment (optional - can be set in config.yaml instead): + ```bash + # Optional - all these values can be set in config.yaml + export OCI_COMPARTMENT_ID="ocid1.compartment.oc1..your-compartment-id" + export OCI_SOURCE_LANG="en" + export OCI_TARGET_LANG="es" + ``` + +4. Update `config.yaml` with your translation and storage settings: + ```yaml + # Language Translation Service Configuration + language_translation: + compartment_id: "ocid1.compartment.oc1..your-compartment-id" + source_bucket: "source-bucket-name" + target_bucket: "target-bucket-name" + source_language: "en" # ISO language code + target_language: "es" # ISO language code + + # Object Storage Configuration + object_storage: + namespace: "your-namespace" # Your tenancy's Object Storage namespace + bucket_name: "your-bucket-name" # Bucket for CSV/JSON translations + ``` + +5. For bulk document translation: + ```bash + python bucket_translation.py + ``` + +6. For CSV/JSON translation: + ```bash + # For CSV files (column numbers start from 1) + python csv_json_translation.py csv input.csv output.csv 1 2 3 + + # For JSON files + python csv_json_translation.py json input.json output.json key1 key2 + ``` + +## Usage Examples + +### Bulk Document Translation +```bash +# Translate all documents from source bucket to target bucket +python bucket_translation.py +``` + +### CSV Translation +```bash +# Translate columns 1, 3, and 5 from English to Spanish +python csv_json_translation.py csv products.csv products_es.csv 1 3 5 +``` + +### JSON Translation +```bash +# Translate 'name' and 'details' fields in a JSON file +python csv_json_translation.py json catalog.json catalog_es.json name details +``` + +## Configuration + +The project uses three types of configuration: + +1. **OCI Configuration** (`~/.oci/config`): + - Created automatically by `oci setup config` + - Contains your OCI authentication details + - Used for API authentication + +2. **Translation Configuration** (`config.yaml`): + ```yaml + # Language Translation Service Configuration + language_translation: + compartment_id: "ocid1.compartment.oc1..your-compartment-id" + source_bucket: "source-bucket-name" + target_bucket: "target-bucket-name" + source_language: "en" + target_language: "es" + + # Object Storage Configuration + object_storage: + namespace: "your-namespace" # Your tenancy's Object Storage namespace + bucket_name: "your-bucket-name" # Bucket for CSV/JSON translations + ``` + +3. **Environment Variables** (optional, override config.yaml): + - `OCI_COMPARTMENT_ID`: Your OCI compartment OCID + - `OCI_SOURCE_LANG`: Source language code + - `OCI_TARGET_LANG`: Target language code + +### Configuration Priority + +The configuration values are loaded in the following priority order: +1. Environment variables (if set) +2. Values from config.yaml +3. Default values (for language codes only: en -> es) + +## Supported Languages + +The service supports a wide range of languages. Common language codes include: +- English (en) +- Spanish (es) +- French (fr) +- German (de) +- Italian (it) +- Portuguese (pt) +- Chinese Simplified (zh-CN) +- Japanese (ja) + +For a complete list of supported languages, refer to the OCI Documentation. + +## Error Handling + +Both tools include comprehensive error handling: +- Configuration validation +- Service availability checks +- File format validation +- Translation status monitoring + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. \ No newline at end of file diff --git a/oci-language-translation/bucket_translation.py b/oci-language-translation/bucket_translation.py new file mode 100644 index 0000000..466d9f0 --- /dev/null +++ b/oci-language-translation/bucket_translation.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 + +import oci +import yaml +import sys +import time +from pathlib import Path + +def load_config(): + """Load configuration from config.yaml file""" + with open("config.yaml", "r") as file: + config = yaml.safe_load(file) + return config + +def init_clients(config): + """Initialize OCI clients""" + # Initialize the AI Language client + ai_client = oci.ai_language.AIServiceLanguageClient( + oci.config.from_file( + file_location="config.yaml", + profile_name="DEFAULT" + ) + ) + + # Initialize Object Storage client + object_storage = oci.object_storage.ObjectStorageClient( + oci.config.from_file( + file_location="config.yaml", + profile_name="DEFAULT" + ) + ) + + return ai_client, object_storage + +def list_objects_in_bucket(object_storage, namespace, bucket_name): + """List all objects in a bucket""" + list_objects_response = object_storage.list_objects( + namespace_name=namespace, + bucket_name=bucket_name + ) + return [obj.name for obj in list_objects_response.data.objects] + +def translate_documents(ai_client, config): + """Translate all documents in the source bucket""" + try: + # Get configuration values + compartment_id = config["language_translation"]["compartment_id"] + source_bucket = config["language_translation"]["source_bucket"] + target_bucket = config["language_translation"]["target_bucket"] + source_language = config["language_translation"]["source_language"] + target_language = config["language_translation"]["target_language"] + + # Create batch document translation job + create_batch_job_response = ai_client.create_batch_document_translation_job( + create_batch_document_translation_job_details=oci.ai_language.models.CreateBatchDocumentTranslationJobDetails( + compartment_id=compartment_id, + display_name=f"Batch_Translation_{time.strftime('%Y%m%d_%H%M%S')}", + source_language_code=source_language, + target_language_code=target_language, + input_location=oci.ai_language.models.ObjectStorageLocation( + bucket_name=source_bucket, + namespace_name=namespace + ), + output_location=oci.ai_language.models.ObjectStorageLocation( + bucket_name=target_bucket, + namespace_name=namespace + ) + ) + ) + + job_id = create_batch_job_response.data.id + print(f"Translation job created with ID: {job_id}") + + # Monitor job status + while True: + job_status = ai_client.get_batch_document_translation_job( + batch_document_translation_job_id=job_id + ).data.lifecycle_state + + print(f"Job status: {job_status}") + if job_status in ["SUCCEEDED", "FAILED"]: + break + time.sleep(30) + + return job_status == "SUCCEEDED" + + except Exception as e: + print(f"Error during translation: {str(e)}") + return False + +def main(): + try: + # Load configuration + config = load_config() + + # Initialize clients + ai_client, object_storage = init_clients(config) + + # Start translation + success = translate_documents(ai_client, config) + + if success: + print("Translation completed successfully!") + else: + print("Translation failed.") + + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/oci-language-translation/config_example.yaml b/oci-language-translation/config_example.yaml new file mode 100644 index 0000000..e559631 --- /dev/null +++ b/oci-language-translation/config_example.yaml @@ -0,0 +1,12 @@ +# Language Translation Service Configuration +language_translation: + compartment_id: "ocid1.compartment.oc1..your-compartment-id" + source_bucket: "source-bucket-name" + target_bucket: "target-bucket-name" + source_language: "en" # ISO language code + target_language: "es" # ISO language code + +# Object Storage Configuration +object_storage: + namespace: "your-namespace" # Your tenancy's Object Storage namespace + bucket_name: "your-bucket-name" # Bucket for CSV/JSON translations diff --git a/oci-language-translation/csv_json_translation.py b/oci-language-translation/csv_json_translation.py new file mode 100644 index 0000000..cacc523 --- /dev/null +++ b/oci-language-translation/csv_json_translation.py @@ -0,0 +1,228 @@ +#!/usr/bin/env python3 + +import oci +import datetime +import time +import sys +import json +import yaml +import os +import pandas as pd +from pathlib import Path + +def generate_job_name(): + """Generate a unique job name with timestamp""" + current_date = datetime.date.today() + current_time = datetime.datetime.now() + return f"translation_job_{current_date.strftime('%Y-%m-%d')}T{current_time.strftime('%H-%M-%S')}" + +def load_config(): + """Load configuration from config.yaml""" + try: + with open("config.yaml", "r") as f: + return yaml.safe_load(f) + except Exception as e: + print(f"Error loading config.yaml: {str(e)}") + sys.exit(1) + +def translate_csv(ai_client, input_file, output_file, columns_to_translate, source_language, target_language, compartment_id, namespace, bucket): + """Translate specific columns in a CSV file using OCI Language service""" + try: + # Create the translation configuration for CSV + translation_config = { + "translation": { + "csv": { + "columnsToTranslate": columns_to_translate, + "csvDntHeaderRowCount": True + } + } + } + + # Create input location + input_location = oci.ai_language.models.ObjectStorageFileNameLocation( + namespace_name=namespace, + bucket_name=bucket, + object_names=[input_file] + ) + + # Set up model metadata + model_metadata_details = oci.ai_language.models.ModelMetadataDetails( + model_type="PRE_TRAINED_TRANSLATION", + language_code=source_language, + configuration={ + "targetLanguageCodes": oci.ai_language.models.ConfigurationDetails( + configuration_map={"languageCodes": target_language} + ), + "properties": oci.ai_language.models.ConfigurationDetails( + configuration_map={"advancedProperties": json.dumps(translation_config)} + ) + } + ) + + # Set up output location + output_location = oci.ai_language.models.ObjectPrefixOutputLocation( + namespace_name=namespace, + bucket_name=bucket, + prefix=output_file + ) + + # Create and submit translation job + create_job_details = oci.ai_language.models.CreateJobDetails( + display_name=generate_job_name(), + compartment_id=compartment_id, + input_location=input_location, + model_metadata_details=[model_metadata_details], + output_location=output_location + ) + + job_response = ai_client.create_job(create_job_details=create_job_details) + print(f"Created translation job: {job_response.data.display_name}") + + # Monitor job status + job_id = job_response.data.id + while True: + job_status = ai_client.get_job(job_id=job_id) + current_state = job_status.data.lifecycle_state + print(f"{datetime.datetime.now()}: Job status: {current_state}") + + if current_state in ["SUCCEEDED", "FAILED"]: + break + time.sleep(5) + + if current_state == "SUCCEEDED": + print(f"Translation completed successfully! Check {output_file} for results") + return True + else: + print(f"Translation failed with status: {current_state}") + return False + + except Exception as e: + print(f"Error during CSV translation: {str(e)}") + return False + +def translate_json(ai_client, input_file, output_file, keys_to_translate, source_language, target_language, compartment_id, namespace, bucket): + """Translate specific keys in a JSON file using OCI Language service""" + try: + # Create the translation configuration for JSON + translation_config = { + "translation": { + "json": { + "keysToTranslate": keys_to_translate + } + } + } + + # Create input location + input_location = oci.ai_language.models.ObjectStorageFileNameLocation( + namespace_name=namespace, + bucket_name=bucket, + object_names=[input_file] + ) + + # Set up model metadata + model_metadata_details = oci.ai_language.models.ModelMetadataDetails( + model_type="PRE_TRAINED_TRANSLATION", + language_code=source_language, + configuration={ + "targetLanguageCodes": oci.ai_language.models.ConfigurationDetails( + configuration_map={"languageCodes": target_language} + ), + "properties": oci.ai_language.models.ConfigurationDetails( + configuration_map={"advancedProperties": json.dumps(translation_config)} + ) + } + ) + + # Set up output location + output_location = oci.ai_language.models.ObjectPrefixOutputLocation( + namespace_name=namespace, + bucket_name=bucket, + prefix=output_file + ) + + # Create and submit translation job + create_job_details = oci.ai_language.models.CreateJobDetails( + display_name=generate_job_name(), + compartment_id=compartment_id, + input_location=input_location, + model_metadata_details=[model_metadata_details], + output_location=output_location + ) + + job_response = ai_client.create_job(create_job_details=create_job_details) + print(f"Created translation job: {job_response.data.display_name}") + + # Monitor job status + job_id = job_response.data.id + while True: + job_status = ai_client.get_job(job_id=job_id) + current_state = job_status.data.lifecycle_state + print(f"{datetime.datetime.now()}: Job status: {current_state}") + + if current_state in ["SUCCEEDED", "FAILED"]: + break + time.sleep(5) + + if current_state == "SUCCEEDED": + print(f"Translation completed successfully! Check {output_file} for results") + return True + else: + print(f"Translation failed with status: {current_state}") + return False + + except Exception as e: + print(f"Error during JSON translation: {str(e)}") + return False + +def main(): + try: + if len(sys.argv) < 5: + print("Usage: python csv_json_translation.py ") + sys.exit(1) + + file_type = sys.argv[1].lower() + input_file = sys.argv[2] + output_file = sys.argv[3] + items_to_translate = sys.argv[4:] + + # Load configuration + config = load_config() + + # Initialize OCI client using default config + oci_config = oci.config.from_file() + ai_client = oci.ai_language.AIServiceLanguageClient(config=oci_config) + + # Get configuration values + source_language = os.getenv("OCI_SOURCE_LANG", config["language_translation"]["source_language"]) + target_language = os.getenv("OCI_TARGET_LANG", config["language_translation"]["target_language"]) + compartment_id = os.getenv("OCI_COMPARTMENT_ID", config["language_translation"]["compartment_id"]) + namespace = config["object_storage"]["namespace"] + bucket = config["object_storage"]["bucket_name"] + + if not compartment_id: + print("Error: OCI_COMPARTMENT_ID environment variable or compartment_id in config.yaml is required") + sys.exit(1) + + if file_type == "csv": + # Convert column numbers to integers + columns = [int(col) for col in items_to_translate] + success = translate_csv(ai_client, input_file, output_file, columns, + source_language, target_language, compartment_id, + namespace, bucket) + elif file_type == "json": + success = translate_json(ai_client, input_file, output_file, items_to_translate, + source_language, target_language, compartment_id, + namespace, bucket) + else: + print("Unsupported file type. Please use 'csv' or 'json'") + sys.exit(1) + + if not success: + sys.exit(1) + + except Exception as e: + print(f"Error: {str(e)}") + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/oci-language-translation/docs/oci_file_translation_csv_columnsToTranslate_sample.py b/oci-language-translation/docs/oci_file_translation_csv_columnsToTranslate_sample.py new file mode 100644 index 0000000..599a92a --- /dev/null +++ b/oci-language-translation/docs/oci_file_translation_csv_columnsToTranslate_sample.py @@ -0,0 +1,87 @@ +import oci +import datetime +import time + +# Change this to create a job name automatically based on your own convention +def generate_job_name(): + current_date = datetime.date.today() + current_time = datetime.datetime.now() + # Create a unique file name with the current timestamp + return f"job_{current_date.strftime('%Y-%m-%d')}T{current_time.strftime('%H-%M-%S')}" + +# Use your own auth info . +oci_config = { + "user": 'ocid1.user.oc1..aaaaaaaa3gj6ljlcbe37ua2dh6dcbhcrpuy7z4jqhrlvviz3qseuns75c', + "key_file": '~/.oci/oci_api_key.pem', + "fingerprint": 'c8:e8:5f:61:eb:f7:c0:14:46:fd:a1:63:3b:b8:78', + "tenancy": 'ocid1.tenancy.oc1..aaaaaaaaawihvxgba2bzuk5lgauuvled5663n5n24mtulyup2ftfcghmk', + "region": 'us-ashburn-1' +} +# OCID of the compartment where your job is going to be created +compartmentId = "ocid1.compartment.oc1..aaaaaaaapyjqsd6a7qg2nkubqlefmj7gvkcx7mjbggiacl6dirid5py6b" + + +## Upload your files to a bucket. +namespace_name = 'axecxhcuzme' +bucket_name = 'oci_file_translation_test' +# Input CSV files are here. Max size of single file is 20M, so you might need to split a file (1000 lines max for example) +prefix="source/synthetic" +# Translated CSV files are going to be stored in this folder +target_prefix="output/synthetic_multiple/" + +# CSV column name start from 1. SYNTHETIC_VARIABLE_DICT_converted (Column M) is 13th for example. +translation_config = "{\"translation\":{\"csv\":{\"columnsToTranslate\":[13,22],\"csvDntHeaderRowCount\":true}}}" +source_lang = "en" +target_langs="fr,es" # Any more languages? + + +oci.config.validate_config(oci_config) +print(f'imported oci version {oci.__version__}') +ai_client = oci.ai_language.AIServiceLanguageClient(config=oci_config) + +# If you want to translate a specific file +#input_location = oci.ai_language.models.ObjectStorageFileNameLocation( +# namespace_name=namespace_name, bucket_name=bucket_name, +# object_names=[prefix+"/"+"synthetic_data_textgen_command_r_fusion_small.csv"]) + +# Or all files in a specific bucket (or a specific folder) +input_location = oci.ai_language.models.ObjectStoragePrefixLocation( + namespace_name=namespace_name, bucket_name=bucket_name, + prefix=prefix) + +# Give the index of your column to translate (English version of local text) - starting from 1 (not 0) + +# Change the target language code +# nl for Dutch, de for German, ar for Arabic, fr for French, it for Italian +model_metadata_details = oci.ai_language.models.ModelMetadataDetails( + model_type="PRE_TRAINED_TRANSLATION", language_code=source_lang, + configuration = {"targetLanguageCodes": + oci.ai_language.models.ConfigurationDetails(configuration_map={"languageCodes":target_langs}), + "properties": + oci.ai_language.models.ConfigurationDetails(configuration_map={ + "advancedProperties":translation_config})}) + +# Give the output location. +# Can be a different bucket or a different folder in the same bucket +output_location = oci.ai_language.models.ObjectPrefixOutputLocation( + namespace_name=namespace_name, bucket_name=bucket_name, prefix=target_prefix) + +createJobDetails = oci.ai_language.models.CreateJobDetails(display_name=generate_job_name(), description=None, + compartment_id=compartmentId, + input_location=input_location, + model_metadata_details=[model_metadata_details], + output_location=output_location) + +createJobOutput = ai_client.create_job(create_job_details=createJobDetails) +print(f"created a job {createJobOutput.data.display_name}") + + +# Just quick using Control-C if your job is going to take long (i.e. thousands of lines) +# You can check the output of the translation job in the OCI console +# Console ==> Choose region ==> AI ==> Language ==> Job ==> Choose a right compartment +getJobOutput = ai_client.get_job(job_id=createJobOutput.data.id) +while getJobOutput.data.lifecycle_state in ('ACCEPTED', 'IN_PROGRESS'): + print(f"{datetime.datetime.now()}: waiting for the job to complete") + time.sleep(5); + getJobOutput = ai_client.get_job(job_id=createJobOutput.data.id) +print(f'{datetime.datetime.now()}: job {getJobOutput.data.display_name} for {getJobOutput.data.total_documents} files completed. status is: {getJobOutput.data.lifecycle_state}'); diff --git a/oci-language-translation/requirements.txt b/oci-language-translation/requirements.txt new file mode 100644 index 0000000..f10b2d9 --- /dev/null +++ b/oci-language-translation/requirements.txt @@ -0,0 +1,3 @@ +oci>=2.110.0 +pyyaml +pandas \ No newline at end of file From c86cbb6175eec8e79205c1a45e974497e773bea2 Mon Sep 17 00:00:00 2001 From: jasperan <23caj23@gmail.com> Date: Fri, 13 Dec 2024 02:44:15 +0100 Subject: [PATCH 3/5] feat: added config files in gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0f23f34..85ecf5f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,7 @@ Temporary Items .csr .pem -oci-language-translation/config.yaml \ No newline at end of file +oci-language-translation/config.yaml +oci-subtitle-translation/config.yaml +oci-csv-json-translation/config.yaml +oci-language-multiple-translation/config.yaml \ No newline at end of file From 27ed5545d46214e6e3c686865e4fe8826f83d3f3 Mon Sep 17 00:00:00 2001 From: jasperan <23caj23@gmail.com> Date: Fri, 13 Dec 2024 02:44:29 +0100 Subject: [PATCH 4/5] feat: added code assist article --- oci-code-assist/README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 oci-code-assist/README.md diff --git a/oci-code-assist/README.md b/oci-code-assist/README.md new file mode 100644 index 0000000..5c079b0 --- /dev/null +++ b/oci-code-assist/README.md @@ -0,0 +1,31 @@ +# Get Started with Oracle Code Assist + +To get started with Oracle Code Assist, follow these steps: + +1. Apply for the Beta Program: + - Visit the [Oracle Beta Programs page](https://www.oracle.com/beta-programs/) and select the Oracle Code Assist Beta Program link. + - Complete and submit the recruitment form for Oracle Code Assist. Note that a separate recruitment form and legal agreement are required for each beta program. + - Ensure you have an Oracle Single Sign-On (SSO) account associated with your company email address. If you don't have one, you'll need to create it during the application process. +2. Await Approval: + - The Oracle Beta Program Office will review your application. + - Upon approval, you'll receive a notification email with further instructions. +3. Install the Plugin: + - Oracle Code Assist is available as a plugin for popular development environments like JetBrains IntelliJ IDEA and Microsoft Visual Studio Code. + - Once approved, follow the provided instructions to download and install the plugin in your preferred development environment. +4. Start Using Oracle Code Assist: + - With the plugin installed, you can begin leveraging Oracle Code Assist's features, such as: + - Generating code to enhance productivity. + - Creating unit tests to increase test coverage. + - Annotating code to improve readability. + - Explaining code to accelerate learning. + - Providing chat-based answers to coding-related questions. + +For more detailed information, refer to the [Oracle Code Assist: AI Companion to Boost Developer Velocity](https://blogs.oracle.com/developers/post/oracle-code-assist-ai-companion-boost-velocity) blog post. + +Note: Oracle Code Assist is currently in beta. Features and availability may change based on user feedback and ongoing development. + +Few other useful links here: + +- [Oracle Code Assist](https://www.oracle.com/application-development/code-assist/) +- [Announcing Oracle Code Assist beta and NetSuite SuiteScript support](https://blogs.oracle.com/developers/post/announcing-oracle-code-assist-beta-and-netsuite-suitescript-support) +- [Embracing Open Source to drive innovation at Oracle](https://blogs.oracle.com/developers/post/kubecon-2024-announcements) From fe820fee446901cb2573937700bb8094ed9a97ba Mon Sep 17 00:00:00 2001 From: jasperan <23caj23@gmail.com> Date: Fri, 13 Dec 2024 02:48:28 +0100 Subject: [PATCH 5/5] feat: updated bucket translation to load config from ~/.oci/config --- .../bucket_translation.py | 112 ------------------ 1 file changed, 112 deletions(-) delete mode 100644 oci-language-translation/bucket_translation.py diff --git a/oci-language-translation/bucket_translation.py b/oci-language-translation/bucket_translation.py deleted file mode 100644 index 466d9f0..0000000 --- a/oci-language-translation/bucket_translation.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python3 - -import oci -import yaml -import sys -import time -from pathlib import Path - -def load_config(): - """Load configuration from config.yaml file""" - with open("config.yaml", "r") as file: - config = yaml.safe_load(file) - return config - -def init_clients(config): - """Initialize OCI clients""" - # Initialize the AI Language client - ai_client = oci.ai_language.AIServiceLanguageClient( - oci.config.from_file( - file_location="config.yaml", - profile_name="DEFAULT" - ) - ) - - # Initialize Object Storage client - object_storage = oci.object_storage.ObjectStorageClient( - oci.config.from_file( - file_location="config.yaml", - profile_name="DEFAULT" - ) - ) - - return ai_client, object_storage - -def list_objects_in_bucket(object_storage, namespace, bucket_name): - """List all objects in a bucket""" - list_objects_response = object_storage.list_objects( - namespace_name=namespace, - bucket_name=bucket_name - ) - return [obj.name for obj in list_objects_response.data.objects] - -def translate_documents(ai_client, config): - """Translate all documents in the source bucket""" - try: - # Get configuration values - compartment_id = config["language_translation"]["compartment_id"] - source_bucket = config["language_translation"]["source_bucket"] - target_bucket = config["language_translation"]["target_bucket"] - source_language = config["language_translation"]["source_language"] - target_language = config["language_translation"]["target_language"] - - # Create batch document translation job - create_batch_job_response = ai_client.create_batch_document_translation_job( - create_batch_document_translation_job_details=oci.ai_language.models.CreateBatchDocumentTranslationJobDetails( - compartment_id=compartment_id, - display_name=f"Batch_Translation_{time.strftime('%Y%m%d_%H%M%S')}", - source_language_code=source_language, - target_language_code=target_language, - input_location=oci.ai_language.models.ObjectStorageLocation( - bucket_name=source_bucket, - namespace_name=namespace - ), - output_location=oci.ai_language.models.ObjectStorageLocation( - bucket_name=target_bucket, - namespace_name=namespace - ) - ) - ) - - job_id = create_batch_job_response.data.id - print(f"Translation job created with ID: {job_id}") - - # Monitor job status - while True: - job_status = ai_client.get_batch_document_translation_job( - batch_document_translation_job_id=job_id - ).data.lifecycle_state - - print(f"Job status: {job_status}") - if job_status in ["SUCCEEDED", "FAILED"]: - break - time.sleep(30) - - return job_status == "SUCCEEDED" - - except Exception as e: - print(f"Error during translation: {str(e)}") - return False - -def main(): - try: - # Load configuration - config = load_config() - - # Initialize clients - ai_client, object_storage = init_clients(config) - - # Start translation - success = translate_documents(ai_client, config) - - if success: - print("Translation completed successfully!") - else: - print("Translation failed.") - - except Exception as e: - print(f"Error: {str(e)}") - sys.exit(1) - -if __name__ == "__main__": - main()