Skip to content

Utils

config_loader

llama_utils.utils.config_loader

A class or function to load configuration.

ConfigLoader

A class or function to load configuration.

Source code in src/llama_utils/utils/config_loader.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class ConfigLoader:
    """A class or function to load configuration."""

    def __init__(
        self,
        llm: Any = None,
        embedding: Any = None,
    ):
        """Initialize the ConfigLoader class.

        Parameters
        ----------
        llm: Any, optional, default is llama3
            llm model to use.
        embedding: Any, optional, default is BAAI/bge-base-en-v1.5
            Embedding model to use.
        """
        if llm is None:
            llm = get_ollama_llm()
        if embedding is None:
            embedding = get_hugging_face_embedding()

        Settings.embed_model = embedding
        Settings.llm = llm
        Settings.text_splitter = TEXT_SPLITTER
        self._settings = Settings
        self._embedding = embedding
        self._llm = llm

    @property
    def settings(self):
        """Get the settings."""
        return self._settings

    @property
    def llm(self):
        """Get the llm model."""
        return self._llm

    @llm.setter
    def llm(self, value):
        self._llm = value
        Settings.llm = value

    @property
    def embedding(self):
        """Get the embedding model."""
        return self._embedding

    @embedding.setter
    def embedding(self, value):
        self._embedding = value
        Settings.embed_model = value

embedding property writable

Get the embedding model.

llm property writable

Get the llm model.

settings property

Get the settings.

__init__(llm: Any = None, embedding: Any = None)

Initialize the ConfigLoader class.

Parameters:

Name Type Description Default
llm Any

llm model to use.

None
embedding Any

Embedding model to use.

None
Source code in src/llama_utils/utils/config_loader.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(
    self,
    llm: Any = None,
    embedding: Any = None,
):
    """Initialize the ConfigLoader class.

    Parameters
    ----------
    llm: Any, optional, default is llama3
        llm model to use.
    embedding: Any, optional, default is BAAI/bge-base-en-v1.5
        Embedding model to use.
    """
    if llm is None:
        llm = get_ollama_llm()
    if embedding is None:
        embedding = get_hugging_face_embedding()

    Settings.embed_model = embedding
    Settings.llm = llm
    Settings.text_splitter = TEXT_SPLITTER
    self._settings = Settings
    self._embedding = embedding
    self._llm = llm

helper_functions

llama_utils.utils.helper_functions

A collection of helper functions used across different modules (e.g., text preprocessing, validation).

HelperFunctions

A collection of helper functions used across different modules (e.g., text preprocessing, validation).

Source code in src/llama_utils/utils/helper_functions.py
10
11
12
13
14
15
class HelperFunctions:
    """A collection of helper functions used across different modules (e.g., text preprocessing, validation)."""

    def __init__(self):
        """Initialize the helper functions."""
        pass

__init__()

Initialize the helper functions.

Source code in src/llama_utils/utils/helper_functions.py
13
14
15
def __init__(self):
    """Initialize the helper functions."""
    pass

generate_content_hash(content: str)

Generate a hash for the document content using SHA-256.

Parameters:

Name Type Description Default
content str

The content of the document.

required

Returns:

Type Description
str

The SHA-256 hash of the content.

Source code in src/llama_utils/utils/helper_functions.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def generate_content_hash(content: str):
    """Generate a hash for the document content using SHA-256.

    Parameters
    ----------
    content: str
        The content of the document.

    Returns
    -------
    str
        The SHA-256 hash of the content.
    """
    return hashlib.sha256(content.encode("utf-8")).hexdigest()

is_sha256(string: str) -> bool

Check if a string is a valid SHA-256 hash.

Parameters:

Name Type Description Default
string str

The string to check.

required

Returns:

Type Description
bool

True if the string is a valid SHA-256 hash, False otherwise.

Source code in src/llama_utils/utils/helper_functions.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def is_sha256(string: str) -> bool:
    """Check if a string is a valid SHA-256 hash.

    Parameters
    ----------
    string: str
        The string to check.

    Returns
    -------
    bool
        True if the string is a valid SHA-256 hash, False otherwise.
    """
    # SHA-256 hash must be 64 characters long and contain only hexadecimal characters
    return bool(re.fullmatch(r"[a-fA-F0-9]{64}", string))