Skip to content

Pipeline preset

The base class for pipeline presets.

Authors

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

BasePipelinePreset(language_model_id='openai/gpt-4o-mini', language_model_credentials=None, system_instruction='')

Bases: ABC

Base class for pipeline presets.

This class functions both as a preset configuration and as an executable pipeline.

Attributes:

Name Type Description
language_model_id str | ModelId

The model id, can either be a ModelId instance or a string in the following format: 1. For azure-openai provider: azure-openai/azure-endpoint:azure-deployment. 2. For openai-compatible provider: openai-compatible/base-url:model-name. 3. For langchain provider: langchain/<package>.<class>:model-name. 4. For other providers: provider/model-name.

language_model_credentials str | dict[str, Any] | None

The credentials for the language model. Can either be: 1. An API key. 2. A path to a credentials JSON file, currently only supported for Google Vertex AI. 3. A dictionary of credentials, currently only supported for LangChain.

system_instruction str

The system instruction for the language model.

Initialize a new preset.

Parameters:

Name Type Description Default
language_model_id str | ModelId

The model id, can either be a ModelId instance or a string in the following format: 1. For azure-openai provider: azure-openai/azure-endpoint:azure-deployment. 2. For openai-compatible provider: openai-compatible/base-url:model-name. 3. For langchain provider: langchain/<package>.<class>:model-name. 4. For other providers: provider/model-name. Defaults to "openai/gpt-4o-mini".

'openai/gpt-4o-mini'
language_model_credentials str | dict[str, Any] | None

The credentials for the language model. Can either be: 1. An API key. 2. A path to a credentials JSON file, currently only supported for Google Vertex AI. 3. A dictionary of credentials, currently only supported for LangChain. Defaults to None.

None
system_instruction str

The system instruction for the language model. Defaults to an empty string.

''

__call__(query, attachments=None, config=None)

Invoke the pipeline.

This method works in both synchronous and asynchronous contexts. It automatically detects the current context and uses the appropriate approach.

Parameters:

Name Type Description Default
query str

The query to pass to the language model.

required
attachments list

The attachments to pass to the language model. Defaults to None.

None
config dict[str, Any]

The configuration to pass to the language model. Defaults to None.

None

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The response from the language model.

build() abstractmethod

Build the pipeline.

This method must be implemented by subclasses.

Returns:

Name Type Description
Pipeline Pipeline

The built pipeline.

Raises:

Type Description
NotImplementedError

If the method is not implemented by subclasses.

build_config(query, attachments=None, config=None) abstractmethod

Build the runtime configuration for the pipeline.

This method must be implemented by subclasses.

Parameters:

Name Type Description Default
query str

The query to pass to the language model.

required
attachments list[Any] | None

The attachments to pass to the language model. Defaults to None.

None
config dict[str, Any] | None

The configuration to pass to the language model. Defaults to None.

None

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The runtime configuration for the pipeline.

build_initial_state(query, attachments=None, config=None) abstractmethod

Build the initial state for the pipeline.

This method must be implemented by subclasses.

Parameters:

Name Type Description Default
query str

The query to pass to the language model.

required
attachments list[Any] | None

The attachments to pass to the language model. Defaults to None.

None
config dict[str, Any] | None

The configuration to pass to the language model. Defaults to None.

None

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The initial state for the pipeline.

invoke(query, attachments=None, config=None) async

Invoke the pipeline.

This method must be implemented by subclasses.

Parameters:

Name Type Description Default
query str

The query to pass to the language model.

required
attachments list

The attachments to pass to the language model. Defaults to None.

None
config dict[str, Any]

The configuration to pass to the language model. Defaults to None.

None

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The response from the language model.

Raises:

Type Description
NotImplementedError

If the method is not implemented by subclasses.