Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
Basic idea of ​​the declarative memory profiling plugin
  • Loading branch information
marcoserafini2 committed Mar 24, 2024
1 parent cd303f3 commit 8750ddd
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 56 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,10 @@ permissions:
env:
PLUGIN_JSON: "0.0.1"
TAG_EXISTS: false
PLUGIN_NAME: "my_plugin"
PLUGIN_NAME: "declarative_memory_profiling"

jobs:
# This will be deleted by setup.py
check:
runs-on: ubuntu-latest
outputs:
plugin_name: ${{ steps.init.outputs.plugin_name }}
steps:
- name: Get plugin name
id: init
run: |
echo "plugin_name=${{ env.PLUGIN_NAME }}" >> $GITHUB_OUTPUT
# This is the end of the removed section
release:
# This will be deleted by setup.py
needs: check
if: startsWith(needs.check.outputs.plugin_name, 'MY_PLUGIN') == false
# This is the end of the removed section
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# My plugin
# Declarative Memory Profiling

[![awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=awesome+plugin&color=383938&style=for-the-badge&logo=cheshire_cat_ai)](https://)
[![Awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=Awesome+plugin&color=000000&style=for-the-badge&logo=cheshire_cat_ai)](https://)
[![awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=awesome+plugin&color=F4F4F5&style=for-the-badge&logo=cheshire_cat_black)](https://)
[![awesome plugin](https://custom-icon-badges.demolab.com/static/v1?label=&message=awesome+plugin&color=383938&style=for-the-badge&logo=cheshire_cat_ai)](https://)

![alt text](declarative_memory_profiling_image.png)

Write here all the useful information about your plugin.

This repository is the template to automate the release of official Cheshire Cat AI plugins.

## Usage


1. Create a new repository clicking on the `Use this template` button.
2. Clone your new repo directly in the Cat's `plugins` folder.
3. Run the `setup.py` script:
Expand Down
52 changes: 52 additions & 0 deletions declarative_memory_profiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from cat.mad_hatter.decorators import tool, hook, plugin
from cat.log import log
from pydantic import BaseModel

class DeclarativeMemoryProfilingSettings(BaseModel):
#TODO customize message
no_profile_set_error: str = ""

@plugin
def settings_model():
return DeclarativeMemoryProfilingSettings

@hook
def before_rabbithole_insert_memory(doc, cat):

if "declarative_memory_profile" in cat.working_memory:
# insert the profile name metadata on doc
log.debug(f"Profile before insert memory {cat.working_memory['declarative_memory_profile']}")
doc.metadata["profile"] = cat.working_memory["declarative_memory_profile"]

return doc

@hook
def before_cat_recalls_declarative_memories(declarative_recall_config, cat):

if "declarative_memory_profile" in cat.working_memory:
# filter memories using profile metadata
log.debug(f"Profile before recall memories {cat.working_memory['declarative_memory_profile']}")
declarative_recall_config["metadata"] = {"profile": cat.working_memory["declarative_memory_profile"] }

return declarative_recall_config

@hook
def agent_fast_reply(fast_reply, cat):

if cat.working_memory["user_message_json"]["text"][:2] == "@p":
#Change active profile
profile_name = cat.working_memory["user_message_json"]["text"].split(" ")[1]
cat.working_memory["declarative_memory_profile"] = profile_name
fast_reply["output"] = f"Set profile to '{profile_name}'"

elif "declarative_memory_profile" not in cat.working_memory:

commands = """
No declarative memory profile selected. Commands available:
[@p profile_name] - Set the active profile to profile_name
[@c] - Print active profile (Not implemented yet)
"""
fast_reply["output"] = commands

return fast_reply

Binary file added declarative_memory_profiling_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 0 additions & 31 deletions my_plugin.py

This file was deleted.

8 changes: 4 additions & 4 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "My plugin",
"name": "Declarative Memory Profiling",
"version": "0.0.1",
"description": "Description of my_plugin.",
"description": "Description of declarative_memory_profiling.",
"author_name": "Me",
"author_url": "https://mywebsite.me",
"plugin_url": "https://github.com/my_name/my_plugin",
"plugin_url": "https://github.com/my_name/declarative_memory_profiling",
"tags": "cat, template, example",
"thumb": "https://raw.githubusercontent.com/my_repo_path/my_plugin.png"
"thumb": "https://raw.githubusercontent.com/my_repo_path/declarative_memory_profiling.png"
}

0 comments on commit 8750ddd

Please sign in to comment.