aboutsummaryrefslogtreecommitdiff
path: root/llm.py
diff options
context:
space:
mode:
Diffstat (limited to 'llm.py')
-rwxr-xr-xllm.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/llm.py b/llm.py
index b21e81e..649f927 100755
--- a/llm.py
+++ b/llm.py
@@ -27,6 +27,8 @@ class AgentConfig:
workdir: Path
actions: List["Action"]
+ trustlevels: Dict[str, int]
+ trustlevel: int
client = OpenAI(
@@ -105,9 +107,16 @@ def query_agent(query: str, config: AgentConfig, state=()):
f = first(config.actions, lambda f: f.name == action_name)
if f is not None:
- result_json = f(action, config)
+ desc = f.formatter(action)
+ if (
+ config.trustlevels[action_name] > config.trustlevel
+ and not input(f"Perform {desc}? [y/N] ") == "y"
+ ):
+ result_json = {"status": "error", "reason": "Permission denied by user"}
+ else:
+ result_json = f(action, config)
result_jsons.append(result_json)
- replacements.append((m.start(), m.end(), action_name))
+ replacements.append((m.start(), m.end(), desc))
replaced_res = ""
i = 0
@@ -133,7 +142,18 @@ def main():
)
args = parser.parse_args()
- config = AgentConfig(workdir=args.workdir, actions=[ls, read, write, tldr, shell])
+ config = AgentConfig(
+ workdir=args.workdir,
+ actions=[ls, read, write, tldr, shell],
+ trustlevels={
+ "ls": 0,
+ "read": 0,
+ "tldr": 0,
+ "write": 1,
+ "shell": 2,
+ },
+ trustlevel=0,
+ )
state = (
{