Skip to content

chronulus_core.types.attribute

Text

Bases: BaseModel

Attribute to upload a large text document

Parameters:

Name Type Description Default
data str

The content of the large text document

required

Attributes:

Name Type Description
data str

The content of the large text document

Source code in src2/chronulus_core/types/attribute.py
class Text(BaseModel):
    """Attribute to upload a large text document

    Parameters
    ----------
    data : str
        The content of the large text document

    Attributes
    ----------
    data : str
        The content of the large text document
    """
    data: str = Field(description='the contents of the text file')

TextFromFile

Bases: BaseModel

Attribute to upload a text document from a local file

The text should be accessible in your local file system by the client

Parameters:

Name Type Description Default
file_path str

Path to text file, e.g., '/path/to/text.txt'

required

Attributes:

Name Type Description
file_path str

Path to text file, e.g., '/path/to/text.txt'

data Optional[str]

The content of the large text document

Source code in src2/chronulus_core/types/attribute.py
class TextFromFile(BaseModel):
    """Attribute to upload a text document from a local file

    The text should be accessible in your local file system by the client

    Parameters
    ----------
    file_path : str
        Path to text file, e.g., '/path/to/text.txt'

    Attributes
    ----------
    file_path : str
        Path to text file, e.g., '/path/to/text.txt'
    data : Optional[str]
        The content of the large text document

    """
    file_path: str = Field(exclude=True, description='path to the text file')
    data: Union[str, None] = Field(default=None, description='the contents of the text file')

    def model_post_init(self, __context: Any) -> None:
        if self.data is None:

            try:
                # Try UTF-8 first
                with open(self.file_path, 'r', encoding='utf-8') as f:
                    text_content = f.read()
            except UnicodeDecodeError:
                # Fallback if UTF-8 fails
                print("Warning: UTF-8 decoding failed, trying system default encoding")
                with open(self.file_path, 'r') as f:
                    text_content = f.read()
            file_name = os.path.basename(self.file_path)
            text_content = f"file: {file_name}\n\n" + text_content

            self.data = text_content