Skip to content

Introduction to DistillerClient

First Tutorial  Agent Library  Project Creation

The DistillerClient module is a core component of the AI Refinery SDK, specifically engineered to connect to AIRefinery service and optimize the execution of the client-side functionalities within AI-driven environments.

Objective

Use the SDK to create and run an AI system with the DistillerClient of AI Refinery SDK. As an example, this system will serve as a weather assistant, providing users with assistance on weather-related queries."

Steps

1. Configuration file

As a first step, you simply need to create a yaml file with all the required configuration. You can customize your assistant agent in this simple YAML configuration file.

utility_agents:
  - agent_class: SearchAgent
    agent_name: "Weather Agent"
    agent_description: 
      This agent finds the latest updates of the weather in any state in the USA.
      Do not ask this agent any question that is not related to this scope.
    config:
      output_style: "conversational"
      contexts:
        - "chat_history"

orchestrator:
  agent_list:
    - agent_name: "Weather Agent"

2. Python file

1. Project creation

Now, you can start the development of your assistant. The first step is to create the project. Project names should be unique under the same ACCOUNT.

from dotenv import load_dotenv
from air import  DistillerClient
import os

load_dotenv() # loads your API_KEY from your local '.env' file
api_key=str(os.getenv("API_KEY"))

distiller_client = DistillerClient(api_key=api_key)

project = "weather_project"

distiller_client.create_project(
    config_path="config.yaml",
    project=project
)
Once a project is created, the configuration file will be saved in the AIRefinery cloud and will be accessible to any user under the same ACCOUNT. Each project is assigned a project version number that can be used later to access that version of the account. The version number is shown once the project creation operation is successful:
Project <project_name> - version <i> has been created for <accoun_number>.

2. Connecting to a project

After the project is successfully created, you will be able to connect using the project name and a unique user id (uuid) of your choice, using the interacitve() session:

import asyncio
import os

from air import DistillerClient
from dotenv import load_dotenv

load_dotenv()  # loads your API_KEY from your local '.env' file
api_key = str(os.getenv("API_KEY"))


async def distiller_client_demo():

    distiller_client = DistillerClient(api_key=api_key)

    async with distiller_client(
        project="weather_project",  # your project name
        uuid="test_user",  # your user name
    ) as dc:
        responses = await dc.query(
            "How is the weather today at Mountain View, California?"
        )  # send the query to be processed
        async for response in responses:
            print(f"Response: {response['content']}")  # print out the response


if __name__ == "__main__":
    asyncio.run(distiller_client_demo())
By default, the distiller_client will connect to the latest version of the project.

If a prior version is desired, you can specify the project version as follows:

import asyncio
import os

from air import DistillerClient
from dotenv import load_dotenv

load_dotenv()  # loads your API_KEY from your local '.env' file
api_key = str(os.getenv("API_KEY"))


async def distiller_client_demo():

    distiller_client = DistillerClient(api_key=api_key)

    async with distiller_client(
        project="weather_project",  # your project name
        uuid="test_user",  # your user name
        project_version="1" # specific project version
    ) as dc:
        responses = await dc.query(
            "How is the weather today at Mountain View, California?"
        )  # send the query to be processed
        async for response in responses:
            print(f"Response: {response['content']}")  # print out the response


if __name__ == "__main__":
    asyncio.run(distiller_client_demo())

We recommend that once a project is created and the configuration yaml file does not need to be updated, there is no need to keep using distiller_client.create_project() everytime a new user is connecting to the project.