Skip to content

Commit e70847b

Browse files
authored
Bug fixes for #11661 (#553)
* Submited : Create a Large Language Model (LLM) chatbot using Oracle Database 23ai and Generative AI Service. * Name adjustements * Folder rename * Deleted old folder * Fixed some bugs
1 parent bf54503 commit e70847b

File tree

5 files changed

+51
-31
lines changed

5 files changed

+51
-31
lines changed

ai-chatbot-engine/search+llm/search+llm.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ with connection.cursor() as cursor:
8888
The SQL query is executed with the provided vector parameter, fetching relevant information from the database. For each result, the code retrieves the text content, stored in JSON format, and appends it to a list along with the calculated similarity score. This process iterates through all fetched results, accumulating them in the `results` list.
8989

9090
If we print the results, we obtain something like the following. As requested, we have the "score" of each hit, which is essentially the distance in vector space between the question and the text chunk, as well as the metadata JSON embedded in each chunk.
91+
```python
92+
import pprint
93+
pprint.pp(results)
94+
```
9195

9296
```
9397
[(0.342059188035412,
@@ -206,17 +210,19 @@ In a Retrieval-Augmented Generation (RAG) application, the prompt given to a Lar
206210
</copy>
207211
```
208212

209-
The user's OCID can be retrieved like this:
213+
The **user's OCID** can be retrieved like this:
210214
- Sign in to the Oracle Cloud Console.
211215
- In the top-right corner, click on your user profile icon, then click on “User Settings”.
212216
- In the User Settings page, you will find your User OCID.
213217

214-
The tenancy's OCID:
218+
The **key file** is generated using the instructions [from this doc](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#apisigningkey_topic_How_to_Generate_an_API_Signing_Key_Console).
219+
220+
The **tenancy's OCID**:
215221
- Open the Navigation Menu (the hamburger menu icon).
216222
- Under Identity, click on Tenancy.
217223
- The Tenancy OCID will be displayed on the Tenancy details page.
218224

219-
While you have the Console open, fetch also the comaprtment OCID (you will need it in the next step):
225+
While you have the Console open, fetch also the **compartment OCID** (you will need it in the next step):
220226
- Navigate to Identity: Open the main menu and select Identity & Security -> Compartments.
221227
- List of Compartments: You will see a list of compartments. Click on the compartment you need the OCID for.
222228
- Compartment Details: The details page of the compartment will display its OCID.

ai-chatbot-engine/setup-23ai/setup-23ai.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ Estimated Time: 15 minutes
1313

1414
### Prerequisites
1515

16-
* Basic knowledge of Oracle Cloud Infrastructure (OCI) concepts and consoles
16+
* Basic knowledge of Oracle Cloud Infrastructure (OCI) concepts and console
1717
* Basic Linux knowledge
1818

1919
> Note: Any kind of Linux-based system is okay, but you will need to modify the following instructions to suit your specific setup.
2020
2121
## Task 1: Create a compute instance to run the lab
2222

23+
> Note: If you don't know how to create a virtual machine and connect to it via SSH, please [see this lab first](https://livelabs.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=648&clear=RR,180&session=108750023091545). The following section will only give you a brief overview.
24+
2325
Open your Oracle Cloud Infrastructure Cloud Console and make sure you are in the "US Midwest (Chicago)" region, which is necessary to access the OCI Generative AI services endpoint.
2426

2527
![console](images/image1.png)
@@ -32,19 +34,21 @@ Open your Oracle Cloud Infrastructure Cloud Console and make sure you are in the
3234

3335
4. Choose the "Oracle Linux 8" image.
3436

35-
5. Choose the instance shape based on your requirements.
37+
5. Choose a `VM.Standard.E4.Flex` shape.
38+
39+
6. In the Networking section, most of the defaults are perfect for our purposes. However, you will need to scroll down and select the Assign a public IPv4 address option.
3640

37-
6. Configure the networking options and ensure that you have proper security lists that allow SSH (port 22) and Jupyter Lab (port 8888).
41+
6. Configure the security list to allow SSH (port 22) and Jupyter Lab (port 8888). [See here](https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/securitylists.htm) how to do it.
3842

39-
7. Connect to your remote instance using SSH.
43+
7. Create your instance by clicking on the `Create` button.
44+
45+
8. Connect to your remote instance using SSH.
4046
```
4147
<copy>
42-
ssh opc@[remote IP]
48+
ssh -i <private_ssh_key> opc@<public_ip_address>
4349
</copy>
4450
```
4551

46-
> Note: The exact connection details depend on how you configured remote access when creating the instance.
47-
4852
## Task 2: Install and configure the database (Oracle Database 23ai Free)
4953
For simplicity, we will install our database in a container using Podman, a popular container management tool similar to Docker.
5054

ai-chatbot-engine/setup-python/setup-python.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Estimated Time: 15 minutes
1919

2020
## Task 1: Install Python
2121

22+
> Note: First, log in to your remote instance via SSH, as described in the previous lab.
23+
2224
### Step 1: Prerequisites.
2325

2426
```bash
@@ -54,6 +56,14 @@ Estimated Time: 15 minutes
5456

5557
Close and save with `control-x`, `y`, and `Enter`
5658

59+
Make sure the new lines in our `bashrc` are run before going further:
60+
61+
```bash
62+
<copy>
63+
source ~/.bashrc
64+
</copy>
65+
```
66+
5767
### Step 3: Once we have `pyenv` up and running, let's install Python 3.12.
5868
```
5969
<copy>pyenv install 3.12</copy>
@@ -62,6 +72,9 @@ Creating the working folder:
6272
```
6373
<copy>mkdir vectors</copy>
6474
```
75+
```
76+
<copy>cd vectors</copy>
77+
```
6578

6679
### Step 4: Assign the Python version we just downloaded to our working directory:
6780
```
@@ -72,8 +85,17 @@ Now check if it succeeded :
7285
```
7386
<copy>python --version</copy>
7487
```
88+
## Task 2: Install the required frameworks
89+
90+
```bash
91+
<copy>
92+
pip install oracledb
93+
pip install sentence-transformers
94+
pip install oci
95+
</copy>
96+
```
7597

76-
## Task 2: Install and configure Jupyter Lab
98+
## Task 3: Install and configure Jupyter Lab
7799

78100
### Step 1: Install the Jupyter server
79101
```
@@ -87,7 +109,7 @@ If you see an output like this one, it worked.
87109

88110
![Jupyter ourput](images/image4.png)
89111

90-
Leave it running.
112+
Leave it running, but write down the `token` listed in the command output.
91113

92114
### Step 2: Open an SSH tunnel to allow access to the Jupyter Lab server.
93115

@@ -98,24 +120,14 @@ Instead of exposing Jupyter Lab directly to the internet, you can use SSH tunnel
98120
In your local terminal, not within the SSH session with your remote instance, run this:
99121

100122
```bash
101-
<copy>ssh -L 8888:localhost:8888 opc@<remote IP></copy>
123+
<copy>ssh -L 8888:localhost:8888 -i <private_ssh_key> opc@<public_ip_address></copy>
102124
```
103125
> Note: The exact connection details depend on how you configured remote access when creating the instance.
104126
105-
Now, open the Jupyter URL (http://127.0.0.1:8888/lab) in a browser on your local machine.
127+
Now, open the Jupyter URL http://127.0.0.1:8888/lab?token=[`the token listed by your jupyter command output`] in a browser on your local machine.
106128

107129
![jupyter lab](images/image7.png)
108130

109-
## Task 3: Install the required frameworks
110-
111-
```bash
112-
<copy>
113-
pip install oracledb
114-
pip install sentence-transformers
115-
pip install oci
116-
</copy>
117-
```
118-
119131
You may now **proceed to the next lab**
120132

121133
## Learn More

ai-chatbot-engine/vectorization/vectorization.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Let's work with our source files, which contain the knowledge we want to use as
4040
### Source files format
4141
FAQs are loaded from a file, encoded, and stored. For this example, we will use a properly formatted plain text FAQ, following the pattern:
4242
```
43-
<copy>
4443
What is Oracle Cloud Free Tier?
4544
4645
Oracle Cloud Free Tier allows you to sign up for an Oracle Cloud account which provides a number of Always Free services and a Free Trial with US$300 of free credit to use on all eligible Oracle Cloud Infrastructure services for up to 30 days. The Always Free services are available for an unlimited period of time. The Free Trial services may be used until your US$300 of free credits are consumed or the 30 days has expired, whichever comes first.
@@ -58,7 +57,6 @@ Why do I need to provide credit or debit card information when I sign up for Ora
5857
To provide free Oracle Cloud accounts to our valued customers, we need to ensure that you are who you say you are. We use your contact information and credit/debit card information for account setup and identity verification. Oracle may periodically check the validity of your card, resulting in a temporary “authorization” hold. These holds are removed by your bank, typically within three to five days, and do not result in actual charges to your account.
5958
6059
=====
61-
</copy>
6260
```
6361

6462
So, we have the question, an empty line, the answer, and then a separator denoted by `=====`. For this simple example, we load the whole thing into memory. For a small FAQ file, there is no need for a proper vector database; however, if your knowledge base grows, you will want one.
@@ -71,7 +69,7 @@ Now, drag and drop the downloaded file into the Jupyter window to upload it to y
7169
![Jupyter drag&drop](images/image8.png)
7270

7371
### Step 2: Create a new notebook to host our code.
74-
Right-click into the left navigation pane in the Jupyter window and select "New file".
72+
Right-click into the left navigation pane in the Jupyter window and select "New notebook".
7573

7674
![new file](images/image9.png)
7775

@@ -99,7 +97,7 @@ Finally, let's start to code.
9997
file_path = os.path.join(directory_path, filename)
10098

10199
with open(file_path) as f:
102-
raw_faq = f.read()
100+
raw_faq = f.read()
103101

104102
filename_without_ext = os.path.splitext(filename)[0] # remove .txt extension
105103
faqs[filename_without_ext] = [text.strip() for text in raw_faq.split('=====')]
@@ -130,7 +128,7 @@ Finally, let's start to code.
130128
![load txt files](images/image12.png)
131129
132130
133-
3. The final step in preparing the source data is to arrange the above dictionary in a way that is easy to ingest in the vector database.
131+
3. The final step in preparing the source data is to arrange the above dictionary in a way that is easy to ingest in the vector database. Enter this code into a new cell.
134132
135133
```python
136134
<copy>

ai-chatbot-engine/workshops/freetier/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"workshoptitle": "AI Chatbot engine with Oracle Database 23c and OCI Generative AI Services",
3-
"help": "bogdan.farca@oracle.com",
2+
"workshoptitle": "AI Chatbot engine with Oracle Database 23ai and OCI Generative AI Services",
3+
"help": "livelabs-help-db_us@oracle.com",
44
"tutorials": [
55
{
66
"title": "Introduction",

0 commit comments

Comments
 (0)