Skip to content

Distiller API Reference

The DistillerClient module is a core component of the AI Refineryโ„ข SDK, specifically engineered to orchestrate and manage complex workflows within AI-driven environments.

Class Overview

DistillerClient

The DistillerClient class is designed to manage and execute complex workflows within AI-driven environments.

class DistillerClient:
    """Manages and executes distillation projects within the AI Refinery framework."""

Methods

__init__

Initializes the DistillerClient instance with optional account and API key parameters.

def __init__(self, account: Optional[str] = None, api_key: Optional[str] = None):
    ...
  • account (Optional[str]): Account identifier.
  • api_key (Optional[str]): API key for authentication.

create_project

Registers a new distillation project with a configuration file.

def create_project(self, config_path: str, project: str) -> bool:
    ...
Parameters:
  • config_path (str): Configuration file path.
  • project (str): Project name.
Returns:
  • bool: True if project creation is successful.

download_project

Downloads the configuration from the server for a given project.

def download_project(self, project: str) -> dict:
    ...
Parameters:
  • project (str): Name of the project to download the configuration for.
Returns:
  • dict: The downloaded configuration as a JSON object.

run

Runs a distillation session for a specified project.

def run(self, query: str, project: str, custom_agent_gallery: dict[str, Callable] = {}, uuid: str = "test", verbose: bool = False, db_client: Optional[DatabaseClient] = None, reset: bool = False, return_user_message: bool = False):
    ...
Parameters:
  • query (str): User query to be sent to the Distiller framework.
  • project (str): Project name.
  • custom_agent_gallery (dict[str, Callable], optional): Custom agent functions.
  • uuid (str, optional): Unique user ID for each project. Defaults to "test".
  • verbose (bool, optional): Whether to print the conversations. Defaults to False.
  • db_client (Optional[DatabaseClient], optional): Database client for logging conversations.
  • reset (bool, optional): Reset the session state. Defaults to False.
  • return_user_message (bool, optional): Whether to return user message. Defaults to False.
Returns:
  • Generator: Yields JSON responses from the Distiller framework.

retrieve_history

Retrieves the conversation history from the database.

def retrieve_history(self, db_client: DatabaseClient, project: str, uuid: str, n_messages: int, as_string: bool = False) -> str | list[dict]:
    ...
Parameters:
  • db_client (DatabaseClient): Database client for querying the database.
  • project (str): Project name.
  • uuid (str): Unique user ID.
  • n_messages (int): Number of past messages to retrieve.
  • as_string (bool, optional): Whether to return the history as a string. Defaults to False.
Returns:
  • str | list[dict]: The retrieved conversation history.

reset

Resets the server-side session for a project.

def reset(self, project: str, uuid: str = "test") -> bool:
    ...
Parameters:
  • project (str): Project name.
  • uuid (str, optional): Unique user ID for each project. Defaults to "test".
Returns:
  • bool: True if the reset is successful.

interactive

Runs the distiller client in interactive mode for a specified project.

def interactive(self, project: str, custom_agent_gallery: dict[str, Callable] = {}, uuid: str = "test", reset: bool = False):
    ...
Parameters:
  • project (str): Project name.
  • custom_agent_gallery (dict[str, Callable], optional): Custom agent functions. Defaults to an empty dictionary.
  • uuid (str, optional): Unique user ID for each project. Defaults to "test".
  • reset (bool, optional): Whether to reset the existing connection between the user and the server. Defaults to False.

Example Usage

from air import DistillerClient, ChatClient, login

def simple_agent(query: str):
    prompt = """Generate synthetic data useful for answering this question (do not mention synthetic data):\n\n{query}"""
    chat = ChatClient(model="meta/llama3-70b-instruct")
    return chat.get_completion(prompt.format(query=query))

if __name__ == "__main__":
    login(account="demo_test", api_key="encoded_api_key", base_url="http://0.0.0.0:8080")

    distiller = DistillerClient()
    distiller.create_project(config_path="example.yaml", project="example")
    custom_agents = {"Data Scientist Agent": simple_agent}
    distiller.run(project="example", custom_agent_gallery=custom_agents, reset=True)