graphdoc.data.dspy_data.dspy_data_helper module

class graphdoc.data.dspy_data.dspy_data_helper.DspyDataHelper[source]

Bases: ABC

Abstract class for creating data objects related to a given dspy.Signature.

prompt_signature() Signature | SignatureMeta[source]

Given a prompt, return a dspy.Signature object.

Parameters:

prompt (Any) – A prompt.

static _(prompt: Predict) Signature | SignatureMeta[source]

Given a dspy.Predict object, return a dspy.Signature object.

static formatted_signature(signature: Signature | SignatureMeta, example: Example) str[source]

Given a dspy.Signature and a dspy.Example, return a formatted signature as a string.

Parameters:
  • signature (dspy.Signature) – A dspy.Signature object.

  • example (dspy.Example) – A dspy.Example object.

Returns:

A formatted signature as a string.

Return type:

str

abstract static example(inputs: dict[str, Any]) Example[source]

Given a dictionary of inputs, return a dspy.Example object.

Parameters:

inputs (dict[str, Any]) – A dictionary of inputs.

Returns:

A dspy.Example object.

Return type:

dspy.Example

abstract static example_example() Example[source]

Return an example dspy.Example object with the inputs set to the example values.

Returns:

A dspy.Example object.

Return type:

dspy.Example

abstract static model_signature() ModelSignature[source]

Return a mlflow.models.ModelSignature object. Based on the example object, removes the output fields and utilizes the remaining fields to infer the model signature.

Returns:

A mlflow.models.ModelSignature object.

Return type:

mlflow.models.ModelSignature

abstract static prediction(inputs: dict[str, Any]) Prediction[source]

Given a dictionary of inputs, return a dspy.Prediction object.

Parameters:

inputs (dict[str, Any]) – A dictionary of inputs.

Returns:

A dspy.Prediction object.

Return type:

dspy.Prediction

abstract static prediction_example() Prediction[source]

Return an example dspy.Prediction object with the inputs set to the example values.

Returns:

A dspy.Prediction object.

Return type:

dspy.Prediction

abstract static trainset(inputs: dict[str, Any] | Dataset, filter_args: dict[str, Any] | None = None) list[Example][source]

Given a dictionary of inputs or a datasets.Dataset object, return a list of dspy.Example objects.

Parameters:
  • inputs (Union[dict[str, Any], datasets.Dataset]) – A dictionary of inputs or a datasets.Dataset object.

  • filter_args (Optional[dict[str, Any]]) – A dictionary of filter arguments. These are instructions for how we will filter and / or transform the inputs.

Returns:

A list of dspy.Example objects.

Return type:

list[dspy.Example]