A utilities library for Common AI Platform
Project description
ai-cap-utils
A library to simplify your use case with chat bot with LLMs. Perfect for Common AI Platform.
Installation
uv add ai-cap-utils
Usage
See example.py and example_multiagents.py.
General
from ai_cap_utils.agent import BaseAgent
from ai_cap_utils.agent.prebuilt import SummariserAgent
from ai_cap_utils.tool import tool
# --------------------------------------------
# Create and run your own agent with some tool
# --------------------------------------------
@tool
def add_numbers(a: int, b: int):
"""Adds two numbers together"""
return a + b
agent = BaseAgent(
system_prompt="You are a helpful assistant that answers everything nicely (only that you can do or know)",
tools=[add_numbers],
)
r = agent.chat_each_message("hello")
r = agent.chat_each_message("add two numbers for me")
r = agent.chat_each_message("2 and 4")
print(r) # Inpect the output
print()
# You can use `chat_interact()` method to have an interactive session
agent.chat_interact()
Now, if you use self.chat_interact(), save the file and run this file in the command line.
uv run your_file.py
Or activate your python environment and run
python your_file.py
Example output:
================================ Human Message =================================
hello
================================== Ai Message ==================================
Hello! How can I assist you today?
================================ Human Message =================================
add two numbers for me
================================== Ai Message ==================================
Of course! Please provide the two numbers you'd like to add.
================================ Human Message =================================
2 and 4
================================== Ai Message ==================================
Tool Calls:
add_numbers (call_kGDJ89gTwG6cTZFT7cWr1dBs)
Call ID: call_kGDJ89gTwG6cTZFT7cWr1dBs
Args:
a: 2
b: 4
================================= Tool Message =================================
Name: add_numbers
6
================================== Ai Message ==================================
The sum of 2 and 4 is 6.
Initialise an agent using a Google's credentials dict
from ai_cap_utils.tool import tool
from ai_cap_utils.agent import BaseAgent
# --------------------------------------------
# Import some pre-defined agent
# --------------------------------------------
sum_agent = SummariserAgent()
# --------------------------------------------
# Create your own math agent
# --------------------------------------------
@tool
def add_numbers(a: int, b: int):
"""Add two numbers together"""
return a + b
@tool
def multiplication(a: float, b: float):
"""Multiply two numbers together"""
return a * b
math_system_prompt = "You are a specialist in math problems, you can add and multiply."
# Get a dictionary somehow... (Usually, you can pass a path to your credentials.json)
# But if the credentials are retreived from a secret manager, you can pass in directly.
google_creds = {
"type": "service_account",
"project_id": "random-project",
"private_key_id": "your-private-key",
"private_key": "-----BEGIN PRIVATE KEY-----\nsome-random-gibberish\n-----END PRIVATE KEY-----\n",
"client_email": "user@random-project.iam.gserviceaccount.com",
"client_id": "12345678910",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/roojai%40random-project.iam.gserviceaccount.com",
}
math_agent = BaseAgent(
system_prompt=math_system_prompt,
tools=[add_numbers, multiplication],
google_credentials_path=google_creds,
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_cap_utils-0.4.0.tar.gz.
File metadata
- Download URL: ai_cap_utils-0.4.0.tar.gz
- Upload date:
- Size: 94.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aa9ac4967dac2ae3d61e503415ca5f639108b8a8e80d09f8058e76c4c3bb51b
|
|
| MD5 |
b33ba6e1e6bd49697e892a6228065ef1
|
|
| BLAKE2b-256 |
efbcdb13f33ce37d6562636792e05fefb314c21dc7c60ea4021fe5b49ce6c6cb
|
File details
Details for the file ai_cap_utils-0.4.0-py3-none-any.whl.
File metadata
- Download URL: ai_cap_utils-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2583aa4503e037ebd27fa7f419ad715468bccac687482992489cf179792fdd8a
|
|
| MD5 |
c28055195106f2476acae761a90fe2c6
|
|
| BLAKE2b-256 |
a078f9e611c8170d3fc2b533a064dc340dcbc631d6b74b99302a677a839502fa
|