From 75ef14d9d33996fd77ff5695b178b3550d0dd082 Mon Sep 17 00:00:00 2001 From: endolith Date: Mon, 20 Jan 2025 12:23:02 -0500 Subject: [PATCH 1/2] Add docstrings to explain skills system to OI OI tries to call help(computer.skills.import_skills) or help(computer.skills.list), for instance and there is no documentation. --- interpreter/core/computer/skills/skills.py | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/interpreter/core/computer/skills/skills.py b/interpreter/core/computer/skills/skills.py index 0bc6bfcc91..dbca194244 100644 --- a/interpreter/core/computer/skills/skills.py +++ b/interpreter/core/computer/skills/skills.py @@ -21,12 +21,32 @@ class Skills: + """ + Manages access to pre-imported automation skills. + + Available methods: + - list(): Returns names of available skills + - search(query): Lists available skills (currently same as list()) + + Usage: + To use a skill, call it directly as a function: + example_skill() + + To create a new skill: + computer.skills.new_skill.create() + """ def __init__(self, computer): self.computer = computer self.path = str(Path(oi_dir) / "skills") self.new_skill = NewSkill(self) def list(self): + """ + Lists all available skills. Skills are already imported and can be called directly. + + Returns: + list[str]: Names of available skills with () to indicate they're callable + """ return [ file.replace(".py", "()") for file in os.listdir(self.path) @@ -34,13 +54,21 @@ def list(self): ] def run(self, skill): + """ + DEPRECATED: Do not use this method. + Skills are already imported - call them directly as functions instead. + """ print( "To run a skill, run its name as a function name (it is already imported)." ) def search(self, query): """ - This just lists all for now. + Lists available skills (currently same as list()). + Skills are already imported and can be called directly. + + Returns: + list[str]: Names of available skills with () to indicate they're callable """ return [ file.replace(".py", "()") @@ -49,6 +77,13 @@ def search(self, query): ] def import_skills(self): + """ + [INTERNAL METHOD - NOT FOR Assistant USE] + System initialization method that imports all Python files from the skills directory. + + This method is called automatically during system setup to load available skills. + Assistant should use list(), search(), or call skills directly instead of this method. + """ previous_save_skills_setting = self.computer.save_skills self.computer.save_skills = False From 119198cdb0925d87d940c3e27d667f0ec819e673 Mon Sep 17 00:00:00 2001 From: endolith Date: Mon, 27 Jan 2025 23:35:53 -0500 Subject: [PATCH 2/2] Clarify skills messages in list() and search() Update error messages to better explain how to enable skills, and return empty list if skills are disabled. When OI tries to list skills, it shows them, but then it can't actually call them and it gets very confused. --- interpreter/core/computer/skills/skills.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/interpreter/core/computer/skills/skills.py b/interpreter/core/computer/skills/skills.py index dbca194244..64b9d70290 100644 --- a/interpreter/core/computer/skills/skills.py +++ b/interpreter/core/computer/skills/skills.py @@ -24,6 +24,9 @@ class Skills: """ Manages access to pre-imported automation skills. + Note: Skills system must be enabled via profile (like 'the01') or by creating + OpenInterpreter with import_skills=True. + Available methods: - list(): Returns names of available skills - search(query): Lists available skills (currently same as list()) @@ -47,6 +50,15 @@ def list(self): Returns: list[str]: Names of available skills with () to indicate they're callable """ + if not self.computer.import_skills: + print("Skills are disabled. To enable skills, either use a profile like 'the01' that supports skills, " + "or create an instance of OpenInterpreter with import_skills=True") + return [] + + if not self.computer._has_imported_skills: + print("Skills have not been imported yet.") + return [] + return [ file.replace(".py", "()") for file in os.listdir(self.path) @@ -70,6 +82,15 @@ def search(self, query): Returns: list[str]: Names of available skills with () to indicate they're callable """ + if not self.computer.import_skills: + print("Skills are disabled. To enable skills, either use a profile like 'the01' that supports skills, " + "or create an instance of OpenInterpreter with import_skills=True") + return [] + + if not self.computer._has_imported_skills: + print("Skills have not been imported yet.") + return [] + return [ file.replace(".py", "()") for file in os.listdir(self.path) @@ -84,6 +105,9 @@ def import_skills(self): This method is called automatically during system setup to load available skills. Assistant should use list(), search(), or call skills directly instead of this method. """ + if not self.computer.import_skills: + return + previous_save_skills_setting = self.computer.save_skills self.computer.save_skills = False