first commit

This commit is contained in:
2025-03-06 15:37:13 -03:00
parent 7e0fb54b7b
commit 1e8ffd5f0e
9 changed files with 71 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
# AI Agents: The New Bridge Between Legacy APIs and Business Intelligence
# Develop an Agent AI with Oracle Cloud Generative AI
## Introduction
@@ -61,9 +61,56 @@ The langchain.tools library understands the scope of work by associating the con
Another interesting point about the langchain.tools library is that the service signature attributes are also interpreted, that is, the library itself determines how to forward the request in natural language and define the attributes of the parameters of the service in question. This is already very impressive in itself, as it greatly reduces the implementation burden on integrations. In the traditional integration model, there is time to be spent defining the FROM-TO between the source and destination of these integrations. This is a very reasonable effort. In the Agent AI model, it is through the context that the attributes are passed, that is, the library can determine what each parameter is and pass it to the service in the correct way.
### Test the Code
You can test and adjust the code for your purposes. The service named "delivery_address" was implemented calling a REST API. In this example, you can test the code change the real REST request to a fake request. To do this, comment the real code:
![img_1.png](images/img_11.png)
To comment the code, just put the "#" into the lines:
![img_2.png](images/img_12.png)
And discomment this code:
![img_3.png](images/img_13.png)
You can integrate you own API. Using the Oracle Cloud resources, you can use:
- **Oracle Cloud API Gateway**
- **Oracle Integration**
- **Oracle Cloud Kubernetes Engine**
- **Oracle Cloud Streaming**
![img.png](images/img_16.png)
And you can integrate with on-premises or other cloud resources.
### Configure the code
This python code needs some libraries. So you need to download the [requirements.txt](./source/requirements.txt) file. This file contains the libraries.
Run this code to install the libraries in your terminal:
pip install -r requirements.txt
You need to configure the OCI-CLI and link with your tenancy. You can install and configure following this material: [Installing the OCI-CLI](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm)
After install the libraries and the OCI-CLI, you need to configure a compartment to store your resources for the Generative AI. Please, change the compartment_id. Maintain the auth_profile with DEFAULT.
![img_5.png](images/img_15.png)
### Run the code
You can run the code executing this command on your terminal:
python agent_ocigenai.py
![img.png](images/img_8.png)
### Scenarios for Agent AI
## Scenarios for Agent AI
There are several scenarios for integrations with multiple REST APIs and the use of AGENT AI. The complexities between mapping business information and available APIs are many. This is very common in several corporate business situations. Here are some examples where an AGENT AI can facilitate this task:

BIN
images/img_11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
images/img_12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
images/img_13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
images/img_14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
images/img_15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
images/img_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 KiB

View File

@@ -83,6 +83,22 @@ def order_cost():
print("Total: $", total)
return {"total_cost": total, "order_items": order_list}
# @tool
# def delivery_address(postalCode: str, number: str = "", complement: str = "") -> str:
# """Find the complete address of a postal code to delivery, along with the building number and complement.
# The customer can ask for 'delivery to' or 'my address is'. postalCode normally is the postal code or CEP,
# number is the number of buiding and complenent is the apartment or other complement for the address. always confirm the address
# and the total cost of order."""
#
# url = f"https://xxxxxxxxxxxxxxxxxx.apigateway.us-ashburn-1.oci.customer-oci.com/cep/cep?cep={postalCode}"
# response = get_rest_service_auth(url)
#
# address = response["frase"]
# full_address = f"{address}, Number: {number}, Complement: {complement}"
# print(full_address)
# return str(full_address)
@tool
def delivery_address(postalCode: str, number: str = "", complement: str = "") -> str:
"""Find the complete address of a postal code to delivery, along with the building number and complement.
@@ -90,11 +106,7 @@ def delivery_address(postalCode: str, number: str = "", complement: str = "") ->
number is the number of buiding and complenent is the apartment or other complement for the address. always confirm the address
and the total cost of order."""
url = f"https://cihjkhlijtmunsiiokgrhetowu.apigateway.us-ashburn-1.oci.customer-oci.com/cep/cep?cep={postalCode}"
response = get_rest_service_auth(url)
address = response["frase"]
full_address = f"{address}, Number: {number}, Complement: {complement}"
full_address = f"Paulista Avenue, 1000 - 01310-000 - Sao Paulo - SP"
print(full_address)
return str(full_address)
@@ -124,7 +136,7 @@ llm = ChatOCIGenAI(
model_id="cohere.command-r-08-2024",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="ocid1.compartment.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
auth_profile="LATINOAMERICA", # replace with your profile name,
auth_profile="DEFAULT", # replace with your profile name,
model_kwargs={"temperature": 0.1, "top_p": 0.75, "max_tokens": 2000}
)

4
source/requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
langchain
langchain_community
langchain-core
oci-cli