Skip to content

Commit

Permalink
Support local models, non tool calling models, restricted commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Nov 17, 2024
1 parent 69c6302 commit 11fd63b
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 181 deletions.
27 changes: 24 additions & 3 deletions interpreter_1/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
from .profiles import Profile


def _parse_list_arg(value: str) -> list:
"""Parse a comma-separated or JSON-formatted string into a list"""
if not value:
return []

# Try parsing as JSON first
if value.startswith("["):
try:
import json

return json.loads(value)
except json.JSONDecodeError:
pass

# Fall back to comma-separated parsing
return [item.strip() for item in value.split(",") if item.strip()]


def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
"""Convert Profile attributes to argparse parameter definitions"""
return {
Expand Down Expand Up @@ -54,17 +72,20 @@ def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
"tools": {
"flags": ["--tools"],
"default": profile.tools,
"help": "Specify enabled tools (comma-separated)",
"help": "Specify enabled tools (comma-separated or JSON list)",
"type": _parse_list_arg,
},
"allowed_commands": {
"flags": ["--allowed-commands"],
"default": profile.allowed_commands,
"help": "Specify allowed commands",
"help": "Specify allowed commands (comma-separated or JSON list)",
"type": _parse_list_arg,
},
"allowed_paths": {
"flags": ["--allowed-paths"],
"default": profile.allowed_paths,
"help": "Specify allowed paths",
"help": "Specify allowed paths (comma-separated or JSON list)",
"type": _parse_list_arg,
},
"auto_run": {
"flags": ["--auto-run", "-y"],
Expand Down
Loading

0 comments on commit 11fd63b

Please sign in to comment.