fabricatio_core.models.generic
This module defines generic classes for models in the Fabricatio library, providing a foundation for various model functionalities.
Classes
Base class for all models with Pydantic configuration. |
|
Class that provides formatted JSON representation utilities. |
|
Class that includes a name attribute. |
|
Class that includes a description attribute. |
|
Class that includes a title attribute. |
|
Class that combines naming and description attributes with briefing generation. |
|
Class that manages file dependencies. |
|
Class that prepares the vectorization of the model. |
|
Configuration holder with hierarchical fallback mechanism. |
|
Configuration for embedding-related settings. |
|
Configuration for reranker-related settings. |
|
Configuration for LLM-related settings. |
|
Class that provides a reverse JSON schema of the model. |
|
Class that provides a formatted JSON schema of the model. |
|
Class that provides a prompt for creating a JSON object. |
|
Class that provides a method to instantiate the class from a string. |
|
Class that provides a method to propose a JSON object based on the requirement. |
|
Class that provides a language attribute. |
|
Class that provides a method to scratch the object. |
Module Contents
- class fabricatio_core.models.generic.Base(/, **data: Any)[source]
Bases:
pydantic.BaseModel,abc.ABCBase class for all models with Pydantic configuration.
This class sets up the basic Pydantic configuration for all models in the Fabricatio library. The
model_configusesuse_attribute_docstrings=Trueto ensure field descriptions are pulled from the attribute’s docstring instead of the default Pydantic behavior.- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fabricatio_core.models.generic.Display(/, **data: Any)[source]
-
Class that provides formatted JSON representation utilities.
Provides methods to generate both pretty-printed and compact JSON representations of the model. Used for debugging and logging purposes.
- display() str[source]
Generate pretty-printed JSON representation.
- Returns:
JSON string with 1-level indentation for readability
- Return type:
- compact() str[source]
Generate compact JSON representation.
- Returns:
Minified JSON string without whitespace
- Return type:
- class fabricatio_core.models.generic.Named(/, **data: Any)[source]
-
Class that includes a name attribute.
This class adds a name attribute to models, which is intended to be a unique identifier.
- class fabricatio_core.models.generic.Described(/, **data: Any)[source]
-
Class that includes a description attribute.
This class adds a description attribute to models, providing additional context or information.
- description: str
A comprehensive description of this object, including its purpose, scope, and context. This should clearly explain what this object is about, why it exists, and in what situations it applies. The description should be detailed enough to provide full understanding of this object’s intent and application.
- class fabricatio_core.models.generic.Titled(/, **data: Any)[source]
-
Class that includes a title attribute.
- class fabricatio_core.models.generic.WithBriefing(/, **data: Any)[source]
Bases:
Named,Described,abc.ABCClass that combines naming and description attributes with briefing generation.
This class inherits from both Named and Described classes to provide a combined interface that includes both name and description attributes. It also provides automatic briefing generation by combining these two attributes.
- class fabricatio_core.models.generic.WithDependency(/, **data: Any)[source]
-
Class that manages file dependencies.
This class includes methods to manage file dependencies required for reading or writing.
- dependencies: List[str] = None
The file dependencies which is needed to read or write to meet a specific requirement, a list of file paths.
- add_dependency[P: str | pathlib.Path](dependency: P | List[P]) Self[source]
Add a file dependency to the task.
- remove_dependency[P: str | pathlib.Path](dependency: P | List[P]) Self[source]
Remove a file dependency from the task.
- clear_dependencies() Self[source]
Clear all file dependencies from the task.
- Returns:
The current instance of the task.
- Return type:
Self
- override_dependencies[P: str | pathlib.Path](dependencies: List[P] | P) Self[source]
Override the file dependencies of the task.
- class fabricatio_core.models.generic.Vectorizable[source]
Bases:
abc.ABCClass that prepares the vectorization of the model.
This class includes methods to prepare the model for vectorization, ensuring it fits within a specified token length.
- prepare_vectorization() str[source]
Prepare the vectorization of the model.
- Returns:
The prepared vectorization of the model.
- Return type:
- Raises:
ValueError – If the chunk exceeds the maximum sequence length.
- class fabricatio_core.models.generic.ScopedConfig(/, **data: Any)[source]
-
Configuration holder with hierarchical fallback mechanism.
- fallback_to(other: ScopedConfig | Any, exclude: Set[str] | None = None) Self[source]
Merge configuration values with fallback priority.
Copies non-null values from ‘other’ to self where current values are None.
- Parameters:
other (ScopedConfig) – Configuration to fallback to
exclude (Optional[Set[str]]) – Field names to exclude from fallback
- Returns:
Current instance with merged values
- Return type:
Self
- hold_to(others: ScopedConfig | Any | Iterable[ScopedConfig | Any], exclude: Set[str] | None = None) Self[source]
Propagate non-null values to other configurations.
Copies current non-null values to target configurations where they are None.
- Parameters:
others (ScopedConfig|Iterable) – Target configurations to update
exclude (Optional[Set[str]]) – Field names to exclude from propagation
- Returns:
Current instance unchanged
- Return type:
Self
- class fabricatio_core.models.generic.EmbeddingScopedConfig(/, **data: Any)[source]
Bases:
ScopedConfigConfiguration for embedding-related settings.
- class fabricatio_core.models.generic.RerankerScopedConfig(/, **data: Any)[source]
Bases:
ScopedConfigConfiguration for reranker-related settings.
- class fabricatio_core.models.generic.LLMScopedConfig(/, **data: Any)[source]
Bases:
ScopedConfigConfiguration for LLM-related settings.
- llm_max_completion_tokens: pydantic.PositiveInt | None = None
The maximum number of tokens to generate.
- class fabricatio_core.models.generic.UnsortGenerate(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of')[source]
Bases:
pydantic.json_schema.GenerateJsonSchemaClass that provides a reverse JSON schema of the model.
This class overrides the sorting behavior of the JSON schema generation to maintain the original order.
- sort(value: pydantic.json_schema.JsonSchemaValue, parent_key: str | None = None) pydantic.json_schema.JsonSchemaValue[source]
Not sort.
- Parameters:
value (JsonSchemaValue) – The JSON schema value to sort.
parent_key (str | None) – The parent key of the JSON schema value.
- Returns:
The JSON schema value without sorting.
- Return type:
JsonSchemaValue
- class fabricatio_core.models.generic.WithFormatedJsonSchema(/, **data: Any)[source]
-
Class that provides a formatted JSON schema of the model.
This class includes a method to generate a formatted JSON schema of the model.
- class fabricatio_core.models.generic.CreateJsonObjPrompt(/, **data: Any)[source]
Bases:
WithFormatedJsonSchema,abc.ABCClass that provides a prompt for creating a JSON object.
This class includes a method to create a prompt for creating a JSON object based on the model’s schema and a requirement.
- class fabricatio_core.models.generic.InstantiateFromString(/, **data: Any)[source]
-
Class that provides a method to instantiate the class from a string.
This class includes a method to instantiate the class from a JSON string representation.
- class fabricatio_core.models.generic.ProposedAble(/, **data: Any)[source]
Bases:
CreateJsonObjPrompt,InstantiateFromString,abc.ABCClass that provides a method to propose a JSON object based on the requirement.
This class combines the functionality to create a prompt for a JSON object and instantiate it from a string.
- class fabricatio_core.models.generic.SketchedAble(/, **data: Any)[source]
Bases:
ProposedAble,Display,abc.ABCClass that provides a method to scratch the object.
This class combines the functionality to propose a JSON object, instantiate it from a string, and display it.