memoryscope.core.worker.memory_base_worker

class memoryscope.core.worker.memory_base_worker.MemoryBaseWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]

基类:BaseWorker

FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/memory_base_worker.py'
__init__(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]

Initializes the MemoryBaseWorker with specified models and configurations.

参数:
  • embedding_model (str) -- Identifier or instance of the embedding model used for transforming text.

  • generation_model (str) -- Identifier or instance of the text generation model.

  • rank_model (str) -- Identifier or instance of the ranking model for sorting the retrieved memories wrt. the semantic similarities.

  • **kwargs -- Additional keyword arguments passed to the parent class initializer.

The constructor also initializes key attributes related to memory store, monitoring, user and target identification, and a prompt handler, setting them up for later use.

property chat_messages: List[List[Message]]

Property to get the chat messages.

返回:

List of chat messages.

返回类型:

List[Message]

property chat_messages_scatter: List[Message]

Property to get the chat messages.

返回:

List of chat messages.

返回类型:

List[Message]

property chat_kwargs: Dict[str, Any]

Retrieves the chat keyword arguments from the context.

This property getter fetches the chat-related parameters stored in the context, which are used to configure how chat interactions are handled.

返回:

A dictionary containing the chat keyword arguments.

返回类型:

Dict[str, str]

property user_name: str
property target_name: str
property workflow_name: str
property language: LanguageEnum
property embedding_model: BaseModel

Property to get the embedding model. If the model is currently stored as a string, it will be replaced with the actual model instance from the global context's model dictionary.

返回:

The embedding model used for converting text into vector representations.

返回类型:

BaseModel

property generation_model: BaseModel

Property to access the generation model. If the model is stored as a string, it retrieves the actual model instance from the global context's model dictionary.

返回:

The model used for text generation.

返回类型:

BaseModel

property rank_model: BaseModel

Property to access the rank model. If the stored rank model is a string, it fetches the actual model instance from the global context's model dictionary before returning it.

返回:

The rank model instance used for ranking tasks.

返回类型:

BaseModel

property memory_store: BaseMemoryStore

Property to access the memory vector store. If not initialized, it fetches the global memory store.

返回:

The memory store instance used for inserting, updating, retrieving and deleting operations.

返回类型:

BaseMemoryStore

property monitor: BaseMonitor

Property to access the monitoring component. If not initialized, it fetches the global monitor.

返回:

The monitoring component instance.

返回类型:

BaseMonitor

property prompt_handler: PromptHandler

Lazily initializes and returns the PromptHandler instance.

返回:

An instance of PromptHandler initialized with specific file path and keyword arguments.

返回类型:

PromptHandler

property memory_manager: MemoryManager

Lazily initializes and returns the MemoryHandler instance.

返回:

An instance of MemoryHandler.

返回类型:

MemoryHandler

get_language_value(languages: dict | List[dict]) Any | List[Any][源代码]

Retrieves the value(s) corresponding to the current language context.

参数:

languages (dict | list[dict]) -- A dictionary or list of dictionaries containing language-keyed values.

返回:

The value or list of values matching the current language setting.

返回类型:

Any | list[Any]

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]

name: str
workflow_context: Dict[str, Any]
memoryscope_context: MemoryscopeContext
raise_exception: bool
is_multi_thread: bool
thread_pool: ThreadPoolExecutor
enable_parallel: bool
kwargs: dict
continue_run: bool
async_task_list: list
thread_task_list: list
logger: Logger