Requirements

Please ensure you have the following:

  • Python 3.10+
  • pip or Poetry
  • ACI.dev account: Sign up at platform.aci.dev with your sign up code
  • An API key: Can be created in project settings on the aipolabs developer portal

Install and Use the Aipolabs ACI

1. Install Aipolabs ACI Python Client

Install with pip:

pip install aipolabs

Install with poetry:

poetry add aipolabs

2. Set up your Aipolabs ACI Client

from aipolabs import Aipolabs

client = Aipolabs(
    # it reads from environment variable by default so you can omit it if you set it in your environment
    api_key=os.environ.get("AIPOLABS_API_KEY")
)

3. Add a Tool to Your LLM Request

function_definition = aipolabs.functions.get_definition("BRAVE_SEARCH__WEB_SEARCH")

response = openai.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {
                "role": "system",
                "content": "You are a helpful assistant with access to a variety of tools.",
            },
            {
                "role": "user",
                "content": "What is aipolabs?",
            },
        ],
        tools=[function_definition],
        tool_choice="required",  # force the model to generate a tool call for demo purposes
    )

4. Execute Tool Calls

tool_call = (
    response.choices[0].message.tool_calls[0]
    if response.choices[0].message.tool_calls
    else None
)

result = aipolabs.functions.execute(
    tool_call.function.name,
    json.loads(tool_call.function.arguments),
    linked_account_owner_id=LINKED_ACCOUNT_OWNER_ID,
)
print(f"{create_headline('Function Call Result')} \n {result}")