Skip to content

Input module

AudioInput(optional=False, name=None)

Instantiate a symbolic multimodal (audio) input for a Program.

The audio sibling of ImageInput: it declares a ChatMessages input branch into which you put a user ChatMessage whose content mixes the instruction text with one or more synalinks.Audio parts.

Parameters:

Name Type Description Default
optional bool

Whether the input is optional or not. An optional input can accept None values.

False
name string

Optional name string for the module. Should be unique in a program (do not reuse the same name twice). It will be autogenerated if it isn't provided.

None

Returns:

Type Description
SymbolicDataModel

A ChatMessages-shaped symbolic data model.

Source code in synalinks/src/modules/core/input_module.py
@synalinks_export(["synalinks.modules.AudioInput", "synalinks.AudioInput"])
def AudioInput(
    optional=False,
    name=None,
):
    """Instantiate a symbolic multimodal (audio) input for a `Program`.

    The audio sibling of `ImageInput`: it declares a `ChatMessages` input
    branch into which you put a user `ChatMessage` whose content mixes the
    instruction text with one or more `synalinks.Audio` parts.

    Args:
        optional (bool): Whether the input is optional or not.
            An optional input can accept `None` values.
        name (string): Optional name string for the module.
            Should be unique in a program (do not reuse the same name twice).
            It will be autogenerated if it isn't provided.

    Returns:
        (SymbolicDataModel): A `ChatMessages`-shaped symbolic data model.
    """
    return Input(data_model=ChatMessages, optional=optional, name=name)

ImageInput(optional=False, name=None)

Instantiate a symbolic multimodal (image) input for a Program.

A modality is a content part of a Message, so an image input is just a chat input: this declares a ChatMessages input branch into which you put a user ChatMessage whose content mixes the question text with one or more synalinks.Image parts.

Example:

import synalinks

inputs = synalinks.ImageInput()
outputs = await synalinks.Generator(
    data_model=Answer,
    language_model=language_model,
)(inputs)
program = synalinks.Program(inputs=inputs, outputs=outputs)

result = await program(
    synalinks.ChatMessages(
        messages=[
            synalinks.ChatMessage(
                role="user",
                content=[
                    "What is in this picture?",
                    synalinks.Image(url="https://example.com/cat.png"),
                ],
            )
        ]
    )
)

Parameters:

Name Type Description Default
optional bool

Whether the input is optional or not. An optional input can accept None values.

False
name string

Optional name string for the module. Should be unique in a program (do not reuse the same name twice). It will be autogenerated if it isn't provided.

None

Returns:

Type Description
SymbolicDataModel

A ChatMessages-shaped symbolic data model.

Source code in synalinks/src/modules/core/input_module.py
@synalinks_export(["synalinks.modules.ImageInput", "synalinks.ImageInput"])
def ImageInput(
    optional=False,
    name=None,
):
    """Instantiate a symbolic multimodal (image) input for a `Program`.

    A modality is a content part of a `Message`, so an image input is just a
    chat input: this declares a `ChatMessages` input branch into which you put
    a user `ChatMessage` whose content mixes the question text with one or more
    `synalinks.Image` parts.

    Example:

    ```python
    import synalinks

    inputs = synalinks.ImageInput()
    outputs = await synalinks.Generator(
        data_model=Answer,
        language_model=language_model,
    )(inputs)
    program = synalinks.Program(inputs=inputs, outputs=outputs)

    result = await program(
        synalinks.ChatMessages(
            messages=[
                synalinks.ChatMessage(
                    role="user",
                    content=[
                        "What is in this picture?",
                        synalinks.Image(url="https://example.com/cat.png"),
                    ],
                )
            ]
        )
    )
    ```

    Args:
        optional (bool): Whether the input is optional or not.
            An optional input can accept `None` values.
        name (string): Optional name string for the module.
            Should be unique in a program (do not reuse the same name twice).
            It will be autogenerated if it isn't provided.

    Returns:
        (SymbolicDataModel): A `ChatMessages`-shaped symbolic data model.
    """
    return Input(data_model=ChatMessages, optional=optional, name=name)

Input(schema=None, data_model=None, optional=False, name=None)

Used to instantiate a SymbolicDataModel.

A SymbolicDataModel is a symbolic data model-like object, which we augment with certain attributes that allow us to build a Synalinks Program just by knowing the inputs and outputs of the program (similar to Keras symbolic tensor).

Example:

import synalinks

class Query(synalinks.DataModel):
    query: str

inputs = synalinks.Input(data_model=Query)

# You can also create it using a JSON schema like this:

inputs = synalinks.Input(schema=Query.get_schema())

# Or using a symbolic datamodel:

inputs = synalinks.Input(data_model=Query.to_symbolic_data_model())

Parameters:

Name Type Description Default
schema dict

A Json schema of the data_model. If not provided uses the data_model argument.

None
data_model DataModel

Optional existing data model to wrap into the Input layer. If set, the module will use this data_model rather than creating a new placeholder data model.

None
optional bool

Whether the input is optional or not. An optional input can accept None values.

False
name string

Optional name string for the module. Should be unique in a program (do not reuse the same name twice). It will be autogenerated if it isn't provided.

None

Returns:

Type Description
SymbolicDataModel

The symbolic data model corresponding to the given data model/schema.

Source code in synalinks/src/modules/core/input_module.py
@synalinks_export(["synalinks.modules.Input", "synalinks.Input"])
def Input(
    schema=None,
    data_model=None,
    optional=False,
    name=None,
):
    """Used to instantiate a `SymbolicDataModel`.

    A `SymbolicDataModel` is a symbolic data model-like object, which we augment with
    certain attributes that allow us to build a Synalinks `Program` just by knowing the
    inputs and outputs of the program (similar to Keras symbolic tensor).

    Example:

    ```python
    import synalinks

    class Query(synalinks.DataModel):
        query: str

    inputs = synalinks.Input(data_model=Query)

    # You can also create it using a JSON schema like this:

    inputs = synalinks.Input(schema=Query.get_schema())

    # Or using a symbolic datamodel:

    inputs = synalinks.Input(data_model=Query.to_symbolic_data_model())
    ```

    Args:
        schema (dict): A Json schema of the data_model.
            If not provided uses the `data_model` argument.
        data_model (DataModel): Optional existing data model to wrap into
            the `Input` layer. If set, the module will use this data_model rather
            than creating a new placeholder data model.
        optional (bool): Whether the input is optional or not.
            An optional input can accept `None` values.
        name (string): Optional name string for the module.
            Should be unique in a program (do not reuse the same name twice).
            It will be autogenerated if it isn't provided.

    Returns:
        (SymbolicDataModel): The symbolic data model corresponding to
            the given data model/schema.
    """
    module = InputModule(
        schema=schema,
        input_data_model=data_model.to_symbolic_data_model() if data_model else None,
        optional=optional,
        name=name,
    )
    return module.output