Skip to content

Commit

Permalink
add user's name setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-corbellini committed Dec 11, 2023
1 parent 008f965 commit f6ff888
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
32 changes: 14 additions & 18 deletions fast_setup.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
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


@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"]

Expand All @@ -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"]

Expand All @@ -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
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tool.py
Original file line number Diff line number Diff line change
@@ -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()}"

0 comments on commit f6ff888

Please sign in to comment.