utils
¶
LoguruFormatter
¶
LoguruFormatter(
fmt: Optional[str] = None,
max_length: Optional[int] = None,
suffix_length: int = 0,
)
Custom formatter for loguru logger.
Parameters:
-
fmt
(Optional[str]
, default:None
) –The format string for the log message.
-
max_length
(Optional[int]
, default:None
) –The maximum length of the message, truncate if longer.
-
suffix_length
(int
, default:0
) –The length of the suffix to keep when truncating.
Source code in src/appl/utils.py
loguru_format
¶
Format the log message with the record.
Source code in src/appl/utils.py
find_dotenv
¶
find_dotenv(
filename: str = ".env",
raise_error_if_not_found: bool = False,
current_folder: Optional[str] = None,
usecwd: bool = False,
) -> str
Search in increasingly higher folders for the given file.
Returns path to the file if found, or an empty string otherwise.
Source code in src/appl/utils.py
find_files
¶
Find files in the folder or its parent folders.
Source code in src/appl/utils.py
get_folder
¶
Get the the current working directory.
Source code in src/appl/utils.py
get_git_info
¶
get_git_info() -> GitInfo
Get the git info of the current project.
Source code in src/appl/utils.py
get_meta_file
¶
Get the meta file storing metadata of the trace file.
get_num_tokens
¶
get_num_tokens(
prompt: str,
model_name: Optional[str] = None,
encoding_name: Optional[str] = None,
) -> int
Get the number of tokens in the prompt for the given model or encoding.
Source code in src/appl/utils.py
namespace_to_dict
¶
Recursively converts a nested argparse.Namespace object to a nested dictionary.
Parameters:
-
namespace
(Namespace
) –An argparse.Namespace object, potentially containing nested Namespace objects
Returns:
Example
args = parser.parse_args() args_dict = namespace_to_dict(args)
Source code in src/appl/utils.py
timeit
¶
Time the execution of a function as a decorator.