generated from cheshire-cat-ai/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic idea of the declarative memory profiling plugin
- Loading branch information
1 parent
cd303f3
commit 8750ddd
Showing
6 changed files
with
62 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |