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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stateful_chat_client-0.1.0.tar.gz.
File metadata
- Download URL: stateful_chat_client-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.8.5 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9756a9226312b0114c34416beb487b051a4be6d070ec830c911cfc8987bd27ae
|
|
| MD5 |
e9aaa81c0ccb9e7f83637166c33394bd
|
|
| BLAKE2b-256 |
cfa79453b10eb6dc6a7b18fd612fd077b0ba89adac442c30b4b17177aa207c9f
|
File details
Details for the file stateful_chat_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stateful_chat_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.8.5 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d947d8ed2d77d81a53b625dad50bcf8613947261e485153bfa13d1cb1e277bd9
|
|
| MD5 |
2d6f7e0db564767eddea792048ab94f7
|
|
| BLAKE2b-256 |
c09b3b219dcd261fee63c49e61eae4509bbb5687bdf3447d313e2dcc6378b925
|