🐛 fix(base.py): add check for name in settings to prevent accessing non-existent keys

The code now checks if the name is present in the settings before accessing the corresponding keys in the get_custom_nodes function. This prevents accessing non-existent keys and avoids potential errors.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-06 17:27:55 -03:00
commit 116c600d95
4 changed files with 16 additions and 4 deletions

View file

@ -32,7 +32,10 @@ class AgentCreator(LangChainTypeCreator):
def get_signature(self, name: str) -> Optional[Dict]:
try:
if name in get_custom_nodes(self.type_name).keys():
if (
name in get_custom_nodes(self.type_name).keys()
and name in settings.agents
):
return get_custom_nodes(self.type_name)[name]
elif name in self.from_method_nodes:
return build_template_from_method(

View file

@ -45,7 +45,10 @@ class ChainCreator(LangChainTypeCreator):
def get_signature(self, name: str) -> Optional[Dict]:
try:
if name in get_custom_nodes(self.type_name).keys():
if (
name in get_custom_nodes(self.type_name).keys()
and name in settings.chains
):
return get_custom_nodes(self.type_name)[name]
elif name in self.from_method_nodes.keys():
return build_template_from_method(

View file

@ -32,7 +32,10 @@ class MemoryCreator(LangChainTypeCreator):
def get_signature(self, name: str) -> Optional[Dict]:
"""Get the signature of a memory."""
try:
if name in get_custom_nodes(self.type_name).keys():
if (
name in get_custom_nodes(self.type_name).keys()
and name in settings.memories
):
return get_custom_nodes(self.type_name)[name]
elif name in self.from_method_nodes:
return build_template_from_method(

View file

@ -40,7 +40,10 @@ class PromptCreator(LangChainTypeCreator):
def get_signature(self, name: str) -> Optional[Dict]:
try:
if name in get_custom_nodes(self.type_name).keys():
if (
name in get_custom_nodes(self.type_name).keys()
and name in settings.prompts
):
return get_custom_nodes(self.type_name)[name]
return build_template_from_class(name, self.type_to_loader_dict)
except ValueError as exc: