Skip to content

Commit

Permalink
add sql example
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarrata committed Feb 4, 2025
1 parent 0e45c42 commit b7fc1a2
Show file tree
Hide file tree
Showing 15 changed files with 644 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bootstrap/database/db-init-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
command: ['sh', '-c', 'until nc -z -v -w30 $POSTGRESQL_DATABASE 5432; do echo "Waiting for database connection..."; sleep 2; done;']
env:
- name: POSTGRESQL_DATABASE
value: agenticdb.agentic-db.svc.cluster.local
value: agenticdb.agentic-zone.svc.cluster.local
containers:
- name: postgresql
image: registry.redhat.io/rhel9/postgresql-13:latest
Expand All @@ -34,7 +34,7 @@ spec:
name: agenticdb
key: database-password
- name: POSTGRESQL_DATABASE_HOST
value: agenticdb.agentic-db.svc.cluster.local
value: agenticdb.agentic-zone.svc.cluster.local
command: ["/bin/bash", "-c"]
args:
- |
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/database/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ spec:
- name: POSTGRESQL_USER
valueFrom:
secretKeyRef:
name: claimdb
name: agenticdb
key: database-user
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: claimdb
name: agenticdb
key: database-password
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
name: claimdb
name: agenticdb
key: database-name
securityContext:
capabilities: {}
Expand All @@ -66,11 +66,11 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- name: claimdb-data
- name: agenticdb-data
mountPath: /var/lib/pgsql/data
volumes:
- name: claimdb-data
- name: agenticdb-data
persistentVolumeClaim:
claimName: claimdb
claimName: agenticdb
strategy:
type: Recreate
2 changes: 1 addition & 1 deletion bootstrap/database/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ resources:
- secret.yaml
- deployment.yaml
- service.yaml
# - sql-script-configmap.yaml
- sql-script-configmap.yaml
# wave 2
- db-init-job.yaml
2 changes: 1 addition & 1 deletion bootstrap/database/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claimdb
name: agenticdb
namespace: agentic-zone
labels:
app: agentic-db
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/database/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: Secret
apiVersion: v1
metadata:
name: claimdb
name: agenticdb
namespace: agentic-zone
labels:
app: agentic-db
Expand Down
64 changes: 64 additions & 0 deletions bootstrap/database/sql-script-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sql-script-configmap
annotations:
argocd.argoproj.io/sync-wave: "1"
data:
script.sql: |
-- Ensure the schema exists
CREATE SCHEMA IF NOT EXISTS agenticdb AUTHORIZATION agenticdb;
-- Drop existing tables if they exist
DROP TABLE IF EXISTS agenticdb.transactions CASCADE;
-- Drop existing sequences if they exist
DROP SEQUENCE IF EXISTS agenticdb.transactions_id_seq;
-- Create a sequence for transaction IDs
CREATE SEQUENCE IF NOT EXISTS agenticdb.transactions_id_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
-- Create the transactions table
CREATE TABLE IF NOT EXISTS agenticdb.transactions
(
id INTEGER NOT NULL DEFAULT nextval('agenticdb.transactions_id_seq'::regclass),
transaction_id TEXT COLLATE pg_catalog."default" UNIQUE NOT NULL,
client_name TEXT COLLATE pg_catalog."default" NOT NULL,
transaction_type TEXT COLLATE pg_catalog."default" CHECK (transaction_type IN ('BUY', 'SELL', 'SHORT SELL')),
stock_symbol TEXT COLLATE pg_catalog."default" NOT NULL,
shares INTEGER NOT NULL CHECK (shares > 0),
price_per_share NUMERIC(10,2) NOT NULL CHECK (price_per_share > 0),
broker TEXT COLLATE pg_catalog."default",
transaction_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
-- Link the sequence to the table
ALTER SEQUENCE agenticdb.transactions_id_seq OWNED BY agenticdb.transactions.id;
-- Insert sample transactions
-- TRANSACTION 1: Alice Johnson buys 50 shares of Apple (AAPL)
INSERT INTO agenticdb.transactions (transaction_id, client_name, transaction_type, stock_symbol, shares, price_per_share, broker, transaction_time)
VALUES ('TXN1001', 'Alice Johnson', 'BUY', 'AAPL', 50, 185.75, 'Morgan Stanley', '2024-06-15 09:30:00');
-- TRANSACTION 2: Michael Smith sells 100 shares of Tesla (TSLA)
INSERT INTO agenticdb.transactions (transaction_id, client_name, transaction_type, stock_symbol, shares, price_per_share, broker, transaction_time)
VALUES ('TXN1002', 'Michael Smith', 'SELL', 'TSLA', 100, 245.20, 'Charles Schwab', '2024-06-15 10:15:00');
-- TRANSACTION 3: Emma Davis buys 200 shares of Microsoft (MSFT)
INSERT INTO agenticdb.transactions (transaction_id, client_name, transaction_type, stock_symbol, shares, price_per_share, broker, transaction_time)
VALUES ('TXN1003', 'Emma Davis', 'BUY', 'MSFT', 200, 340.10, 'JPMorgan Chase', '2024-06-15 11:45:00');
-- TRANSACTION 4: Robert Miller short-sells 75 shares of Nvidia (NVDA)
INSERT INTO agenticdb.transactions (transaction_id, client_name, transaction_type, stock_symbol, shares, price_per_share, broker, transaction_time)
VALUES ('TXN1004', 'Robert Miller', 'SHORT SELL', 'NVDA', 75, 462.85, 'Goldman Sachs', '2024-06-15 14:30:00');
8 changes: 7 additions & 1 deletion content/modules/ROOT/pages/03-02-tools-usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ Through tool calling, LLMs can:
- **Perform Specialized Calculations**: Use tools like code interpreters to execute complex calculations or data transformations.
- **Format Responses for Structured Systems**: Generate responses in specific schemas required by APIs or databases, ensuring smooth communication with these systems.

== Exercise: Tools Usage - Practical Example
== Exercise: Tools Usage (Internet Search) - Practical Example

Let's see the Tools Usage in Action!

From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `02.1-tools-calling.ipynb` and follow the instructions.

== Exercise: Tools Usage (Database Query) - Practical Example

Let's see the Tools Usage in Action!

From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `02.2-tools-calling-sql.ipynb` and follow the instructions.

== Benefits of Using Tools with LLMs

Incorporating tools into LLM workflows enables AI systems to handle a broader range of tasks, increasing both accuracy and flexibility. For example:
Expand Down
2 changes: 1 addition & 1 deletion content/modules/ROOT/pages/03-03-chain-of-thought.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ image::04/04-02-cot.png[Chain of Thought, scaledwidth="20%"]

Let's see the Chain of Thought in Action!

From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `02.2-chain-of-thought.ipynb` and follow the instructions.
From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `02.3-chain-of-thought.ipynb` and follow the instructions.
2 changes: 1 addition & 1 deletion content/modules/ROOT/pages/03-04-react-prompting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ image::04/04-01-react-basic.png[ReAct Basic]

Let's see the ReAct Pattern in Action!

From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `2.3-react-prompting.ipynb` and follow the instructions.
From the `agentic-workshop/lab-materials/02` folder, please open the notebook called `2.4-react-prompting.ipynb` and follow the instructions.
6 changes: 6 additions & 0 deletions content/modules/ROOT/pages/03-05-rag.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ In a RAG setup, the model follows a two-step process:

image::04/04-04-rag.jpg[RAG]

== Exercise: RAG Pattern - Practical Example

Let's see the RAG Pattern in Action!

From the `agentic-workshop/lab-materials/03` folder, please open all the notebooks on that folder in order and follow the instructions.

== Benefits of RAG

- **Enhanced Accuracy**: RAG reduces reliance on outdated or incomplete training data, leading to more accurate and contextually relevant responses.
Expand Down
Loading

0 comments on commit b7fc1a2

Please sign in to comment.