memoryscope.core.utils.tool_functions
- memoryscope.core.utils.tool_functions.underscore_to_camelcase(name: str, is_first_title: bool = True) str [源代码]
Converts an underscore_notation string to CamelCase.
- 参数:
name (str) -- The underscore_notation string to be converted.
is_first_title (bool) -- Title the first word or not. Defaults to True
- 返回:
A CamelCase formatted string.
- 返回类型:
str
- memoryscope.core.utils.tool_functions.camelcase_to_underscore(name: str) str [源代码]
Converts a CamelCase string to underscore_notation.
- 参数:
name (str) -- The CamelCase formatted string to be converted.
- 返回:
A converted string in underscore_notation.
- 返回类型:
str
- memoryscope.core.utils.tool_functions.init_instance_by_config(config: dict, default_class_dir: str = 'memoryscope', **kwargs)[源代码]
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.
- 参数:
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.
- 返回:
An instance initialized with the provided config and kwargs.
- 返回类型:
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] [源代码]
Converts input strings into a structured list of message objects suitable for AI interactions.
- 参数:
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.
- 返回:
A list of Message objects, each representing a part of the conversation setup.
- 返回类型:
List[Message]
- memoryscope.core.utils.tool_functions.char_logo(words: str, seed: int = 1732168973570471006, color=None)[源代码]
Render the context of logo with colors
- 参数:
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.
- 返回:
A rendered logo
- memoryscope.core.utils.tool_functions.md5_hash(input_string: str) str [源代码]
Computes a MD5 hash of the given input string.
- 参数:
input_string (str) -- The string for which the MD5 hash needs to be computed.
- 返回:
A hexadecimal MD5 hash representation.
- 返回类型:
str
- memoryscope.core.utils.tool_functions.contains_keyword(text, keywords) bool [源代码]
Checks if the given text contains any of the specified keywords, ignoring case.
- 参数:
text (str) -- The text to search within.
keywords (List[str]) -- A list of keywords to look for in the text.
- 返回:
True if any keyword is found in the text, False otherwise.
- 返回类型:
bool