Zum Inhalt

TemplateVariablesCollectionsResource

TemplateVariablesCollectionsResource

TemplateVariablesCollectionsResource(client: Union[Client, AsyncClient])

Bases: BaseResource

aupdate async

aupdate(collection_id: int, name: str, description: str | None = None, read_only: bool | None = None, columns: List[str | CollectionColumn] | None = None) -> TemplateVariablesCollection

Update an existing collection (async).

create

create(name: str, description: str = '', variables: List[Dict[str, Any]] | None = None, columns: List[str | CollectionColumn] | None = None, read_only: bool = False) -> TemplateVariablesCollectionWithEntries

Creates a new collection.

Parameters:

Name Type Description Default
name str

The name for the new collection.

required
description str

Optional description for the collection.

''
variables list[dict[str, Any]]

Optional list of variables to add to the collection. Values can be strings for TEXT columns, dicts for CONVERSATION columns, or other types.

None
columns list[str | CollectionColumn]

Optional list of column definitions. Can be column names as strings (defaults to TEXT type) or CollectionColumn objects.

None
read_only bool

Whether the collection should be read-only.

False

Returns:

Type Description
TemplateVariablesCollection

The newly created collection object.

Raises:

Type Description
HTTPStatusError

If collection with same name already exists (400 BAD REQUEST)

delete

delete(template_variables_collection: TemplateVariablesCollection) -> None

Delete a collection.

get

get(*, name: str | None = None, id: int | None = None) -> TemplateVariablesCollectionWithEntries

Get a collection by name or id.

Parameters:

Name Type Description Default
name str | None

The name of the collection to get.

None
id int | None

The id of the collection to get.

None

Returns:

Name Type Description
TemplateVariablesCollectionWithEntries TemplateVariablesCollectionWithEntries

The collection object.

Raises:

Type Description
ValueError

If neither or both name and id are provided, or if not found.

get_or_create

get_or_create(name: str, description: str = '', variables: List[Dict[str, Any]] | None = None, columns: List[str | CollectionColumn] | None = None, read_only: bool = False) -> tuple[TemplateVariablesCollectionWithEntries, bool]

Gets an existing collection by name or creates a new one if it doesn't exist.

If a collection with the given name exists: - If columns parameter is provided, validates that the existing collection has matching column types - Returns the existing collection if compatible, otherwise raises ValueError - Other parameters (description, variables, read_only) are ignored with warnings

Parameters:

Name Type Description Default
name str

The name of the collection to get or create.

required
description str

Optional description for the collection if created.

''
variables List[Dict[str, Any]] | None

Optional list of variables to add to the collection if created. Values can be strings for TEXT columns, dicts for CONVERSATION columns, or other types.

None
columns List[str | CollectionColumn] | None

Optional list of column definitions for the collection if created. Can be column names as strings (defaults to TEXT type) or CollectionColumn objects. If provided and collection exists, column types must match existing collection.

None
read_only bool

Whether the collection should be read-only if created.

False

Returns:

Type Description
tuple[TemplateVariablesCollectionWithEntries, bool]

tuple[TemplateVariablesCollectionWithEntries, bool]: A tuple containing: - Collection: The retrieved or created collection object - bool: True if a new collection was created, False if existing was found

Raises:

Type Description
ValueError

If collection exists but has incompatible column types

list

list(filters: TemplateVariablesCollectionFilter | None = None, compatible_prompt_template: PromptTemplate | None = None, sort_options: TemplateVariablesCollectionSort | None = None) -> list[TemplateVariablesCollection]

Get a list of template variables collections.

Parameters:

Name Type Description Default
filters TemplateVariablesCollectionFilter | None

Filter for template variables collections.

None
compatible_prompt_template PromptTemplate | None

Filter collections compatible with a specific prompt template.

None
sort_options TemplateVariablesCollectionSort | None

Sort for template variables collections.

None

Returns:

Type Description
list[TemplateVariablesCollection]

list[TemplateVariablesCollection]: A list of template variables collections.

update

update(collection_id: int, name: str, description: str | None = None, read_only: bool | None = None, columns: List[str | CollectionColumn] | None = None) -> TemplateVariablesCollection

Update an existing collection.

Parameters:

Name Type Description Default
collection_id int

The ID of the collection to update.

required
name str

The new name for the collection.

required
description str | None

Optional new description for the collection.

None
read_only bool | None

Optional new read-only status for the collection.

None
columns List[str | CollectionColumn] | None

Optional list of columns in the desired order. Can be column names as strings (defaults to TEXT type) or CollectionColumn objects. Missing columns are deleted, new columns are created, existing columns are reordered.

None

Returns:

Name Type Description
TemplateVariablesCollection TemplateVariablesCollection

The updated collection object.

Raises:

Type Description
HTTPStatusError

If collection doesn't exist or validation fails.