memoryscope.core.utils.tool_functions
- memoryscope.core.utils.tool_functions.underscore_to_camelcase(name: str, is_first_title: bool = True) str [source]
Converts an underscore_notation string to CamelCase.
- Parameters:
name (str) – The underscore_notation string to be converted.
is_first_title (bool) – Title the first word or not. Defaults to True
- Returns:
A CamelCase formatted string.
- Return type:
str
- memoryscope.core.utils.tool_functions.camelcase_to_underscore(name: str) str [source]
Converts a CamelCase string to underscore_notation.
- Parameters:
name (str) – The CamelCase formatted string to be converted.
- Returns:
A converted string in underscore_notation.
- Return type:
str
- memoryscope.core.utils.tool_functions.init_instance_by_config(config: dict, default_class_dir: str = 'memoryscope', **kwargs)[source]
Initialize an instance of a class specified in the configuration dictionary.
This function dynamically imports a class from a module path, allowing for user-defined classes or default paths. It supports adding a suffix to the class name, merging additional keyword arguments with the config, and handling nested module paths.
- Parameters:
config (dict) – A dictionary containing the configuration, including the ‘class’ key that specifies the class’s module path.
default_class_dir (str, optional) – The default module path prefix to use if not explicitly defined in ‘config’. Defaults to “memory_scope”.
**kwargs – Additional keyword arguments to pass to the class constructor.
- Returns:
An instance initialized with the provided config and kwargs.
- Return type:
instance
- memoryscope.core.utils.tool_functions.prompt_to_msg(system_prompt: str, few_shot: str, user_query: str, concat_system_prompt: bool = True) List[Message] [source]
Converts input strings into a structured list of message objects suitable for AI interactions.
- Parameters:
system_prompt (str) – The system-level instruction or context.
few_shot (str) – An example or demonstration input, often used for illustrating expected behavior.
user_query (str) – The actual user query or prompt to be processed.
concat_system_prompt (bool) – Concat system prompt again or not in the user message. A simple method to improve the effectiveness for some LLMs. Defaults to True.
- Returns:
A list of Message objects, each representing a part of the conversation setup.
- Return type:
List[Message]
- memoryscope.core.utils.tool_functions.char_logo(words: str, seed: int = 1729505172166990279, color=None)[source]
Render the context of logo with colors
- Parameters:
words – The context of logo.
seed – The random seed which generates colors if there is no specific color. Defaults to the current timestamp.
color – The specific color. Defaults to None.
- Returns:
A rendered logo
- memoryscope.core.utils.tool_functions.md5_hash(input_string: str) str [source]
Computes a MD5 hash of the given input string.
- Parameters:
input_string (str) – The string for which the MD5 hash needs to be computed.
- Returns:
A hexadecimal MD5 hash representation.
- Return type:
str
- memoryscope.core.utils.tool_functions.contains_keyword(text, keywords) bool [source]
Checks if the given text contains any of the specified keywords, ignoring case.
- Parameters:
text (str) – The text to search within.
keywords (List[str]) – A list of keywords to look for in the text.
- Returns:
True if any keyword is found in the text, False otherwise.
- Return type:
bool