Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis and Image should be nested in metadata / not outside - maybe remove image all together from database #20

Open
dreaminglucid opened this issue Aug 27, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@dreaminglucid
Copy link
Owner

dreaminglucid commented Aug 27, 2023

I've modified the get_dream, get_dreams, and update_dream_analysis_and_image functions to nest the analysis and image fields inside the metadata dictionary. This will ensure that when dreams are fetched or updated, the analysis and image fields will be part of the metadata rather than being separate fields.

Here are the updated functions:

get_dream

def get_dream(dream_id):
    log(f"Initiating retrieval of dream with id {dream_id}.", type="info")
    dream = get_memory("dreams", dream_id)
    if dream is None:
        log(f"Dream with id {dream_id} not found.", type="error")
        return None
    
    metadata = dream.get('metadata', {})
    
    # Consolidate all metadata fields, including optional analysis and image
    metadata_fields = {
        "title": metadata.get("title", ""),
        "date": metadata.get("date", ""),
        "entry": metadata.get("entry", ""),
        "useremail": metadata.get("useremail", ""),
        "analysis": metadata.get("analysis", None),
        "image": metadata.get("image", None)
    }

    dream_data = {
        "id": dream["id"],
        "document": dream["document"],
        "metadata": metadata_fields
    }
    log(f"Successfully retrieved dream with id {dream_id}: {dream_data}", type="info")
    return dream_data

get_dreams

def get_dreams(userEmail):
    log("Fetching all dreams.", type="info")
    memories = get_memories("dreams", n_results=2222)
    dreams = []
    for memory in memories:
        if memory['metadata'].get('useremail') == userEmail:
            metadata_fields = {
                "title": memory["metadata"].get("title", ""),
                "date": memory["metadata"].get("date", ""),
                "entry": memory["metadata"].get("entry", ""),
                "useremail": memory["metadata"].get("useremail", ""),
                "analysis": memory["metadata"].get("analysis", None),
                "image": memory["metadata"].get("image", None)
            }
            
            dream_data = {
                "id": memory["id"],
                "document": memory["document"],
                "metadata": metadata_fields
            }
            dreams.append(dream_data)
    log(f"Debug: Retrieved dreams for userEmail {userEmail}: {dreams}", type="info")
    return dreams

update_dream_analysis_and_image

def update_dream_analysis_and_image(dream_id, analysis=None, image=None):
    log(f"Initiating update for dream analysis and image for dream id {dream_id}.", type="info")
    dream = get_dream(dream_id)
    if dream is None:
        log(f"Dream with id {dream_id} not found.", type="error")
        return None

    metadata = dream.get("metadata")
    if metadata is None:
        log(f"Metadata for dream with id {dream_id} not found.", type="error")
        return None

    if analysis:
        if isinstance(analysis, str):
            metadata["analysis"] = analysis
        else:
            log(f"Invalid analysis data for dream id {dream_id}.", type="error")
            return None

    if image:
        if isinstance(image, str):
            metadata["image"] = image
        else:
            log(f"Invalid image data for dream id {dream_id}.", type="error")
            return None

    try:
        update_memory("dreams", dream_id, metadata=metadata)
        log("Dream analysis and image updated successfully.", type="info")
        return dream
    except Exception as e:
        log(f"Failed to update dream id {dream_id}. Error: {str(e)}", type="error")
        return None

In these updated functions, the analysis and image fields are now part of the metadata dictionary. This should align with your requirement to have these fields nested within metadata.

@dreaminglucid dreaminglucid added the bug Something isn't working label Aug 27, 2023
@dreaminglucid dreaminglucid self-assigned this Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant