Setting Connection & Initializing

1. Setting Up the Datalake Connection

Before using Promptlake, a MongoDB connection must be established within Datalake.

from config import Config
from dotenv import load_dotenv
from groclake.datalake import Datalake

load_dotenv()

class DatalakeConnection(Datalake):
    def __init__(self):
        super().__init__()
        MONGODB_CONFIG = Config.MONGODB_CONFIG
        MONGODB_CONFIG['connection_type'] = 'mongo'

        self.test_pipeline = self.create_pipeline(name="test_pipeline")
        self.test_pipeline.add_connection(name="mongodb_connection", config=MONGODB_CONFIG)
        self.execute_all()

        self.connections = {
            "mongodb_connection": self.get_connection("mongodb_connection")
        }

    def get_connection(self, connection_name):
        return self.test_pipeline.get_connection_by_name(connection_name)

# Initialize the connection
datalake_connection = DatalakeConnection()
mongodb_connection = datalake_connection.connections["mongodb_connection"]

What This Does

  • Initializes a Datalake instance.

  • Sets up MongoDB as a connection inside a data pipeline.

  • Executes all configured connections and stores them in a dictionary for easy access.


2. Initializing Promptlake

After setting up the Datalake connection, Promptlake can be initialized.

class Promptlake:
    def __init__(self):
        self.mongodb_connection = mongodb_connection
  • This class provides structured methods for storing and retrieving prompts.

  • It directly interacts with the MongoDB connection from Datalake.

Last updated