No project description provided
Project description
stateful-chat-client
Conversation Logger for MongoDB
A Python package to facilitate recording and retrieving AI conversations from a MongoDB database.
Features
- Record conversations to MongoDB in real-time.
- Retrieve past conversations from the database.
- Organize conversations based on unique thread IDs.
Installation
To install the package, use pip:
pip install stateful-chat-client
Quickstart
- Setting up the logger
from stateful-chat-client import ConversationLogger logger = ConversationLogger(host='localhost', port=27017, database_name='conversation_database', collection_name='conversations')
- Recording a conversation
from stateful-chat-client.conversation_logger import record_conversation from langchain.llms import OpenAI from langchain.chains import ConversationChain from langchain.chains.conversation.memory import ConversationBufferMemory conversation = ConversationChain( llm=OpenAI(), memory=ConversationBufferMemory(), verbose=True, ) conversation.predict(input="Hello!") thread_id = str(uuid.uuid4()) messages = conversation.memory.buffer_as_messages record_conversation(messages, thread_id, logger=logger)
- Retrieve past conversations and save to memory
from stateful-chat-client.conversation_logger import retrieve_and_save_to_memory new_conversation = ConversationChain( llm=OpenAI(), memory=ConversationBufferMemory(), verbose=True, ) new_conversation = retrieve_and_save_to_memory(thread_id, new_conversation_instance, logger=logger) new_conversation.predict(input="Hello! What did I say first?")
Requirements
- MongoDB server (local or remote)
- Python 3.8 or newer
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for stateful_chat_client-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9756a9226312b0114c34416beb487b051a4be6d070ec830c911cfc8987bd27ae |
|
MD5 | e9aaa81c0ccb9e7f83637166c33394bd |
|
BLAKE2b-256 | cfa79453b10eb6dc6a7b18fd612fd077b0ba89adac442c30b4b17177aa207c9f |
Close
Hashes for stateful_chat_client-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d947d8ed2d77d81a53b625dad50bcf8613947261e485153bfa13d1cb1e277bd9 |
|
MD5 | 2d6f7e0db564767eddea792048ab94f7 |
|
BLAKE2b-256 | c09b3b219dcd261fee63c49e61eae4509bbb5687bdf3447d313e2dcc6378b925 |