-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uploaded plugin: auto heal python code
- Loading branch information
1 parent
393b38a
commit cee2056
Showing
1 changed file
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import config, traceback | ||
from utils.install import * | ||
from utils.shared_utils import SharedUtil | ||
|
||
""" | ||
myHand AI plugin: auto heal python code | ||
* install missing packages | ||
* fixed broken codes | ||
User can define number of attempts of auto-healing by editing "max_consecutive_auto_heal" in config.py. | ||
The default value of config.max_consecutive_auto_heal is 3. | ||
""" | ||
|
||
def heal_python(function_args): | ||
# get the sql query statement | ||
fix = function_args.get("fix") # required | ||
missing = function_args.get("missing") # required | ||
if isinstance(missing, str): | ||
missing = eval(missing) | ||
|
||
try: | ||
if missing: | ||
for i in missing: | ||
installmodule(f"--upgrade {i}") | ||
exec(SharedUtil.fineTunePythonCode(fix), globals()) | ||
return "EXECUTED" | ||
except: | ||
return traceback.format_exc() | ||
|
||
functionSignature = { | ||
"name": "heal_python", | ||
"description": "Fix python code if both original code and traceback error are provided", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"fix": { | ||
"type": "string", | ||
"description": "Improved version of python code that resolved the traceback error. Return the original code instead only if traceback shows an import error.", | ||
}, | ||
"missing": { | ||
"type": "string", | ||
"description": """List of missing packages identified from import errors, e.g. "['datetime', 'requests']". Return "[]" if there is no import error in the traceback.""", | ||
}, | ||
}, | ||
"required": ["fix", "missing"], | ||
}, | ||
} | ||
|
||
# configs particular to this plugin | ||
# persistent | ||
persistentConfigs = ( | ||
("max_consecutive_auto_heal", 3), | ||
) | ||
config.setConfig(persistentConfigs) | ||
|
||
config.heal_python_signature = [functionSignature] | ||
config.chatGPTApiFunctionSignatures.append(functionSignature) | ||
config.chatGPTApiAvailableFunctions["heal_python"] = heal_python |