From f31df63d0362c2de26784afa58d40deb9c8ddcf7 Mon Sep 17 00:00:00 2001 From: cp-james-harbeck Date: Wed, 30 Aug 2023 17:40:35 -0400 Subject: [PATCH] Add setting option to dream metadata. --- lucidserver/endpoints/main.py | 9 +++++---- lucidserver/memories/main.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lucidserver/endpoints/main.py b/lucidserver/endpoints/main.py index 7986985..12a424a 100644 --- a/lucidserver/endpoints/main.py +++ b/lucidserver/endpoints/main.py @@ -71,6 +71,7 @@ def register_endpoints(app): "lucidity": fields.Int(), # Optional, scaler 1-5 "characters": fields.Str(), # Optional "emotions": fields.Str(), # Optional + "setting": fields.Str(), "id_token": fields.Str(required=True), } @@ -92,7 +93,7 @@ def register_endpoints(app): "query": fields.Str(required=True), } - # Placeholder for user's image style preferences + # Placeholder for user's image style preferences user_style_preferences = {} # Placeholder for user's image style preferences @@ -115,13 +116,13 @@ def create_dream_endpoint(args, userEmail): args["date"], args["entry"], userEmail, - None, # details, which you don't seem to use args.get("symbols"), args.get("lucidity"), args.get("characters"), - args.get("emotions") + args.get("emotions"), + args.get("setting") ) - + if dream_data is None or "id" not in dream_data: raise RuntimeError(f"Dream creation failed with data {args}") diff --git a/lucidserver/memories/main.py b/lucidserver/memories/main.py index c8171ba..17904d6 100644 --- a/lucidserver/memories/main.py +++ b/lucidserver/memories/main.py @@ -9,7 +9,7 @@ from lucidserver.actions import generate_dream_analysis, generate_dream_image, get_image_summary -def create_dream(title, date, entry, userEmail, details=None, symbols=None, lucidity=None, characters=None, emotions=None): +def create_dream(title, date, entry, userEmail, symbols=None, lucidity=None, characters=None, emotions=None, setting=None): try: # Step 1: Initial log to confirm function entry log(f"Entering create_dream function with title: {title}, date: {date}, entry: {entry}, userEmail: {userEmail}", type="debug") @@ -23,7 +23,8 @@ def create_dream(title, date, entry, userEmail, details=None, symbols=None, luci "symbols": symbols, "lucidity": lucidity, "characters": characters, - "emotions": emotions + "emotions": emotions, + "setting": setting } # Log the constructed metadata log(f"Constructed metadata: {metadata}", type="debug") @@ -98,7 +99,8 @@ def get_dream(dream_id): "symbols": dream["metadata"].get("symbols"), "lucidity": dream["metadata"].get("lucidity"), "characters": dream["metadata"].get("characters"), - "emotions": dream["metadata"].get("emotions") + "emotions": dream["metadata"].get("emotions"), + "setting": dream["metadata"].get("setting") } } @@ -138,7 +140,8 @@ def get_dreams(userEmail): "symbols": memory["metadata"].get("symbols"), "lucidity": memory["metadata"].get("lucidity"), "characters": memory["metadata"].get("characters"), - "emotions": memory["metadata"].get("emotions") # Newly added + "emotions": memory["metadata"].get("emotions"), + "setting": memory["metadata"].get("setting") } } # Optionally, extract analysis and image from metadata if present @@ -287,13 +290,15 @@ def update_dream_analysis_and_image(dream_id, analysis=None, image=None): def search_dreams(keyword, user_email): log(f"Searching dreams for keyword: {keyword} and user email: {user_email}.", type="info") search_results = search_memory("dreams", keyword, n_results=100) + + # Adding new fields like symbols, lucidity, characters, emotions to the metadata dictionary dreams = [ { "id": memory["id"], "document": memory["document"], "metadata": { key: memory["metadata"][key] - for key in ["date", "title", "entry", "analysis"] + for key in ["date", "title", "entry", "analysis", "symbols", "lucidity", "characters", "emotions", "setting"] if key in memory["metadata"] }, }