Skip to content

Latest commit

 

History

History
190 lines (129 loc) · 5.99 KB

artifacts.rst

File metadata and controls

190 lines (129 loc) · 5.99 KB

Artifacts

Artifacts are used to record milestones, state, objects, and change created by a chain. Artifacts provide a reference point to interact with these results in subsequent chains. Artifacts may be saved explicitly with SaveArtifact and then referenced with ArtifactMemory.

Artifact Memory

ArtifactMemory loads an artifact from the database and loads it into the prompt as an input.

ARTIFACT_MEMORY = {
    "class_path": "ix.memory.artifacts.ArtifactMemory",
    "config": {
        "load_artifact": True
        "input_key": "artifact_keys",
        "memory_key": "related_artifacts",
    }
}

ArtifactMemory will read from input_key and load the artifact into memory_key, if load_artifact is set to True. Prompts can then output the formatted artifact using memory_key.

The prompt should include memory_key to render the output.

PROMPT = """
{related_artifacts}

Tell me about the artifact [{artifact_keys}]
"""

Prompt will be rendered with the artifact information.

RELATED ARTIFACTS

id: 00000000-0000-0000-0000-000000000000
key: my_key
type: my_type
name: my_name
description: my_description
data:
data stored in artifact

Tell me about the artifacts [{my_key}]

Artifact memory matches based on artifact_key. If there are multiple objects with the same key, then the most recent object is used.

Artifact Memory Scope

Artifact memory scope is limited to the current chat.

Artifact Chains

Chains that integrate with the artifact system.

SaveArtifact

SaveArtifact saves an artifact to the database. The artifact properties may be generated by an LLM, chain, or generated statically.

Artifact Import:

  • artifact_from_key: The key to load the artifact from. Any properties defined in the artifact will be saved on the artifact. Static values will override these values.

Static Attributes: Static attributes may be defined to override attributes loaded from an artifact. If not loading from an artifact, then all attributes are required.

  • artifact_key: The key to save the artifact under. This key may be used to reference the artifact in subsequent requests.
  • artifact_type: The type of artifact to save. This is used to determine how the artifact is stored and displayed.
  • artifact_name: The name of the artifact to save.
  • artifact_description: The description of the artifact to save.

Storage: Artifacts may also be optionally saved to a storage backend. Define artifact_storage to define the storage function.

  • artifact_storage: The storage to use for the artifact. This is used to determine how the artifact is stored and how it may be queried.
  • artifact_storage_id: The storage id to use for the artifact. This may be a database id, file path, or other identifier depending on the storage type.

Input / Output:

  • content_key: The key to load the content from. This is automatically set as an input_variable
  • content_path: jsonpath relative to inputs for content to save. This is used to extract a subset of the content to save. If not set, the entire content at content_key.
  • output_key: The key to save the artifact under. This key may be used to reference the artifact in subsequent requests.

Artifact format:

Artifact when represented as a dictionary have the following format. Fields values may be generated by the chain or set statically by the config.

{
    "key": "my_key",
    "type": "my_type",
    "name": "my_name",
    "description": "my_description",
    "storage": "my_storage",           # Optional
    "storage_id": "my_storage_id",     # Required with storage
    "data": "my_data",                 # Optional
}

Saving an existing artifact:

Artifact dicts may be generated by a chain and then passed to SaveArtifact.

# This example assumes that name, key, description are loaded from ``file_artifact``
# remaining attributes are set statically.
SAVE_ARTIFACT = {
    "class_path": "ix.chains.artifacts.SaveArtifact",
    "config" : {
        "artifact_from_key": "file_artifact",     # Artifact input
        "artifact_type": "file",                  # static type
        "artifact_storage": "write_to_file",      # static storage
        "content_key": "generated_file_json",     # content input
        "output_key": "generated_file_artifact",  # artifact output
    }
}

# create node
root = ChainNode.objects.create(**PARSE_JSON_CONFIG)

Statically defining artifact properties:

Artifact dicts may be generated by a chain and then passed to SaveArtifact.

# everything but content and identifier is statically defined
SAVE_STATIC_ARTIFACT = {
    "class_path": "ix.chains.artifacts.SaveArtifact",
    "config": {
        "artifact_key": "file_list",
        "artifact_name": "file_list",
        "artifact_description": "list of files that will be generated",
        "artifact_type": "artifact_list",
        "content_key": "file_artifacts_json",
        "output_key": "file_artifacts_list",
    },
}

# create node
root = ChainNode.objects.create(**PARSE_JSON_CONFIG)

Extracting content with a jsonpath:

Set content_path to extract a subset of the content to save. If not set, the entire content at content_key will be saved.

SAVE_ARTIFACT = {
    "class_path": "ix.chains.artifacts.SaveArtifact",
    "config" : {
        "content_key": "generated_file_json",
        "content_path": "generated_file_json.data",
    }
}

# create node
root = ChainNode.objects.create(**PARSE_JSON_CONFIG)