utils
Various utiles used from the projects.
deprecation_warning(message, skip=3)
Log a deprecation warning with caller's information. "skip" is the number of stack levels to go back to the caller info.
Source code in cat/utils.py
get_base_path()
get_base_url()
Allows exposing the base url.
Source code in cat/utils.py
get_caller_info(skip=2, return_short=True, return_string=True)
Get the name of a caller in the format module.class.method.
Adapted from: https://gist.github.com/techtonik/2151727
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip
|
int
|
Specifies how many levels of stack to skip while getting caller name. |
2
|
return_string
|
bool
|
If True, returns the caller info as a string, otherwise as a tuple. |
True
|
Returns:
Name | Type | Description |
---|---|---|
package |
str
|
Caller package. |
module |
str
|
Caller module. |
klass |
str
|
Caller classname if one otherwise None. |
caller |
str
|
Caller function or method (if a class exist). |
line |
int
|
The line of the call. |
Notes
skip=1 means "who calls me", skip=2 "who calls my caller" etc.
None is returned if skipped levels exceed stack height.
Source code in cat/utils.py
get_plugins_path()
get_static_path()
get_static_url()
match_prompt_variables(prompt_variables, prompt_template)
Ensure prompt variables and prompt placeholders map, so there are no issues on mismatches
Source code in cat/utils.py
to_camel_case(text)
Format string to camel case.
Takes a string of words separated by either hyphens or underscores and returns a string of words in camel case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
String of hyphens or underscores separated words. |
required |
Returns:
Type | Description |
---|---|
str
|
Camel case formatted string. |
Source code in cat/utils.py
verbal_timedelta(td)
Convert a timedelta in human form.
The function takes a timedelta and converts it to a human-readable string format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
td
|
timedelta
|
Difference between two dates. |
required |
Returns:
Type | Description |
---|---|
str
|
Human-readable string of time difference. |
Notes
This method is used to give the Language Model information time information about the memories retrieved from the vector database.
Examples: