Skip to content

Models API Reference

This page documents the data models used in PromptSite.

promptsite.model.prompt.Prompt dataclass

A class representing a prompt with version control capabilities.

Attributes:

Name Type Description
id str

Unique identifier for the prompt

description str

Description of the prompt

tags List[str]

List of tags associated with the prompt

versions Optional[Dict[str, Version]]

Dictionary of versions for the prompt

variables Optional[Dict[str, Variable]]

Dictionary of variables for the prompt

add_version(content, variables=None)

Add a new version of the prompt.

Parameters:

Name Type Description Default
content str

The content of the new version

required
variables Optional[Dict[str, Variable]]

Dictionary of variables for the new version

None

Returns:

Name Type Description
Version Version

The newly created version object

from_dict(data) classmethod

Create a Prompt instance from a dictionary.

Parameters:

Name Type Description Default
data Dict[str, Any]

Dictionary containing the prompt's data.

required

Returns:

Name Type Description
Prompt Prompt

A new Prompt instance.

get_latest_version()

Get the latest version of the prompt.

Returns:

Type Description
Optional[Version]

Optional[Version]: The latest version, or None if no versions exist

to_dict(columns=None)

Convert the prompt to a dictionary representation.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing the prompt's data

promptsite.model.version.Version dataclass

A class representing a version of a prompt with its associated runs.

Attributes:

Name Type Description
content str

The content of the version

created_at datetime

The date and time when the version was created

version_id str

The unique identifier for the version

variables Optional[Dict[str, Variable]]

The variables of the version, if any, it overrides the prompt variables

__post_init__()

Initialize the version_id if not provided.

_generate_version_id(content)

Generate a version ID based on the hash of the content.

Parameters:

Name Type Description Default
content str

The content of the version

required

Returns:

Name Type Description
str str

The generated version ID

add_run(final_prompt, variables, llm_output=None, execution_time=None, llm_config=None)

Create and add a new run to this version.

Parameters:

Name Type Description Default
llm_output Optional[str]

The output text from the LLM

None
execution_time Optional[float]

Time taken to execute in seconds

None
llm_config Optional[Dict[str, Any]]

Configuration used for the LLM

None

Returns:

Name Type Description
Run Run

The newly created run

build_final_prompt(values, no_instructions=False, custom_instructions='')

Build the final prompt with the variables of the version.

Parameters:

Name Type Description Default
values Dict[str, Any]

The values of the variables

required
no_instructions Optional[bool]

Whether to use the custom instructions

False
custom_instructions Optional[str]

The custom instructions

''

Returns:

Name Type Description
str str

The final prompt

compare_variables(variables)

Compare the variables of the version with the variables of the new version.

Parameters:

Name Type Description Default
variables Dict[str, Variable]

The variables of the new version

required

Returns:

Name Type Description
bool bool

True if the variables are the same, False otherwise

from_dict(data) classmethod

Create Version from dictionary.

Parameters:

Name Type Description Default
data Dict

Dictionary containing the version's data

required

Returns:

Name Type Description
Version Version

The newly created Version

to_dict(columns=None)

Convert Version to a dictionary with serializable values.

Returns:

Name Type Description
Dict Dict

Dictionary containing the version's data

promptsite.model.run.Run dataclass

A Run represents a single execution of a prompt version, storing the output, execution time, and configuration used.

Attributes:

Name Type Description
run_id str

Unique identifier for this run

created_at str

ISO format timestamp when run was created

run_at str

ISO format timestamp when run was executed

final_prompt str

The final prompt that was executed

variables Dict[str, Any]

The variables that were used in the run

llm_output Optional[str]

The output text from the LLM

execution_time Optional[float]

Time taken to execute in seconds

llm_config Optional[Dict[str, Any]]

Configuration used for the LLM

__post_init__()

Initialize the run_id if not provided.

_generate_run_id()

Generate a run ID based on the hash of the run_at timestamp.

from_dict(data) classmethod

Create a Run instance from a dictionary.

Parameters:

Name Type Description Default
data Dict[str, Any]

Dictionary containing the run's data.

required

Returns:

Name Type Description
Run Run

A new Run instance.

to_dict(columns=None)

Convert the run to a dictionary representation.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing the run's data.

promptsite.model.variable.Variable

Base class for all variable types.

Attributes:

Name Type Description
description str

Description of the variable

disable_validation bool

Whether to disable validation for the variable

from_dict(data) classmethod

Create a Variable instance from a dictionary representation.

Parameters:

Name Type Description Default
data Dict[str, Any]

Dictionary containing variable configuration

required

Returns:

Name Type Description
Variable Variable

A new instance of the appropriate Variable subclass

to_dict()

Convert the variable instance to a dictionary representation.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: A dictionary containing the variable type information

validate(value)

Validate if the given value matches the variable type.

Parameters:

Name Type Description Default
value str

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is valid for this variable type, False otherwise

Raises:

Type Description
NotImplementedError

This is an abstract method that must be implemented by subclasses

promptsite.model.variable.SingleVariable

Bases: Variable

Base class for simple variable types that don't require complex validation or transformation.

to_json(value)

Convert a value to its JSON string representation.

Parameters:

Name Type Description Default
value Any

The value to convert to JSON

required

Returns:

Name Type Description
str str

The JSON string representation of the value

promptsite.model.variable.ComplexVariable

Bases: Variable

Complex variable type that uses Pydantic models for validation and schema handling.

This class handles structured data that needs to conform to a specific schema defined by a Pydantic model.

Attributes:

Name Type Description
model BaseModel

The Pydantic model used for validation and schema generation

is_output bool

Whether the variable is an output variable

from_dict(data) classmethod

Create a ComplexVariable instance from a dictionary representation.

Parameters:

Name Type Description Default
data Dict[str, Any]

Dictionary containing variable configuration including model schema information

required

Returns:

Name Type Description
ComplexVariable ComplexVariable

A new instance of ComplexVariable with the reconstructed Pydantic model

get_prompt_insert(value, custom_instructions='')

Generate a formatted prompt string with schema and dataset information.

Parameters:

Name Type Description Default
value Any

The dataset value to include in the prompt

required
custom_instructions str

Custom instructions template to use. Defaults to schema_instructions.

''

Returns:

Name Type Description
str str

Formatted prompt string containing schema and dataset information

to_dict()

Convert the complex variable instance to a dictionary representation.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: A dictionary containing the variable type, model class name, and model schema information

to_json(value)

Convert a complex value to its JSON string representation.

Parameters:

Name Type Description Default
value Any

The value to convert to JSON

required

Returns:

Name Type Description
str str

The JSON string representation of the value

promptsite.model.variable.StringVariable

Bases: SingleVariable

Variable type for string values.

Validates that values are Python string instances.

validate(value)

Validate if the given value is a string.

Parameters:

Name Type Description Default
value str

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is a string instance, False otherwise

promptsite.model.variable.NumberVariable

Bases: SingleVariable

Variable type for numeric values.

Validates that values are Python integer instances.

validate(value)

Validate if the given value is an integer.

Parameters:

Name Type Description Default
value str

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is an integer instance, False otherwise

promptsite.model.variable.BooleanVariable

Bases: SingleVariable

Variable type for boolean values.

Validates that values are Python boolean instances.

validate(value)

Validate if the given value is a boolean.

Parameters:

Name Type Description Default
value str

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is a boolean instance, False otherwise

promptsite.model.variable.ArrayVariable

Bases: ComplexVariable

Variable type for array/list values that conform to a Pydantic model schema.

Validates that values are Python lists where each item conforms to the specified Pydantic model schema.

Attributes:

Name Type Description
schema_instructions str

Template for formatting schema and dataset information

validate(value)

Validate if the given value is a list conforming to the model schema.

Parameters:

Name Type Description Default
value Any

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is a list and all items conform to the model schema, False otherwise

promptsite.model.variable.ObjectVariable

Bases: ComplexVariable

Variable type for object/dict values that conform to a Pydantic model schema.

Validates that values are Python dictionaries that conform to the specified Pydantic model schema.

Attributes:

Name Type Description
schema_instructions str

Template for formatting schema and dataset information

validate(value)

Validate if the given value is a dict conforming to the model schema.

Parameters:

Name Type Description Default
value Any

The value to validate

required

Returns:

Name Type Description
bool bool

True if value is a dict and conforms to the model schema, False otherwise