Skip to content

Commit

Permalink
Merge branch 'oracle-livelabs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martygubar authored Aug 5, 2024
2 parents 8023a90 + 11e7394 commit 3e411c9
Show file tree
Hide file tree
Showing 187 changed files with 2,803 additions and 149 deletions.
12 changes: 10 additions & 2 deletions auto-partitioning/create-table/create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ We are now creating a nonpartitioned table that will become our candidate table
-- keep the random strings apart when written to storage, which will
-- make compression less effective. We want to make the table large
-- as quickly as possible so that it qualifies for auto partitioning.
--
-- If you want to use a paid (non-free) Autonomouse Database environment,
-- the minimum size for the table is 64GB. You can create a suitable table
-- by changing the following line in the SQL statement below.
-- From this:
-- from dual connect by level <= 3 )
-- To this:
-- from dual connect by level <= 30 )
--
alter session set optimizer_ignore_hints = false;
-- Table data is compressed by default, so we will insert random data
Expand Down Expand Up @@ -142,4 +150,4 @@ A candidate table for automatic partitioning must be at least 5 GB in size in a
## Acknowledgements
* **Author** - Nigel Bayliss, Dec 2021
* **Contributor** - Hermann Baer
* **Last Updated By/Date** - Nigel Bayliss, May 2024
* **Last Updated By/Date** - Nigel Bayliss, Aug 2024
2 changes: 1 addition & 1 deletion shared/adb-ai-web-app/introduction/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

In this workshop, you will learn how to use large language models (LLMs) hosted by OCI Generative AI and natural language to analyze your organization's private data in Autonomous Database. Your AI projects will be published as RESTful services that can then be invoked from any application. You will use a React app to surface these analytics.

> **NOTE:** Your tenancy must be subscribed to the **US Midwest (Chicago)** region in order to run this workshop. See the [OCI documentation](https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingregions.htm) for more details.
> **NOTE:** Your tenancy must be subscribed to the **US Midwest (Chicago)** _or_ **Germany Central (Frankfurt)** regions in order to run this workshop. See the [OCI documentation](https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingregions.htm) for more details.
In our scenario, customers for MovieStream - a fictitious moviestreaming company - will receive a targeted promotion with recommended movies. The recommendations will be generated by the LLM based on those movies that the customer previously enjoyed. In addition, a promotional offer will be made based on the customer's geographic location using Autonomous Database's spatial APIs. Architecturally, you will create an open, RESTful service that generates the targeted offer.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Use an OCI Cloud Stack to set up your workshop environment. This step will creat
* **Password:** Enter a password for the `ADMIN` user of your choice such as **`Training4ADW`**. **Important**: Make a note of this password as you will need it to perform later tasks.
* For the other fields, accept the default selections.

>**Note:** The **Secret Key** is **not Required** for this Lab since OCI Generative AI does not use a secret key for Resource Operations.
>**Note:** In the **Workshop Settings** section, the **Secret API key used to connect to AI model** field is **_not Required_** for this Lab since OCI Generative AI does not use a secret key for Resource Operations.
![The Configure variables step 2 of the wizard](./images/configure-variables.png =80%x*)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Allow Users to Connect to Your LLM

<!---
I removed this lab from the manifest.json on July 24 since we are using oci genai.
I am keeping the lab in case we need instruction in the future on using OpenAI as the model.
--->
## Introduction

You can use different large language models (LLM) with Autonomous Database. In this lab, you will enable the user **`MOVIESTREAM`** to use the LLM that you set up in the previous lab.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
233 changes: 233 additions & 0 deletions shared/adb-speaks-human/integrate-genai/integrate-genai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
# Integrate OCI Generative AI with Autonomous Database

## Introduction

In the previous lab, you saw a snapshot of the creative responses that can be produced by LLMs. Let's now apply that creativity to your data. The first step is to integrate OCI Generative AI with Autonomous Database.

You can use different LLMs with Autonomous Database. This lets you pick the best model for your use case. Select AI profiles encapsulate the connections to each model; you specify which profile to use when generating results. In this lab, you will enable the user **`MOVIESTREAM`** to use multiple LLMs offered by the OCI Generative AI service.

Estimated Time: 10 minutes.

### Objectives

In this lab, you will:

* Enable use of Resource Principals for the **`MOVIESTREAM`** user
* Create Select AI Profile for OCI GenAI
* Test the AI profile

### Prerequisites

- This lab requires the completion of **Labs 1 and 2** in the **Contents** menu on the left.

## Task 1: Enable Resource Principal Usage for the MOVIESTREAM User

The **`MOVIESTREAM`** user will connect to **OCI Generative AI** using resource principals (for more information, see [Use Resource Principal to Access Oracle Cloud Infrastructure Resources](https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/resource-principal.html#GUID-E283804C-F266-4DFB-A9CF-B098A21E496A)). This means that the ADB resource (i.e. your ADB instance) needs access to OCI Generative AI. The OCI policy you created in the previous lab authorized that access.

In ADB, enable the use of resource principals for the **`MOVIESTREAM`** user.

1. From the **Console,** Open the **Navigation** menu and click **Oracle Database.** Under **Oracle Database,** click **Autonomous Database.**

2. On the **Autonomous Database** page, click your ADB instance name link, **TrainingAIWorkshop** in our example.

![Open ADB](./images/click-adb-instance.png "")

3. On the **Autonomous Database details** page, click the **Database actions** drop-down list, and then click **SQL**.

![Select SQL option](./images/click-sql.png "")

>**Note:** The setup script automatically enabled Resource Principals usage for MovieStream. The following 2 steps are optional.
4. _The deployment in Lab 1 already set up resource principals in your database_. To better understand the use of resource principals, let's undo that enablement and recreate it. Disable the use of resource principals for the **`MOVIESTREAM`** user. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script (F5)** icon in the Worksheet toolbar.

```
<copy>
begin
dbms_cloud_admin.disable_resource_principal(username => 'MOVIESTREAM');
end;
/
</copy>
```
![Disable resource principal](./images/disable-resource.png "")
5. Now let's re-enable the use of the resource principal by the **`MOVIESTREAM`** user. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script** icon.
```
<copy>
begin
dbms_cloud_admin.enable_resource_principal(username => 'MOVIESTREAM');
end;
/
</copy>
```
![Enable resource principal](./images/enable-resource-principal.png "")
6. Sign out of the **`ADMIN`** user. On the **Oracle Database Actions | SQL banner**, click the drop-down list next to the **`ADMIN`** user, and then select **Sign Out** from the drop-down menu.
![Sign out from Admin](./images/sign-out.png "")
## Task 2: Create an AI Profile for OCI Generative AI
A Select AI profile encapsulates connection information for an AI provider. This includes:
1. A security credential (e.g. the resource principal)
2. The name of the provider
3. The name of the LLM (optional)
4. A list of target tables that will be used for natural language queries (required when using NL2SQL)
You can create as many profiles as you need, which is useful when comparing the quality of the results of different models.
For a complete list of the Select AI profile attributes, see the [DBMS\_CLOUD\_AI\_Package] (https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/dbms-cloud-ai-package.html#GUID-D51B04DE-233B-48A2-BBFA-3AAB18D8C35C) in the Using Oracle Autonomous Database Serverless documentation.
>**Note:** The deployment script created a Select AI profile using the code below:
```
begin

-- Create an AI profile that uses the default LLAMA model on OCI
dbms_cloud_ai.create_profile(
profile_name => 'genai',
attributes =>
'{"provider": "oci",
"credential_name": "OCI$RESOURCE_PRINCIPAL",
"comments":"true",
"object_list": [
{"owner": "MOVIESTREAM", "name": "GENRE"},
{"owner": "MOVIESTREAM", "name": "CUSTOMER"},
{"owner": "MOVIESTREAM", "name": "PIZZA_SHOP"},
{"owner": "MOVIESTREAM", "name": "STREAMS"},
{"owner": "MOVIESTREAM", "name": "MOVIES"},
{"owner": "MOVIESTREAM", "name": "ACTORS"}
]
}'
);
end;
/
```
1. Sign into the SQL worksheet as the **`MOVIESTREAM`** user with the password **`watchS0meMovies#`**. On the **Database Actions Launchpad** page, click the **Development** tab, and then click the **SQL** tab. The SQL Worksheet is displayed.
>**Note:** the **`MOVIESTREAM`** user was created as part of the setup and tables that were created in that schema. You can find the Moviestream password by navigating to **Developer Services** from the Navigation menu. Next, click **Resource Manager** > **Stacks** > Select the stack we created, **Deploy-ChatDB-Autonomous-Database...** > Select the job we created, **ormjob2024117214431** (use your own stack number)> Select **Outputs** under **Resources**.
![Moviestream password](./images/moviestream-output-pswd.png "")
2. Create an AI profile for the **Meta Llama 3 model**. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script** icon.
```
<copy>
BEGIN
-- drops the profile if it already exists
DBMS_CLOUD_AI.drop_profile(
profile_name => 'ociai_llama',
force => true
);
-- Meta Llama 3 (this is the default model, so you could skip the model attribute if you like)
DBMS_CLOUD_AI.create_profile (
profile_name => 'ociai_llama',
attributes =>
'{"provider": "oci",
"credential_name": "OCI$RESOURCE_PRINCIPAL",
"object_list": [
{"owner": "moviestream", "name": "GENRE"},
{"owner": "moviestream", "name": "CUSTOMER"},
{"owner": "moviestream", "name": "PIZZA_SHOP"},
{"owner": "moviestream", "name": "STREAMS"},
{"owner": "moviestream", "name": "MOVIES"},
{"owner": "moviestream", "name": "ACTORS"}
],
"model": "meta.llama-3-70b-instruct"
}');
END;
/
</copy>
```
![Create AI profile](./images/create-llama.png "")
3. Create an AI profile for the **Cohere model**. This model will not be used for SQL generation - it will only be used for generating innovative content. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script** icon.
```
<copy>
BEGIN
-- drops the profile if it already exists
DBMS_CLOUD_AI.drop_profile(profile_name => 'OCIAI_COHERE', force => true);
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'OCIAI_COHERE',
attributes => '{"provider": "oci",
"credential_name": "OCI$RESOURCE_PRINCIPAL",
"model": "cohere.command-r-plus",
"oci_apiformat":"COHERE"
}');
END;
/
</copy>
```
![Create AI profile](./images/create-cohere.png "")
## Task 3: Test the AI profile
We will use the PL/SQL API to generate a response from the Cohere model. This example is using the **chat** action. It is not using any private data coming from your database.
1. Test the LLM and learn about Autonomous Database as the MOVIESTREAM user using the **Cohere model**. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script** icon.
```
<copy>
SELECT DBMS_CLOUD_AI.GENERATE(
prompt => 'what is oracle autonomous database',
profile_name => 'OCIAI_COHERE',
action => 'chat')
FROM dual;
</copy>
```
![Test the LLM](./images/cohere-output.png "")
2. Compare the Cohere model to the **Llama model**. Copy and paste the following code into your SQL Worksheet, and then click the **Run Script** icon.
```
<copy>
SELECT DBMS_CLOUD_AI.GENERATE(
prompt => 'what is oracle autonomous database',
profile_name => 'OCIAI_LLAMA',
action => 'chat')
FROM dual;
</copy>
```
![Generate sentence-like response](./images/llama-chat.png "")
## Summary
You learned how to integrate Autonomous Database with OCI Generative AI. And, you chatted with different models hosted on OCI Generative AI. Next, let's see how to use our private data with LLMs.
You may now proceed to the next lab.
## Learn More
* [DBMS\_NETWORK\_ACL\_ADMIN PL/SQL Package](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_NETWORK_ACL_ADMIN.html#GUID-254AE700-B355-4EBC-84B2-8EE32011E692)
* [DBMS\_CLOUD\_AI Package](https://docs.oracle.com/en-us/iaas/autonomous-database-serverless/doc/dbms-cloud-ai-package.html)
* [Using Oracle Autonomous Database Serverless](https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/index.html)
* [Overview of Generative AI Service](https://docs.oracle.com/en-us/iaas/Content/generative-ai/overview.htm)
## Acknowledgements
* **Author:** Lauran K. Serhal, Consulting User Assistance Developer
* **Contributors:**
* Marty Gubar, Product Management
* Stephen Stuart, Cloud Engineer
* Nicholas Cusato, Cloud Engineer
* Olivia Maxwell, Cloud Engineer
* Taylor Rees, Cloud Engineer
* Joanna Espinosa, Cloud Engineer
* **Last Updated By/Date:** Lauran K. Serhal, July 2024
Data about movies in this workshop were sourced from **Wikipedia**.
Copyright (c) 2024 Oracle Corporation.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled [GNU Free Documentation License](files/gnu-free-documentation-license.txt)
6 changes: 5 additions & 1 deletion shared/adb-speaks-human/introduction/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

In this workshop, you will learn how to use **Autonomous Database Select AI (Select AI)** to query your data using natural language; you don't need prior knowledge of the data structure or how that data is accessed. Next, you'll use those capabilities in a voice-enabled APEX app that enables you to get answers to your questions from your desktop or mobile device.

> **NOTE:** Your tenancy must be subscribed to the **US Midwest (Chicago)** _or_ **Germany Central (Frankfurt)** regions in order to run this workshop. See the [OCI documentation](https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/managingregions.htm) for more details.

### What is Natural Language Processing?

Natural language processing is the ability of a computer application to understand human language as it is spoken and written. It is a component of artificial intelligence (AI).
Expand All @@ -22,6 +25,7 @@ In this workshop, you will:
* Use the Select AI demo application to chat with your data in your own language

### Oracle MovieStream Business Scenario

The workshop's business scenario is based on Oracle MovieStream - a fictitious movie streaming service that is similar to services to which you currently subscribe. You'll be able to ask questions about movies, customers who watch movies, and the movies they decide to watch.

You may now proceed to the next lab.
Expand All @@ -34,7 +38,7 @@ You may now proceed to the next lab.
## Acknowledgements
* **Author:** Lauran K. Serhal, Consulting User Assistance Developer
* **Contributor:** Marty Gubar, Product Manager
* **Last Updated By/Date:** Lauran K. Serhal, April 2024
* **Last Updated By/Date:** Lauran K. Serhal, July 2024

Data about movies in this workshop were sourced from **Wikipedia**.

Expand Down
Loading

0 comments on commit 3e411c9

Please sign in to comment.