Skip to content

Rapidata leaderboard manager

RapidataLeaderboardManager #

RapidataLeaderboardManager(openapi_service: OpenAPIService)

A manager for leaderboards.

Used to create and retrieve leaderboards.

Parameters:

Name Type Description Default
openapi_service OpenAPIService

The OpenAPIService instance for API interaction.

required
Source code in src/rapidata/rapidata_client/leaderboard/rapidata_leaderboard_manager.py
def __init__(self, openapi_service: OpenAPIService):
    self.__openapi_service = openapi_service

create_new_leaderboard #

create_new_leaderboard(
    name: str,
    instruction: str,
    prompts: list[str],
    show_prompt: bool = False,
) -> RapidataLeaderboard

Creates a new leaderboard with the given name, instruction, and prompts.

Parameters:

Name Type Description Default
leaderboard_name

The name of the leaderboard. Will be used to identify the leaderboard on the overview.

required
instruction str

The instruction for the leaderboard. Will determine how the models will be evaluated.

required
prompts list[str]

The prompts for the leaderboard. Will be registered for the leaderboard and able to be retrieved again later.

required
show_prompt bool

Whether to show the prompt to the users when they are evaluating the models.

False
Source code in src/rapidata/rapidata_client/leaderboard/rapidata_leaderboard_manager.py
def create_new_leaderboard(self, name: str, instruction: str, prompts: list[str], show_prompt: bool = False) -> RapidataLeaderboard:
    """
    Creates a new leaderboard with the given name, instruction, and prompts.

    Args:
        leaderboard_name: The name of the leaderboard. Will be used to identify the leaderboard on the overview.
        instruction: The instruction for the leaderboard. Will determine how the models will be evaluated.
        prompts: The prompts for the leaderboard. Will be registered for the leaderboard and able to be retrieved again later.
        show_prompt: Whether to show the prompt to the users when they are evaluating the models.
    """
    leaderboard_id = self.__register_new_leaderboard(name, instruction, show_prompt)
    leaderboard = RapidataLeaderboard(name, instruction, show_prompt, leaderboard_id, self.__openapi_service)
    leaderboard._register_prompts(prompts)
    return leaderboard

get_leaderboard_by_id #

get_leaderboard_by_id(
    leaderboard_id: str,
) -> RapidataLeaderboard

Retrieves a leaderboard by its ID.

Parameters:

Name Type Description Default
leaderboard_id str

The ID of the leaderboard.

required
Source code in src/rapidata/rapidata_client/leaderboard/rapidata_leaderboard_manager.py
def get_leaderboard_by_id(self, leaderboard_id: str) -> RapidataLeaderboard:
    """
    Retrieves a leaderboard by its ID.

    Args:
        leaderboard_id: The ID of the leaderboard.
    """
    leaderboard_result = self.__openapi_service.leaderboard_api.leaderboard_leaderboard_id_get(
        leaderboard_id=leaderboard_id
    )
    return RapidataLeaderboard(leaderboard_result.name, leaderboard_result.instruction, leaderboard_result.show_prompt, leaderboard_id, self.__openapi_service)

find_leaderboards #

find_leaderboards(
    name: str = "", amount: int = 10
) -> list[RapidataLeaderboard]

Find your recent leaderboards given criteria. If nothing is provided, it will return the most recent leaderboard.

Parameters:

Name Type Description Default
name str

The name of the leaderboard - matching leaderboard will contain the name. Defaults to "" for any leaderboard.

''
amount int

The amount of leaderboards to return. Defaults to 10.

10
Source code in src/rapidata/rapidata_client/leaderboard/rapidata_leaderboard_manager.py
def find_leaderboards(self, name: str = "", amount: int = 10) -> list[RapidataLeaderboard]:
    """
    Find your recent leaderboards given criteria. If nothing is provided, it will return the most recent leaderboard.

    Args:
        name (str, optional): The name of the leaderboard - matching leaderboard will contain the name. Defaults to "" for any leaderboard.
        amount (int, optional): The amount of leaderboards to return. Defaults to 10.
    """
    leaderboard_result = self.__openapi_service.leaderboard_api.leaderboards_get(
        request=QueryModel(
            page=PageInfo(
                index=1,
                size=amount
            ),
            filter=RootFilter(filters=[Filter(field="Name", operator="Contains", value=name)]),
            sortCriteria=[SortCriterion(direction="Desc", propertyName="CreatedAt")]
        )
    )
    leaderboards = []
    for leaderboard in leaderboard_result.items:
        leaderboards.append(RapidataLeaderboard(leaderboard.name, leaderboard.instruction, leaderboard.show_prompt, leaderboard.id, self.__openapi_service))
    return leaderboards