maeser.chat.chat_session_manager module#

Module for managing chat sessions and interactions with multiple chat interfaces.

© 2024 Blaine Freestone, Carson Bush

This file is part of Maeser.

Maeser is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Maeser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Maeser. If not, see <https://www.gnu.org/licenses/>.

class maeser.chat.chat_session_manager.ChatSessionManager(chat_logs_manager: BaseChatLogsManager | None = None)[source]#

Bases: object

Manages and directs sessions for multiple chat interfaces.

add_feedback(branch_name: str, session_id: str, message_index: int, feedback: str) None[source]#

Adds feedback to the log for a specific response in a specific session.

Parameters:
  • branch_name (str) – The name of the branch.

  • session_id (str) – The session ID for the conversation.

  • message_index (int) – The index of the message to add feedback to.

  • feedback (str) – The feedback to add to the message.

Returns:

None

ask_question(message: str, branch_name: str, sess_id: str) dict[source]#

Asks a question in a specific session of a branch.

Parameters:
  • message (str) – The question to ask.

  • branch_name (str) – The action of the branch to ask the question in.

  • sess_id (str) – The session ID to ask the question in.

Returns:

The response to the question.

Return type:

dict

property branches: dict#

Returns the list of branches available for chat.

Returns:

The list of branches available for chat.

Return type:

dict

property chat_log_path: str | None#

Returns the path to the logs directory.

Returns:

The path to the logs directory.

Return type:

str | None

get_conversation_history(branch_name: str, session_id: str) dict[source]#

Gets the conversation history for a specific session in a specific branch.

Parameters:
  • branch_name (str) – The action of the branch to get the conversation history from.

  • session_id (str) – The session ID to get the conversation history from.

Returns:

The conversation history for the session.

Return type:

dict

get_new_session_id(branch_name: str, user: User | None = None) str[source]#

Creates a new chat session for the given branch action. Includes creating a new log file for the session.

Parameters:
  • branch_name (str) – The action of the branch to create a session for.

  • user (User | None) – The user to create the session for.

Returns:

The session ID for the new session.

Return type:

str

register_branch(branch_name: str, branch_label: str, graph: langgraph.graph.graph.CompiledGraph) None[source]#

Registers a branch with its information and graph.

Parameters:
  • branch_name (str) – The name of the branch.

  • branch_label (str) – The label of the branch.

  • graph (CompiledGraph) – The graph for the branch.

Returns:

None