Skip to content

Catalog

Defines a base class for catalogs used for loading and managing various components in GLLM Inference.

Authors

Henry Wicaksono (henry.wicaksono@gdplabs.id)

References

NONE

BaseCatalog

Bases: ABC, BaseModel, Generic[T]

A base class for catalogs used for loading and managing various components in GLLM Inference.

Attributes:

Name Type Description
components dict[str, T]

A dictionary containing the components.

Load from Google Sheets using client email and private key example:

catalog = BaseCatalog.from_gsheets(
    sheet_id="...",
    worksheet_id="...",
    client_email="...",
    private_key="...",
)

component = catalog.name

Load from Google Sheets using credential file example:

catalog = BaseCatalog.from_gsheets(
    sheet_id="...",
    worksheet_id="...",
    credential_file_path="...",
)

component = catalog.name

Load from CSV example:

catalog = BaseCatalog.from_csv(csv_path="...")

component = catalog.name

Load from records example:

catalog = BaseCatalog.from_records(
    records=[
        {"name": "...", "col_1": "...", "col_2": "..."},
        {"name": "...", "col_1": "...", "col_2": "..."},
    ],
)

component = catalog.name

__getattr__(name)

Fetches a component by attribute name.

This method attempts to retrieve a component from the components dictionary using the provided attribute name. If the attribute is not found, it raises an AttributeError.

Parameters:

Name Type Description Default
name str

The name of the attribute to fetch.

required

Returns:

Name Type Description
T T

The component associated with the given attribute name.

Raises:

Type Description
AttributeError

If the attribute name does not exist in the components dictionary.

from_csv(csv_path) classmethod

Creates a BaseCatalog[T] instance from CSV data.

This class method reads component data from a CSV file and initializes components based on the provided data.

Parameters:

Name Type Description Default
csv_path str

The file path to the CSV containing component data.

required

Returns:

Type Description
BaseCatalog[T]

BaseCatalog[T]: An instance of BaseCatalog[T] initialized with components based on the CSV data.

from_gsheets(sheet_id, worksheet_id='0', credential_file_path=None, client_email=None, private_key=None) classmethod

Creates a BaseCatalog[T] instance from Google Sheets data.

This class method reads component data from a Google Sheets worksheet and initializes components based on the provided data. Authentication can be provided either by specifying the path to a credential.json file or by directly supplying the client_email and private_key.

Parameters:

Name Type Description Default
sheet_id str

The ID of the Google Sheet.

required
worksheet_id str

The ID of the worksheet within the Google Sheet. Defaults to "0"

'0'
credential_file_path str

The file path to the credential.json file. If provided, client_email and private_key are extracted from this file, effectively ignoring the client_email and private_key arguments. Defaults to None.

None
client_email str

The client email associated with the service account. This is ignored if credential_file_path is provided. Defaults to None.

None
private_key str

The private key used for authentication. This is ignored if credential_file_path is provided. Defaults to None.

None

Returns:

Type Description
BaseCatalog[T]

BaseCatalog[T]: An instance of BaseCatalog[T] initialized with components based on the Google Sheets data.

Raises:

Type Description
ValueError

If authentication credentials are not provided or are invalid.

from_records(records) classmethod

Creates a BaseCatalog[T] instance from a list of records.

This class method builds a catalog from the provided records.

Parameters:

Name Type Description Default
records list[dict[str, str]]

A list of records containing component data.

required

Returns:

Type Description
BaseCatalog[T]

BaseCatalog[T]: An instance of BaseCatalog[T] initialized with components based on the list of records.