chatlog#
Attributes#
Classes#
Represents a chat log entry for a request and response |
|
Handles chat logging functionality |
|
An instance of this class is created for each chat request. |
|
A handler class which writes logging records, appropriately formatted, |
|
Functions#
|
|
|
Log a chat interaction to the chat log file. |
Module Contents#
- class chatlog.ChatLogItem[source]#
Represents a chat log entry for a request and response
- classmethod from_dict(data: Dict[str, Any]) ChatLogItem [source]#
Create from dictionary (e.g. from JSON)
- class chatlog.ChatLogger(log_file_path: str)[source]#
Handles chat logging functionality
- log_chat(item: ChatLogItem)[source]#
Log a chat item to the JSON file
- get_logs() List[ChatLogItem] [source]#
Get all chat logs
- get_conversation_logs(conversation_id: str) List[ChatLogItem] [source]#
Get logs for a specific conversation
- class chatlog.ChatSocketAPI(project: mdvtools.mdvproject.MDVProject, id: str, room: str, conversation_id: str)[source]#
An instance of this class is created for each chat request. It will instantiate a Logger instance & SocketIOHandler which should be GCed when the request is finished.
- update_chat_progress(message: str, id: str, progress: int, delta: int)[source]#
Send a message to the chat log and also update the progress bar.
- Parameters:
message (str) – the message to send to the chat log
id (str) – the id of the associated chat request
progress (int) – the progress value (%) to update the progress bar with
delta (int) – the expected cost of the current operation (%)
- class chatlog.ChatSocketIOHandler(socketio: flask_socketio.SocketIO, event_name: str, namespace: str, id: str, room: str)[source]#
Bases:
logging.StreamHandler
A handler class which writes logging records, appropriately formatted, to a stream. Note that this class does not close the stream, as sys.stdout or sys.stderr may be used.
- class chatlog.LangchainLoggingHandler(logger: logging.Logger)[source]#
Bases:
langchain_core.callbacks.BaseCallbackHandler
- chatlog.log_chat_item(project, question, output, prompt_template, response, conversation_id, view_name: str | None, error: bool = False)[source]#
Log a chat interaction to the chat log file. :param project: The MDVProject instance :param output: Result of invoke ‘from langchain.chains import RetrievalQA’ (can be None for errors) :param prompt_template: The template used for the prompt (can be empty for errors) :param response: The response generated (error message if error) :param conversation_id: ID to group messages from the same conversation :param error: Whether this log is for an error