Enterprise Asset Library¶
The DSSEnterpriseAssetLibrary class lets you list Enterprise Asset Library collections and prompts, and export or import collections as an archive.
To get started, retrieve the Enterprise Asset Library handle from a DSSClient:
eal = client.get_enterprise_asset_library()
Basic operations¶
List the collections you can read¶
Use list_collections() to list the collections available to the current user or API key.
eal = client.get_enterprise_asset_library()
collections = eal.list_collections()
for collection in collections:
print("Collection id: %s" % collection["id"])
print("Collection name: %s" % collection["name"])
List prompts from all readable collections¶
Use list_prompts() to inspect the prompts available in the Enterprise Asset Library.
eal = client.get_enterprise_asset_library()
for prompt in eal.list_prompts():
print("Prompt id: %s" % prompt["id"])
print("Prompt name: %s" % prompt["name"])
If you only want prompts from specific collections, pass their identifiers with restrict_collections.
prompt_list = eal.list_prompts(restrict_collections=["9tp4AsRe", "iV3Y8Xn6"])
Export collections to a file¶
Use export_collections_to_file() to export enterprise asset library collections to a file. When you provide a path, the user must have access to that path on the machine hosting the DSS instance.
The exported archive contains all the collections that the current caller is allowed to export.
export_path = "/tmp/eal-export.zip"
eal = client.get_enterprise_asset_library()
eal.export_collections_to_file(export_path)
Stream an export archive¶
If you want more control over how the archive is saved, use get_export_stream().
The returned stream must be closed by the caller.
eal = client.get_enterprise_asset_library()
with eal.get_export_stream() as stream:
with open("/tmp/eal-export.zip", "wb") as output:
for chunk in stream.stream(1024):
output.write(chunk)
Import collections from an archive¶
Use import_collections() to import collections from an Enterprise Asset Library export archive.
Use conflict_resolution_strategy to control what happens when an imported collection conflicts with an existing one. Refer to the API documentation import_collections() for possible values.
This method returns a DSSFuture, which you can use to monitor the import.
eal = client.get_enterprise_asset_library()
with open("/tmp/eal-export.zip", "rb") as archive:
future = eal.import_collections(
archive,
conflict_resolution_strategy="SKIP"
)
future.wait_for_result()
Get a handle on a collection¶
Use get_collection() when you want to work with a specific collection after listing or importing it, for example to retrieve one of its prompts or create a new prompt in that collection.
eal = client.get_enterprise_asset_library()
collection = eal.get_collection("Tt6gDPJ9")
Once you have a collection handle, you can retrieve an existing prompt from that collection with get_prompt().
prompt = collection.get_prompt("xmsCa8clrp6f0kNt")
print("Prompt name: %s" % prompt.name)
You can also add a new prompt to the collection with create_prompt().
new_prompt = collection.create_prompt(
name="Summarize ticket",
description="Summarize a support ticket before escalation",
content="Summarize the following support ticket: {{ticket}}",
tags=["support", "summary"]
)
print("Created prompt id: %s" % new_prompt.id)
Reference documentation¶
Classes¶
|
A handle to interact with an Enterprise Asset Collection on the DSS instance. |
|
Handle to interact with the Enterprise Asset Library on the DSS instance. |
|
A future represents a long-running task on a DSS instance. |
Functions¶
Export the Enterprise Asset Library collections to a file. |
|
|
Get a handle to interact with a specific Enterprise Asset Collection |
Gets a handle to work with the Enterprise Asset Library |
|
Export the Enterprise Asset Library collections that the caller can export. |
|
|
Import Enterprise Asset Library collections from an archive. |
Lists the collections you have read access to in the Enterprise Asset Library as dict. |
|
|
Lists the prompts in the collections you have read access to |
