diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 158948b..b6385f4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/README.md b/README.md index d602b2c..6ce4d77 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# 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. @@ -10,6 +10,7 @@ This repository is the template to automate the release of official Cheshire Cat ## 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: diff --git a/declarative_memory_profiling.py b/declarative_memory_profiling.py new file mode 100644 index 0000000..512ccdc --- /dev/null +++ b/declarative_memory_profiling.py @@ -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 + diff --git a/declarative_memory_profiling_image.png b/declarative_memory_profiling_image.png new file mode 100644 index 0000000..b4f18d9 Binary files /dev/null and b/declarative_memory_profiling_image.png differ diff --git a/my_plugin.py b/my_plugin.py deleted file mode 100644 index 2f5f034..0000000 --- a/my_plugin.py +++ /dev/null @@ -1,31 +0,0 @@ -from cat.mad_hatter.decorators import tool, hook, plugin -from pydantic import BaseModel -from datetime import datetime, date - -class MySettings(BaseModel): - required_int: int - optional_int: int = 69 - required_str: str - optional_str: str = "meow" - required_date: date - optional_date: date = 1679616000 - -@plugin -def settings_model(): - return MySettings - -@tool -def get_the_day(tool_input, cat): - """Get the day of the week. Input is always None.""" - - dt = datetime.now() - - return dt.strftime('%A') - -@hook -def before_cat_sends_message(message, cat): - - prompt = f'Rephrase the following sentence in a grumpy way: {message["content"]}' - message["content"] = cat.llm(prompt) - - return message diff --git a/plugin.json b/plugin.json index d213dea..64e7b96 100644 --- a/plugin.json +++ b/plugin.json @@ -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" }