blablado calls functions for you#

The blablado library is a simple way to use large language models to call python functions. It is a conenvience wrapper around the OpenAI API and langchain.

You can install it using pip:

pip install blablado
from blablado import Assistant
assistant = Assistant()

Calling simple functions#

The assistant supports calling functions with multiple parameters and common types. Just register the function you would like it to be aware of and then run a prompt with a task that could be solved using the mentioned funciton.

def compute_sum(a:int, b:int):
    """Sums two numbers"""
    print(f"summing {a} and {b}...")
    return a + b

assistant.register_tool(compute_sum)
assistant.do("add 5 plus 4")
summing 5 and 4...
The sum of 5 plus 4 is 9.

Chaining operations#

You can also specify multiple functions/tools and ask to execute them in order.

def multiply_numbers(a:int, b:int):
    """Multiply two numbers"""
    print(f"Multiplying {a} and {b}...")
    return a * b

assistant.register_tool(multiply_numbers)
assistant.do("Add 2 and 4. Afterwards, take the result and multiply it by three. What's the result?")
summing 2 and 4...
Multiplying 6 and 3...
The result of adding 2 and 4, and then multiplying the result by 3 is 18.

Calling functions with common Python data types#

The assistant can also call functions with more complex and yet python standard types such as datetime.

from datetime import datetime

@assistant.register_tool
def book_room(room:str, author:str, start:datetime, end:datetime):
    """Book a room for a specific person from start to end time."""
    
    result = f"""
    Booking {room} for {author} from {start} to {end} was successful.
    """
    
    print(result)
    
    return result
assistant.do("Hi I'm Robert, please book room A03.21 for me from 3 to 4 pm tomorrow. Thanks")
    Booking A03.21 for Robert from 2024-06-02 15:00:00 to 2024-06-02 16:00:00 was successful.
    
I have successfully booked room A03.21 for you, Robert, from 3 to 4 pm tomorrow.

Calling unrelated stuff#

The following examples serve demonstrating that functions are not called in case the assistant doesn’t know what to do.

assistant.do("Setup a coffee for me in the kitchen")
I'm sorry, but I am not capable of setting up a coffee for you in the kitchen.
assistant.do("Why is Europe not in America?")
Europe is not in America because they are separate continents located on different tectonic plates.
assistant.do('which room was booked for robert?')
Room A03.21 was booked for Robert.

Exercise#

Create a new assistant object and add functions for opening and showing images. Program another function that can add two images. Hint: Copy-paste code from the notebook 30_langchain_bia.ipynb.