memoryscope.core.chat.base_memory_chat

class memoryscope.core.chat.base_memory_chat.BaseMemoryChat(**kwargs)[source]

Bases: object

An abstract base class representing a chat system integrated with memory services. It outlines the method to initiate a chat session leveraging memory data, which concrete subclasses must implement.

__init__(**kwargs)[source]
property memory_service: BaseMemoryService

Abstract property to access the memory service.

Raises:

NotImplementedError – This method should be implemented in a subclass.

abstract chat_with_memory(query: str, role_name: str | None = None, system_prompt: str | None = None, memory_prompt: str | None = None, temporary_memories: str | None = None, history_message_strategy: Literal['auto', None] | int = 'auto', remember_response: bool = True, **kwargs)[source]

The core function that carries out conversation with memory accepts user queries through query and returns the conversation results through model_response. The retrieved memories are stored in the memories within meta_data. :param query: User’s query, includes the user’s question. :type query: str :param role_name: User’s role name. :type role_name: str, optional :param system_prompt: System prompt. Defaults to the system_prompt in “memory_chat_prompt.yaml”. :type system_prompt: str, optional :param memory_prompt: Memory prompt, It takes effect when there is a memory and will be placed in

front of the retrieved memory. Defaults to the memory_prompt in “memory_chat_prompt.yaml”.

Parameters:
  • temporary_memories (str, optional) – Manually added user memory in this function.

  • history_message_strategy ("auto", None, int) –

    • If it is set to “auto”, the history messages in the conversation will retain those that have not

      yet been summarized. Default to “auto”.

    • If it is set to None, no conversation history will be saved.

    • If it is set to an integer value “n”, recent “n” message-pair[user, assistant] will be retained.

  • remember_response (bool, optional) – Flag indicating whether to save the AI’s response to memory. Defaults to False.

Returns:

In non-streaming mode, returns a complete AI response. - ModelResponseGen: In streaming mode, returns a generator yielding AI response parts. - Memories: To obtain the memory by invoking the method of model_response.meta_data[MEMORIES]

Return type:

  • ModelResponse

start_backend_service(**kwargs)[source]
run_service_operation(name: str, role_name: str | None = None, **kwargs)[source]
run()[source]

Abstract method to run the chat system.

This method should contain the logic to initiate and manage the chat process, utilizing the memory service as needed. It must be implemented by subclasses.