Connect to a Cloud VM host using VS Code with a Remote SSH extension

On your VS Code install an extension Remote – SSH from Microsoft

Set up your SSH Key:

using your terminal navigate to ~/.ssh

Place your public key on the vm in ~/.ssh/authorized_keys

Make sure permissions are correct:

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys

Add the VM to your SSH config
Edit ~/.ssh/config on your laptop:

Host myvm
HostName YOUR_VM_IP_OR_DNS
User YOUR_USERNAME
IdentityFile ~/.ssh/<your private key pair>

ie.

HostName <your public ip> 
Host gcp-vm
User thecloudadoption_blog
IdentityFile ~/.ssh/gcp_vscode
IdentitiesOnly yes

For GCP VMs, SSH Key format:

Generate a SSH key: -> with a comment at the end like below(VM  username)
ssh-keygen -t ed25519 -f ~/.ssh/gcp_vscode -C "thecloudadoption_blog"

Then display the public key, copy on the VM in GCP console

cat ~/.ssh/gcp_vscode.pub

It will look something like:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB... thecloudadoption_blog

Google Cloud accepts that format directly.

Then you can add the private key on your local config file as explained above.

Connect from VS Code

Open VS Code

Press Ctrl+Shift+P

Run: Remote-SSH: Connect to Host…

Pick myvm or your VM name

VS Code opens a window connected to the VM, and you can edit files there directly

Run python Code within VS Code:

Install the python plugin for the VM-> Extensions-> python.

Select the Python interpreter

Press:

⌘⇧P

Type:

Python: Select Interpreter

Choose something like:

/usr/bin/python3

or your virtual environment:

/home/thecloudadoption_blog/venv/bin/python

If no interpreters appear, we’ll need to install Python or point VS Code at it.

Installing a Jupyter Notebook on a Compute instance running OEL8 on OCI

On my last blog post, I described the steps to install a jupyter lab notebook on a local machine running MacOS.

This post will describe the steps to install a Jupyter lab on a compute instance running on Oracle Enterprise Linux 8 (OEL8) on Oracle cloud infrastructure.

Step 1: SSH to the the instance

ssh -i dev-instance-private.key opc@141.147.xx.xxx

Step 2: update and install Dependencies: (use dnf cmd for Oracle linux 8, yum for linux 7 and below)

sudo dnf update -y

Step 3: Install python and pip

  sudo dnf install python3 -y
  sudo dnf install python3-pip -y

Step 4: Verify Python and pip

python3 --version
python3 -m pip --version

Step 5: Create and Activate a Virtual Environment:
create a virtual environment.

python3 -m venv myenv


Activate the environment.

source myenv/bin/activate

Step 6: Install Jupyter lab

pip install jupyterlab

Step 7: Launch Jupyter lab

  jupyter lab

Step 8: Access JupyterLab:

To access JupyterLab from outside the OCI instance, you need to open port 8888 (or the port you’re using) in your OCI security list.


Go to your OCI compute instance VCN and find the security list associated with it. Add an ingress rule to allow traffic on port 8888 (or the port you’re using)

Step 9: SSH Tunneling

To access the jupyter lab web browser, open another terminal and add the cmd:

ssh -i dev-instance-private.key opc@141.147.XX.XXX -L 8888:127.0.0.1:8888

The above cmd allows you to access the web browser of your jupyterlab running on the OCI compute instance in your local machine

After the above step, copy the given url on step 7 on your browser to access the notebook. ie.

http://localhost:8888/lab?token=8a4fe5599d5ec4565b0407a82161f2156a7f9acb6d331c4e

See also;

How to install a Jupyter notebook on a Mac book

Step 1: Install Homebrew if not already installed (Homebrew is a package manager for MacOS)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Python

brew install python

Step 3: Verify Python installation

python3 --version

You should get something like this below:

Step 4: Install Jupyter Lab using pip command

pip install jupyterlab

Step 5: Verify installation

jupyter lab --version

Step 6: launch Jupyter Notebook

jupyter lab

Jupyter notebook launches on a webpage, on localhost port 8888 or 8889 based on available ports ie. http://localhost:8888/lab

more info- you can add the packages you require in the jupyter lab using pip command: ie Below packages are installed in the Jupiter lab

pip install oci pandas numpy matplotlib scikit-learn

Other cmds;

If you want to list the Jupyter lab sessions running:

juypter lab list

To close a session,close the terminal (ctrl+c) running the jupyter session or open another terminal and close the session using the below cmd

jupyter lab stop 8889

In my case above 8889 was my port number.

Using OCI Generative AI to categorise email feedback and send responses

OCI Generative AI is a fully managed Oracle Cloud Infrastructure service that provides customizable large language models (LLMs) that cover a wide range of use cases, including chat, text generation, summarization, and creating text embeddings.

You can use APIs & scripts to embed OCI Gen AI to your applications after testing it out on the playground from the OCI console.

In the example below using python.

# coding: utf-8
# Copyright (c) 2023, Oracle and/or its affiliates.  All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.

##########################################################################
# chat_demo.py
# Supports Python 3
##########################################################################
# Info:
# Get texts from LLM model for given prompts using OCI Generative AI Service.
##########################################################################
# Application Command line(no parameter needed)
# python chat_demo.py
##########################################################################
import oci

# Setup basic variables
# Auth Config
# TODO: Please update config profile name and use the compartmentId that has policies grant permissions for using Generative AI Service
compartment_id = "ocid1.compartment.oc1.."
CONFIG_PROFILE = "DEFAULT"
config = oci.config.from_file('~/.oci/config', CONFIG_PROFILE)

# Service endpoint
endpoint = "https://inference.generativeai...."

generative_ai_inference_client = oci.generative_ai_inference.GenerativeAiInferenceClient(config=config, service_endpoint=endpoint, retry_strategy=oci.retry.NoneRetryStrategy(), timeout=(10,240))
chat_detail = oci.generative_ai_inference.models.ChatDetails()

chat_request = oci.generative_ai_inference.models.CohereChatRequest()
#chat_request.message = "{input}"

chat_request.message = """

Instructions:
Here are customer feedback emails for a book retailer. Please 
classify each of the emails in 2 categories: good feedback and bad feedback, don't give an explanation.
Write a response for each of the good & bad feedback emails. Be polite and proffesional. 

Data:

Email 1: 
Subject: A Bookworm's Paradise!

Dear BookHunter ,

Just wanted to drop a note and say how thrilled I am with your diverse collection of books. Every visit feels like an adventure, and I always find hidden gems that aren't available elsewhere. Keep up the fantastic work!

 

Email 2: 
Subject: Shipping Delays - A Small Wrinkle in My Experience

Hello BookHunter ,

I've been a loyal customer for years and have always loved your book selection. However, my last order took longer than expected to arrive. Perhaps there's an opportunity to review your shipping partners or provide clearer delivery estimates?


Email 3: 
Subject: Disheartened by My Recent Experience

Dear BookHunter ,

I hate to say this, but my recent visit to your store was quite disappointing. The staff seemed disinterested and didn't help when I asked for recommendations. Such a stark contrast from the warm, welcoming experience I used to love. I hope this was just a one-off.
"""

chat_request.max_tokens = 600
chat_request.temperature = 0.25
chat_request.frequency_penalty = 0
chat_request.top_p = 0.75
chat_request.top_k = 0


chat_detail.serving_mode = oci.generative_ai_inference.models.OnDemandServingMode(model_id="ocid1.generativeaimodel.oc1.uk-london-1.a....")
chat_detail.chat_request = chat_request
chat_detail.compartment_id = compartment_id
chat_response = generative_ai_inference_client.chat(chat_detail)
# Print result
print("**************************Chat Result**************************")
print(vars(chat_response))

Results:

Happy Coding!