Async AI Workflows with Graph Theory

barqawiz

Alex

Posted on February 13, 2024

Async AI Workflows with Graph Theory

Intelli is a Python module that simplifies the orchestration of AI models by employing asynchronous programming and principles from graph theory. Designed for developers and AI engineers seeking to optimize their workflows and connecting different LLM, image or speech models to create complex tasks.

Quick Start with Intelli
To get started with Intelli, make sure you have Python 3.7 or newer. You can install Intelli using pip:

pip install intelli
Enter fullscreen mode Exit fullscreen mode

Applying Graph Theory in Intelli Workflows

intelli work flow
When I am talk about using graph theory with Intelli, it is referring to the way tasks mapped to their dependencies. In this model, each AI task is a node in a graph, and dependencies between tasks are edges.

This setup allows you to design workflows where the execution sequence reflects the interrelationships between tasks, facilitating both sequential and parallel processing. This approach is especially beneficial for managing tasks that need to wait multiple I/O operations, mapping between output of previous step to input of current tasks, ensuring that non-dependent tasks can proceed without delay, increasing overall efficiency. Furthermore, intelli promotes a modular approach to task design, enabling the easy reuse of components.

Creating AI Workflows with Intelli

Let’s say you're developing a content creation platform and need to automate tasks using AI models. With Intelli, you define agents for each task. The agent is based on text, image, vision or speech model.

Here's a simplified view of setting up your components:

Defining Agents

from intelli.flow.agents import Agent

# Define an agent for text generation
text_agent = Agent(
    agent_type="text",
    provider="openai",
    mission="write social media posts",
    model_params={"key": self.openai_api_key, "model": "gpt-3.5-turbo"}
)

# Define an agent for image processing
image_agent = Agent(
    agent_type="image",
    provider="stability",
    mission="generate description only",
    model_params={"key": self.stability_key}
)
Enter fullscreen mode Exit fullscreen mode

Defining Tasks

You can define tasks and assign agents to them:

from intelli.flow.tasks import Task
# there are other input types, like image, vision, speech
from intelli.flow.input import TextTaskInput

task1 = Task(
    TextTaskInput("Create a post about AI technologies"),
    text_agent,
    log=True
)

task2 = Task(
    TextTaskInput("Generate image description for AI technologies post"),
    image_agent,
    log=True
)
Enter fullscreen mode Exit fullscreen mode

Defining Flows

After defining tasks, you can orchestrate them using Intelli’s flow management. The system handles task dependencies to ensure they execute efficiently and in the proper order. The task2 will use the output of task1 when generating the images.

from intelli.flow.flow import Flow
import asyncio

async def main():
    flow = Flow(
        tasks={
            "task1": task1,
            "task2": task2
        },
        map_paths={
            "task1": ["task2"]
        },
        log=True
    )

    output = await flow.start()
    print("Final output:", output)

if __name__ == "__main__":
    asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

you can build more complex flow by utilizing the flexible map feature, example:

map_paths={"task1": ["task2", "task3"], "task3": ["task4"]},
Enter fullscreen mode Exit fullscreen mode

Check full practical code example in the wiki page.

Conclusion

This quick guide introduces the basic steps to automate AI workflows with intelli. While this still in beta phase, the potential of automation with the graph design is huge.

Rerefences

💖 💪 🙅 🚩
barqawiz
Alex

Posted on February 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related