Catalog
Defines a base class for catalogs used for loading and managing various components in GLLM Inference.
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. |
Initialization
Example 1: Load from Google Sheets using client email and private key
catalog = BaseCatalog.from_gsheets(
sheet_id="...",
worksheet_id="...",
client_email="...",
private_key="...",
)
component = catalog.name
Example 2: Load from Google Sheets using credential file
catalog = BaseCatalog.from_gsheets(
sheet_id="...",
worksheet_id="...",
credential_file_path="...",
)
component = catalog.name
Example 3: Load from CSV
catalog = BaseCatalog.from_csv(csv_path="...")
component = catalog.name
Example 4: Load from records
```python records = [ {"name": "...", "col_1": "...", "col_2": "..."}, {"name": "...", "col_1": "...", "col_2": "..."}, ] catalog = BaseCatalog.from_records(records=records) 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 |
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 |
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 |
None
|
client_email |
str
|
The client email associated with the service account. This is ignored if
|
None
|
private_key |
str
|
The private key used for authentication. This is ignored if |
None
|
Returns:
| Type | Description |
|---|---|
BaseCatalog[T]
|
BaseCatalog[T]: An instance of |
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 |