fabricatio_diff.capabilities.diff_edit

Module for handling diff-based editing operations.

Classes

DiffEdit

A class for performing diff-based edits using a language model.

Module Contents

class fabricatio_diff.capabilities.diff_edit.DiffEdit(/, **data: Any)

Bases: fabricatio_core.capabilities.usages.UseLLM, abc.ABC

A class for performing diff-based edits using a language model.

Inherits from UseLLM and ABC to enable language model usage and abstract base class functionality.

async diff_edit(source: str, requirement: str, match_precision: float | None = None, **kwargs: Unpack[fabricatio_core.models.kwargs_types.ValidateKwargs[fabricatio_diff.models.diff.Diff]]) str | None

Perform a diff edit operation on the provided source string based on the given requirement.

Parameters:
  • source (str) – The original string to be edited.

  • requirement (str) – The requirement or target state that guides the edit.

  • match_precision (float | None) – The precision level for matching lines.

  • **kwargs – Additional keyword arguments passed to the diff method.

Returns:

The edited string if a valid diff is applied; otherwise, None.

Return type:

str | None

async diff(source: str, requirement: str, **kwargs: Unpack[fabricatio_core.models.kwargs_types.ValidateKwargs[fabricatio_diff.models.diff.Diff]]) fabricatio_diff.models.diff.Diff | None

Generate a Diff object by querying the language model with a prompt template.

Internally uses _validator to validate the response and construct a Diff instance.

Parameters:
  • source (str) – The original string to compare.

  • requirement (str) – The desired changes or content to match.

  • **kwargs – Validated keyword arguments specific to the Diff type.

Returns:

A Diff instance if validation succeeds; otherwise, None.

Return type:

Diff | None