Skip to content

Commit a13034a

Browse files
authored
Merge branch 'main' into dependabot/pip/ai/generative-ai-service/smart-invoice-extraction/pillow-10.3.0
2 parents 23f9c94 + b25d380 commit a13034a

File tree

74 files changed

+2682
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2682
-57
lines changed

ai/gen-ai-agents/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Oracle’s Generative AI Agents is a fully managed service that combines the pow
99
- [Analysis of Structured Data and Use of AI Agents](https://luigi-saetta.medium.com/analysis-of-structured-data-and-use-of-ai-agents-a40f18da4ed5)
1010
- [AI Agents: The Future of Intelligent Systems in 2025](https://medium.com/@anshuman4luv/ai-agents-the-future-of-intelligent-systems-in-2025-5558c13aa328)
1111
- [LangChain vs LangGraph vs LangFlow vs LangSmith: A Detailed Comparison](https://medium.com/@anshuman4luv/langchain-vs-langgraph-vs-langflow-vs-langsmith-a-detailed-comparison-74bc0d7ddaa9)
12-
- [Developer Coaching: Unlock the power of Oracle AI](https://www.youtube.com/watch?v=6weQp8BugSg&t=2460s)
12+
- [Developer Coaching: Unlock the power of Oracle AI](https://www.youtube.com/watch?v=6weQp8BugSg&t)
13+
- [Build & Scale AI Agents with ODA & Oracle GenAI](https://www.youtube.com/watch?v=0qrxIzTvuaw)
14+
- [From Simple RAG to Agentic RAG: The Evolution of Retrieval-Augmented Generation](https://medium.com/@anshuman4luv/from-simple-rag-to-agentic-rag-the-evolution-of-retrieval-augmented-generation-9221a95a427e)
15+
- [Custom RAG Agents and NVIDIA NIM on Oracle OCI](https://luigi-saetta.medium.com/custom-rag-agents-and-nvidia-nim-on-oracle-oci-3568e1f1b59a)
16+
- [DMCC Transforms HR and Enterprise Operations with Oracle GenAI](https://blogs.oracle.com/ai-and-datascience/post/dmcc-transforms-hr-and-enterprise-operations-with-oracle-genai)
1317

1418
## Reusable Assets Overview
1519
- [HCM agent created by partner Conneqtion Group which contains agents to connect to Fusion HCM, Expense and many others](https://www.youtube.com/watch?v=OhZcWx_H_tQ)

ai/gen-ai-agents/sql-tool/README.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Creating a NL2SQL Agent on OCI
2+
3+
**1. Introduction**
4+
5+
- **Objective**: Step-by-step instructions for building and implementing
6+
a SQL Agent.
7+
8+
- **Overview**: SQL Agent simplifies data tasks by converting natural
9+
language queries into SQL, leveraging large language models (LLMs).
10+
Beyond language capabilities like summarization and text analysis,
11+
LLMs generate SQL, enabling users to interact with databases
12+
effortlessly, without requiring SQL expertise.
13+
14+
**2. Prerequisites**
15+
16+
- **Database Setup:**
17+
18+
Create the database (Oracle Base Database or Autonomous Database).
19+
Database should be in a created in a private subnet (preferred) or
20+
protected by access control from VCN.
21+
22+
- **Create Table and Load Data**
23+
24+
Create tables in the above database and load data. You can follow instructions
25+
[here](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/autonomous-database-serverless/doc/load-data-autonomous.html#GUID-BCD09013-DFC9-4850-BBD2-6A90E9AE884B)
26+
to connect to the DB and load data.
27+
28+
- **Database Tool Connection:**
29+
30+
Create Database Tool Connection to connect to the above database.
31+
Database Tool Connection should use a Private Endpoint to connect to database, You can follow this [doc](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/database-tools/home.htm) for creating a DB tool connection to any Oracle database service in OCI.
32+
33+
- **Prepare Tool Configuration Data**
34+
35+
> User must keep the table DDLs handy before creating agent. Optionally,
36+
> they can also prepare Table Column Descriptions, In Context Examples
37+
> and Custom Instructions. These can be provided to inline to the Agent
38+
> creation wizard. Alternately, these can be uploaded Object Storage
39+
> Bucket and same be used in Agent creation wizard.
40+
41+
- **Policies**
42+
43+
- Create a dynamic group with the below matching rules.
44+
<img src="./media/image1.png"
45+
style="width:6.26806in;height:1.30556in" />
46+
47+
- Add Policies to allow above dynamic group to access resources**:**
48+
49+
allow dynamic-group \<dg-name\> to read database-tools-family in
50+
compartment \<compartment_name\>
51+
allow dynamic-group \<dg-name\> to use database-tools-connections in
52+
compartment \<compartment_name\>
53+
allow dynamic-group \<dg-name\> to read secret-family in compartment
54+
\<compartment_name\>
55+
allow dynamic-group \<dg-name\> to read objects in tenancy
56+
57+
**3. Setting Up the OCI Environment**
58+
59+
**3.1 Logging into OCI Console**
60+
61+
1. Navigate to the [OCI Console](https://www.oracle.com/cloud/).
62+
63+
2. <img src="./media/image2.png"
64+
style="width:6.34306in;height:3.30694in" />Enter your credentials
65+
and click **Sign In** and open Generative AI Agents service.
66+
67+
**4. Creating an agent**
68+
69+
1. Click on **Agent** and select the appropriate **Compartment** where
70+
you want to create the agent.
71+
72+
2. Click on the **Create Agent** button and complete the required
73+
fields:
74+
75+
1. Basic Information
76+
77+
1. Enter the mandatory fields: **Name** and **Welcome
78+
Message**. The **Description** field is optional.
79+
80+
2. Check the box to create endpoints for the agent.
81+
82+
3. <img src="./media/image3.png"
83+
style="width:6.94583in;height:3.29028in" />You can also
84+
allow to add tags to organise this resource. For more info
85+
check
86+
[this](https://docs.oracle.com/en-us/iaas/Content/Tagging/Concepts/taggingoverview.htm).
87+
Refer below screenshot.
88+
89+
2. **Knowledge bases – Not required for SQL.**
90+
91+
3. **Tools**: Select Conserve with your structured data in
92+
database(SQL). Fill in the configuration as described below.
93+
94+
1. **Name**: You need to give a meaningful name to your agent.
95+
96+
2. **Description**: Provide a detailed summary of the data to
97+
be used or query via this tool.
98+
99+
3. **Database schema**: There are two options available to
100+
import the database schema configuration for this tool.
101+
102+
- **Inline** –you can directly paste the SQL schema in the
103+
text box.
104+
<img src="./media/image4.png" style="width:6.5in;height:3.79375in" />
105+
106+
- **Choose from object storage** – You can also import the
107+
database schema configuration from an object storage
108+
bucket. Ensure you have the correct access permissions for
109+
this.
110+
<img src="./media/image5.png" style="width:6.55947in;height:3.06in" />
111+
112+
4. **Model customization** : It has two option. Choose based on
113+
your preference.
114+
115+
- Small(cost-effective) – takes less time to create but less
116+
accuracy.
117+
118+
- Large(more accurate) – longer time but better accuracy.
119+
120+
5. **Dialect** : slightly different variations of SQL, called
121+
dialects. While the core SQL syntax is consistent. we
122+
provide two option for this as well.
123+
124+
- SQLite
125+
126+
- Oracle SQL
127+
<img src="./media/image6.png" style="width:6.21798in;height:2.8782in" />
128+
129+
6. **In-Context Learning Examples:** Provide examples to help
130+
the tool generate more accurate queries. This step is
131+
optional. You can import examples either inline or from an
132+
object storage bucket. <img src="./media/image7.png"
133+
style="width:6.89744in;height:1.08578in" />**
134+
**
135+
136+
7. **Database tool connection:** you need to select and test
137+
appropriate connection tool present in your compartment.
138+
<img src="./media/image8.png"
139+
style="width:6.73316in;height:3.89387in" />
140+
141+
8. **Enable SQL Execution**: To enable SQL execution, turn on
142+
the **Enable SQL Execution** button. This allows the SQL
143+
Agent to execute the query and return the result. If
144+
disabled, the agent will not be able to execute the query.
145+
146+
9. **Enable Self-Correction**: Enable **Self-Correction** by
147+
turning on the **Enable Self-Correction** button. This
148+
allows the SQL Agent to automatically correct the query if
149+
any corrections are needed.
150+
<img src="./media/image9.png"
151+
style="width:4.37304in;height:2.68482in" />
152+
153+
10. **Custom instructions** : you can give custom instructions
154+
like below examples. Or can leave it empty.
155+
<img src="./media/image10.png"
156+
style="width:6.52429in;height:0.98215in" />
157+
158+
11. D**escription of tables and columns:** You can use this
159+
option to provide descriptions for tables and columns.
160+
Descriptions can be imported from object storage, added
161+
inline, or left blank (none).
162+
<img src="./media/image11.png" style="width:6.5in;height:2.02917in" />
163+
164+
3. <img src="./media/image12.png"
165+
style="width:6.91319in;height:3.10278in" />Click on next button,
166+
review and create an agent.
167+
168+
**4. Launch chat**
169+
170+
1. Once the agent is ready and tool is created. You can launch the
171+
chat.
172+
<img src="./media/image13.png" style="width:6.26806in;height:3.1in" />
173+
174+
2. This is how the chat interface will appear, displaying the same
175+
**Welcome Message** that you provided earlier.
176+
<img src="./media/image14.png"
177+
style="width:6.1604in;height:2.68086in" />
178+
179+
2. You can start asking some basic question to get SQL query like
180+
this.
181+
<img src="./media/image15.png"
182+
style="width:6.26806in;height:2.51389in" />
183+
184+
3. You can reset chat session to start new chat.
50.2 KB
Loading
9.32 KB
Loading
18.7 KB
Loading
203 KB
Loading
1.39 MB
Loading
960 KB
Loading
386 KB
Loading
809 KB
Loading
165 KB
Loading
116 KB
Loading
159 KB
Loading
52.3 KB
Loading
31.6 KB
Loading
87.7 KB
Loading
33.2 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Travel Agent
2+
This repository contains all the code for a demo of a **Travel Agent**.
3+
The AI Agent enables a customer to get information about available destinations and to organize a trip, book flight, hotel...
4+
5+
The agent has been developed using **OCI Generative AI** and **LangGraph**.
6+
7+
## Configuration
8+
You only need to create a file, named config_private.py, with the value for **COMPARTMENT_OCID**.
9+
The compartment must be a compartment where you have setup the right policies to access OCI Generative AI.
10+
11+
In config.py AUTH_TYPE is set to API_KEY, therefore you need to have in $HOME/.oci the key pair to access OCI.
12+
13+
## List of libraries used
14+
* oci
15+
* langchain-community
16+
* langgraph
17+
* streamlit
18+
* fastapi
19+
* black
20+
* pydeck
21+
* uvicorn
22+
23+
see also: requirements.txt
24+
25+
## Demo data
26+
Demo data are contained in mock_data.py
27+
28+
If you want some realistic results, you should ask to plan a trip from **Rome** to one
29+
of the following cities:
30+
* Amsterdam
31+
* Barcelona
32+
* Florence
33+
* Madrid
34+
* Valencia
35+
36+
or, simply add other records to the JSON in mock_data.py.
37+
38+
If you want to diplsay the positio of the Hotel in a map, you need to provide in the file
39+
correct values for latitude and longitude.
40+
41+
## Supported languages
42+
As of now, the demo supports:
43+
* English
44+
* Italian
45+
46+
to add other languages, you need to add the translations in translations.py and change, accordingly, some
47+
code in streamlit_app.py.
48+
49+
50+
51+
52+
53+
54+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Base Node class for LangGraph nodes.
3+
4+
This module defines a base class `BaseNode` for all LangGraph nodes,
5+
providing a standard logging interface via `log_info` and `log_error` methods.
6+
Each subclass should implement the `invoke(input, config=None)` method.
7+
"""
8+
9+
import logging
10+
from langchain_core.runnables import Runnable
11+
12+
13+
class BaseNode(Runnable):
14+
"""
15+
Abstract base class for LangGraph nodes.
16+
17+
All node classes in the graph should inherit from this base class.
18+
It provides convenient logging utilities and stores a unique node name
19+
for identification in logs and debugging.
20+
21+
Attributes:
22+
name (str): Identifier for the node, used in logging.
23+
logger (logging.Logger): Configured logger instance for the node.
24+
"""
25+
26+
def __init__(self, name: str):
27+
"""
28+
Initialize the base node with a logger.
29+
30+
Args:
31+
name (str): Unique name of the node for logging purposes.
32+
"""
33+
self.name = name
34+
self.logger = logging.getLogger(name)
35+
self.logger.setLevel(logging.INFO)
36+
37+
# Attach a default console handler if no handlers are present
38+
if not self.logger.handlers:
39+
handler = logging.StreamHandler()
40+
handler.setLevel(logging.INFO)
41+
formatter = logging.Formatter(
42+
"[%(asctime)s] %(levelname)s in %(name)s: %(message)s"
43+
)
44+
handler.setFormatter(formatter)
45+
self.logger.addHandler(handler)
46+
47+
def log_info(self, message: str):
48+
"""
49+
Log an informational message.
50+
51+
Args:
52+
message (str): The message to log.
53+
"""
54+
self.logger.info("[%s] %s", self.name, message)
55+
56+
def log_error(self, message: str):
57+
"""
58+
Log an error message.
59+
60+
Args:
61+
message (str): The error message to log.
62+
"""
63+
self.logger.error("[%s] %s", self.name, message)
64+
65+
def invoke(self, state: dict, config=None, **kwargs) -> dict:
66+
"""
67+
Abstract method to be implemented by subclasses.
68+
69+
Args:
70+
state (dict): The current state of the workflow.
71+
config (optional): Configuration options for the node.
72+
**kwargs: Additional keyword arguments.
73+
74+
Returns:
75+
dict: Updated state after processing.
76+
"""
77+
raise NotImplementedError("Subclasses must implement this method.")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
General configuration options
3+
"""
4+
5+
#
6+
# application configs
7+
#
8+
DEBUG = False
9+
10+
# this is the list of the mandatory fields in user input
11+
# if any of these fields is missing, the agent will ask for clarification
12+
REQUIRED_FIELDS = [
13+
"place_of_departure",
14+
"destination",
15+
"start_date",
16+
"end_date",
17+
"num_persons",
18+
"transport_type",
19+
]
20+
21+
# OCI GenAI services configuration
22+
23+
# can be also INSTANCE_PRINCIPAL
24+
AUTH_TYPE = "API_KEY"
25+
26+
REGION = "eu-frankfurt-1"
27+
SERVICE_ENDPOINT = f"https://inference.generativeai.{REGION}.oci.oraclecloud.com"
28+
29+
# seems to work fine with both models
30+
MODEL_ID = "meta.llama-3.3-70b-instruct"
31+
# MODEL_ID = "cohere.command-a-03-2025"
32+
33+
MAX_TOKENS = 2048
34+
35+
# Mock API configuration
36+
HOTEL_API_URL = "http://localhost:8000/search/hotels"
37+
TRANSPORT_API_URL = "http://localhost:8000/search/transport"
38+
39+
# Hotel Map
40+
MAP_STYLE = "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Config private template
3+
4+
use it to create your config_private.py file
5+
This file contains sensitive information such as compartment OCIDs, and other
6+
"""
7+
8+
COMPARTMENT_OCID = "ocid1.compartment.xxxx"

0 commit comments

Comments
 (0)