Storing a Prompt
The save_prompt()
method saves a prompt to the MongoDB collection.
Example Usage
def save_prompt(self, client_uuid, messages, m=1):
latest_version = self.fetch_prompt(client_uuid, m, get_latest_version=True) or 0
new_version = latest_version + 1
prompt_id = client_uuid + ":" + str(m)
prompt_data = {
"prompt_id": prompt_id,
"prompt_version": new_version,
"model": "gpt-4",
"messages": messages,
"temperature": 0.7,
}
inserted_id = self.mongodb_connection.insert(collection_name="promptlake", data=prompt_data)
print("Prompt inserted into MongoDB with ID:", inserted_id)
How It Works
Retrieves the latest prompt version for a given user.
Increments the version and creates a new entry.
Saves the prompt to MongoDB in the
promptlake
collection.Returns the inserted ID for reference.
Last updated