Skip to content

The Base DataModels

We provide different backend-dependent DataModels to use.

These data models provide I/O for chatbots, agents, rags etc.

The user can build new data models by inheriting from these base models.

The check functions works for every type of data models (by checking the schema) e.g. SymbolicDataModel, JsonDataModel, DataModel or Variable.

ChatMessage

Bases: DataModel

A chat message

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatMessage",
        "synalinks.ChatMessage",
    ]
)
class ChatMessage(DataModel):
    """A chat message"""

    role: ChatRole = Field(
        description="The chat message role",
    )
    content: Union[str, Dict[str, Any]] = Field(
        description="The content of the message",
        default="",
    )
    tool_call_id: Optional[str] = Field(
        description="The id of the tool call if role is `tool`",
        default=None,
    )
    tool_calls: List[ToolCall] = Field(
        description="The tool calls of the agent",
        default=[],
    )

ChatMessages

Bases: DataModel

A list of chat messages

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatMessages",
        "synalinks.ChatMessages",
    ]
)
class ChatMessages(DataModel):
    """A list of chat messages"""

    messages: List[ChatMessage] = Field(
        description="The list of chat messages",
        default=[],
    )

ChatRole

Bases: str, Enum

The chat message roles

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.ChatRole",
        "synalinks.ChatRole",
    ]
)
class ChatRole(str, Enum):
    """The chat message roles"""

    SYSTEM = "system"
    USER = "user"
    ASSISTANT = "assistant"
    TOOL = "tool"

Embedding

Bases: DataModel

An embedding vector

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Embedding",
    ]
)
class Embedding(DataModel):
    """An embedding vector"""

    embedding: List[float] = Field(
        description="The embedding vector",
        default=[],
    )

Embeddings

Bases: DataModel

A list of embeddings

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Embeddings",
        "synalinks.Embeddings",
    ]
)
class Embeddings(DataModel):
    """A list of embeddings"""

    embeddings: List[List[float]] = Field(
        description="The list of embedding vectors",
        default=[],
    )

GenericIO

Bases: DataModel

A pair of generic inputs/outputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericIO",
        "synalinks.GenericIO",
    ]
)
class GenericIO(DataModel):
    """A pair of generic inputs/outputs"""

    inputs: Dict[str, Any] = Field(
        description="The inputs",
    )
    outputs: Dict[str, Any] = Field(
        description="The outputs",
    )

GenericInputs

Bases: DataModel

A generic inputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericInputs",
        "synalinks.GenericInputs",
    ]
)
class GenericInputs(DataModel):
    """A generic inputs"""

    inputs: Dict[str, Any] = Field(
        description="The inputs",
    )

GenericOutputs

Bases: DataModel

A generic outputs

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericOutputs",
        "synalinks.GenericOutputs",
    ]
)
class GenericOutputs(DataModel):
    """A generic outputs"""

    outputs: Dict[str, Any] = Field(
        description="The outputs",
    )

GenericResult

Bases: DataModel

A generic result

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.GenericResult",
        "synalinks.GenericResult",
    ]
)
class GenericResult(DataModel):
    """A generic result"""

    result: List[Any] = Field(
        description="The result",
    )

Instructions

Bases: Trainable

The instructions for the language model

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.Instructions",
        "synalinks.Instructions",
    ]
)
class Instructions(Trainable):
    """The instructions for the language model"""

    instructions: Optional[str] = Field(
        description="The instructions for the language model",
    )

is_chat_message(x)

Checks if the given data model is a chat message

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_chat_message",
        "synalinks.is_chat_message",
    ]
)
def is_chat_message(x):
    """Checks if the given data model is a chat message

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), ChatMessage.get_schema()):
        return True
    return False

is_chat_messages(x)

Checks if the given data model are chat messages

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_chat_messages",
        "synalinks.is_chat_messages",
    ]
)
def is_chat_messages(x):
    """Checks if the given data model are chat messages

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), ChatMessages.get_schema()):
        return True
    return False

is_embedded(x)

Checks if the given data model is an embedded entity

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embedded",
        "synalinks.is_embedded",
    ]
)
def is_embedded(x):
    """Checks if the given data model is an embedded entity

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("embedding", None):
            return True
    return False

is_embedding(x)

Checks if the given data model is an embedding

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embedding",
        "synalinks.is_embedding",
    ]
)
def is_embedding(x):
    """Checks if the given data model is an embedding

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Embedding.get_schema()):
        return True
    return False

is_embeddings(x)

Checks if the given data model are embeddings

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_embeddings",
        "synalinks.is_embeddings",
    ]
)
def is_embeddings(x):
    """Checks if the given data model are embeddings

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Embeddings.get_schema()):
        return True
    return False

is_instructions(x)

Checks if the given data model is an instructions data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_instructions",
        "synalinks.is_instructions",
    ]
)
def is_instructions(x):
    """Checks if the given data model is an instructions data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Instructions.get_schema()):
        return True
    return False

is_prediction(x)

Checks if the given data model is a prediction

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_prediction",
        "synalinks.is_prediction",
    ]
)
def is_prediction(x):
    """Checks if the given data model is a prediction

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Prediction.get_schema()):
        return True
    return False

Checks if is a similarity search data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_similarity_search",
        "synalinks.is_similarity_search",
    ]
)
def is_similarity_search(x):
    """Checks if is a similarity search data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if properties.get("entity_label", None) and properties.get(
            "similarity_search", None
        ):
            return True
    return False

is_tool_call(x)

Checks if the given data model is a tool call

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_tool_call",
        "synalinks.is_tool_call",
    ]
)
def is_tool_call(x):
    """Checks if the given data model is a tool call

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), ToolCall.get_schema()):
        return True
    return False

is_trainable(x)

Checks if the given data model is Trainable

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_trainable",
        "synalinks.is_trainable",
    ]
)
def is_trainable(x):
    """Checks if the given data model is Trainable

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    if contains_schema(x.get_schema(), Trainable.get_schema()):
        return True
    return False

Checks if is a triplet seach data model

Parameters:

Name Type Description Default
x DataModel | JsonDataModel | SymbolicDataModel | Variable

The data model to check.

required

Returns:

Type Description
bool

True if the condition is met

Source code in synalinks/src/backend/pydantic/base.py
@synalinks_export(
    [
        "synalinks.backend.is_triplet_search",
        "synalinks.is_triplet_search",
    ]
)
def is_triplet_search(x):
    """Checks if is a triplet seach data model

    Args:
        x (DataModel | JsonDataModel | SymbolicDataModel | Variable):
            The data model to check.

    Returns:
        (bool): True if the condition is met
    """
    schema = x.get_schema()
    properties = schema.get("properties", None)
    if properties:
        if (
            properties.get("subject_label", None)
            and properties.get("subject_similarity_search", None)
            and properties.get("relation_label", None)
            and properties.get("object_label", None)
            and properties.get("object_similarity_search", None)
        ):
            return True
    return False