Skip to main content

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

  1. Setting up the logger
    from stateful-chat-client import ConversationLogger
    
    logger = ConversationLogger(host='localhost', port=27017,    database_name='conversation_database', collection_name='conversations')
    
  2. 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)
    
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stateful_chat_client-0.1.0.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

stateful_chat_client-0.1.0-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page