From f6ff888f12ce1d67eec0069c1b8b8afd9feee90b Mon Sep 17 00:00:00 2001 From: Nicola Date: Mon, 11 Dec 2023 23:23:13 +0100 Subject: [PATCH] add user's name setting --- fast_setup.py | 32 ++++++++++++++------------------ settings.json | 3 ++- settings.py | 1 + tool.py | 9 +++++++++ 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 tool.py diff --git a/fast_setup.py b/fast_setup.py index beb62f9..c3dee03 100644 --- a/fast_setup.py +++ b/fast_setup.py @@ -1,22 +1,9 @@ -import json -import os.path - from cat.mad_hatter.decorators import tool, hook - - -def get_settings(): - if os.path.isfile("cat/plugins/cat_advanced_tools/settings.json"): - with open("cat/plugins/cat_advanced_tools/settings.json", "r") as json_file: - settings = json.load(json_file) - else: - with open("cat/plugins/cat_advanced_tools_main/settings.json", "r") as json_file: - settings = json.load(json_file) - return settings - +from cat.log import log @hook def agent_prompt_prefix(prefix, cat): - settings = get_settings() + settings = cat.mad_hatter.get_plugin().load_settings() prefix = settings["prompt_prefix"] return prefix @@ -24,7 +11,7 @@ def agent_prompt_prefix(prefix, cat): @hook def before_cat_recalls_episodic_memories(default_episodic_recall_config, cat): - settings = get_settings() + settings = cat.mad_hatter.get_plugin().load_settings() default_episodic_recall_config["k"] = settings["episodic_memory_k"] default_episodic_recall_config["threshold"] = settings["episodic_memory_threshold"] @@ -33,7 +20,7 @@ def before_cat_recalls_episodic_memories(default_episodic_recall_config, cat): @hook def before_cat_recalls_declarative_memories(default_declarative_recall_config, cat): - settings = get_settings() + settings = cat.mad_hatter.get_plugin().load_settings() default_declarative_recall_config["k"] = settings["declarative_memory_k"] default_declarative_recall_config["threshold"] = settings["declarative_memory_threshold"] @@ -42,8 +29,17 @@ def before_cat_recalls_declarative_memories(default_declarative_recall_config, c @hook def before_cat_recalls_procedural_memories(default_procedural_recall_config, cat): - settings = get_settings() + settings = cat.mad_hatter.get_plugin().load_settings() default_procedural_recall_config["k"] = settings["procedural_memory_k"] default_procedural_recall_config["threshold"] = settings["procedural_memory_threshold"] return default_procedural_recall_config + + +@hook +def before_agent_starts(agent_input, cat): + settings = cat.mad_hatter.get_plugin().load_settings() + user_name = settings["user_name"] + agent_input["chat_history"] = agent_input["chat_history"].replace("- Human:", f"- {user_name}:") + + return agent_input \ No newline at end of file diff --git a/settings.json b/settings.json index e0c11ef..068c058 100644 --- a/settings.json +++ b/settings.json @@ -5,5 +5,6 @@ "declarative_memory_k": 3, "declarative_memory_threshold": 0.7, "procedural_memory_k": 3, - "procedural_memory_threshold": 0 + "procedural_memory_threshold": 0.7, + "user_name": "Nicola" } \ No newline at end of file diff --git a/settings.py b/settings.py index a9926db..4112d7a 100644 --- a/settings.py +++ b/settings.py @@ -23,6 +23,7 @@ class MySettings(BaseModel): declarative_memory_threshold: float = 0.7 procedural_memory_k: int = 3 procedural_memory_threshold: float = 0.7 + user_name: str = "Human" @field_validator("episodic_memory_threshold") @classmethod diff --git a/tool.py b/tool.py new file mode 100644 index 0000000..4379be5 --- /dev/null +++ b/tool.py @@ -0,0 +1,9 @@ +from cat.mad_hatter.decorators import tool + + +@tool(return_direct=True) +def show_working_memory(none, cat): + """Useful to display the content of the working memory. Input is None.""" + + # print(cat.working_memory) + return f"{cat.working_memory.keys()}"