TheR1D / shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.
MIT License
8.84k stars 696 forks source link

The options --role and --show-role stopped working with error #469

Closed eiger8 closed 4 months ago

eiger8 commented 4 months ago

When I want to use or check the role i get this error:

shell_gpt version: 1.2.0 Expected result: no error, role is used, shown

Note: on the old version - 0.9.x it was working on the same machine.

sgpt --show-role code 2> err-role.txt stack trace:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/bin/sgpt:8 in <module>                                                                │
│                                                                                                  │
│   5 from sgpt import cli                                                                         │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(cli())                                                                          │
│   9                                                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ cli = <function entry_point at 0x110f08fe0>                                                  │ │
│ │  re = <module 're' from                                                                      │ │
│ │       '/usr/local/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib… │ │
│ │ sys = <module 'sys' (built-in)>                                                              │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/sgpt/app.py:261 in entry_point                           │
│                                                                                                  │
│   258                                                                                            │
│   259                                                                                            │
│   260 def entry_point() -> None:                                                                 │
│ ❱ 261 │   typer.run(main)                                                                        │
│   262                                                                                            │
│   263                                                                                            │
│   264 if __name__ == "__main__":                                                                 │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/main.py:1056 in run                                │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/main.py:328 in __call__                            │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/main.py:311 in __call__                            │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/click/core.py:1157 in __call__                           │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/core.py:716 in main                                │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/core.py:215 in _main                               │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/click/core.py:943 in make_context                        │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/click/core.py:1408 in parse_args                         │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/click/core.py:2400 in handle_parse_result                │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/click/core.py:2362 in process_value                      │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/typer/main.py:994 in wrapper                             │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/sgpt/utils.py:60 in wrapper                              │
│                                                                                                  │
│   57 │   def wrapper(cls: Any, value: str) -> None:                                              │
│   58 │   │   if not value:                                                                       │
│   59 │   │   │   return                                                                          │
│ ❱ 60 │   │   func(cls, value)                                                                    │
│   61 │   │   raise typer.Exit()                                                                  │
│   62 │                                                                                           │
│   63 │   return wrapper                                                                          │
│                                                                                                  │
│ ╭───────────────────── locals ──────────────────────╮                                            │
│ │   cls = <class 'sgpt.role.SystemRole'>            │                                            │
│ │  func = <function SystemRole.show at 0x10f3e89a0> │                                            │
│ │ value = 'code'                                    │                                            │
│ ╰───────────────────────────────────────────────────╯                                            │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/sgpt/role.py:102 in show                                 │
│                                                                                                  │
│    99 │   @classmethod                                                                           │
│   100 │   @option_callback                                                                       │
│   101 │   def show(cls, name: str) -> None:                                                      │
│ ❱ 102 │   │   typer.echo(cls.get(name).role)                                                     │
│   103 │                                                                                          │
│   104 │   @classmethod                                                                           │
│   105 │   def get_role_name(cls, initial_message: str) -> Optional[str]:                         │
│                                                                                                  │
│ ╭─────────────── locals ────────────────╮                                                        │
│ │  cls = <class 'sgpt.role.SystemRole'> │                                                        │
│ │ name = 'code'                         │                                                        │
│ ╰───────────────────────────────────────╯                                                        │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/sgpt/role.py:79 in get                                   │
│                                                                                                  │
│    76 │   │   file_path = cls.storage / f"{name}.json"                                           │
│    77 │   │   if not file_path.exists():                                                         │
│    78 │   │   │   raise BadArgumentUsage(f'Role "{name}" not found.')                            │
│ ❱  79 │   │   return cls(**json.loads(file_path.read_text()))                                    │
│    80 │                                                                                          │
│    81 │   @classmethod                                                                           │
│    82 │   @option_callback                                                                       │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │       cls = <class 'sgpt.role.SystemRole'>                              │                      │
│ │ file_path = PosixPath('/Users/oorys/.config/shell_gpt/roles/code.json') │                      │
│ │      name = 'code'                                                      │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: SystemRole.__init__() got an unexpected keyword argument 'expecting'

Here is my .sgptrc for ref:

CHAT_CACHE_PATH=/Users/myusr/.config/shell_gpt/chat_cache
CACHE_PATH=/Users/myusr/.config/shell_gpt/cache
CHAT_CACHE_LENGTH=100
CACHE_LENGTH=100
REQUEST_TIMEOUT=60
DEFAULT_MODEL=gpt-4
OPENAI_API_HOST=https://api.openai.com
DEFAULT_COLOR=magenta
ROLE_STORAGE_PATH=/Users/myusr/.config/shell_gpt/roles
SYSTEM_ROLES=false
DEFAULT_EXECUTE_SHELL_CMD=false
DISABLE_STREAMING=false
OPENAI_API_KEY=sk-SOME_HASH
CODE_THEME=default
OPENAI_FUNCTIONS_PATH=/Users/myusr/.config/shell_gpt/functions
SHOW_FUNCTIONS_OUTPUT=false
OPENAI_USE_FUNCTIONS=true
OPENAI_BASE_URL=https://api.openai.com/v1
eiger8 commented 4 months ago

sgpt --role bash_script_generator "generate basic shell script" 2> err-role.txt stack trace

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.11/site-packages/sgpt/app.py:199 in main                                  │
│                                                                                                  │
│   196 │   role_class = (                                                                         │
│   197 │   │   DefaultRoles.check_get(shell, describe_shell, code)                                │
│   198 │   │   if not role                                                                        │
│ ❱ 199 │   │   else SystemRole.get(role)                                                          │
│   200 │   )                                                                                      │
│   201 │                                                                                          │
│   202 │   function_schemas = (get_openai_schemas() or None) if functions else None               │
│                                                                                                  │
│ ╭────────────────────── locals ───────────────────────╮                                          │
│ │               cache = True                          │                                          │
│ │                chat = None                          │                                          │
│ │                code = False                         │                                          │
│ │         create_role = None                          │                                          │
│ │      describe_shell = False                         │                                          │
│ │              editor = False                         │                                          │
│ │           functions = True                          │                                          │
│ │   install_functions = None                          │                                          │
│ │ install_integration = None                          │                                          │
│ │         interaction = True                          │                                          │
│ │          list_chats = None                          │                                          │
│ │          list_roles = None                          │                                          │
│ │               model = 'gpt-4'                       │                                          │
│ │              prompt = 'generate basic shell script' │                                          │
│ │                repl = None                          │                                          │
│ │                role = 'bash_script_generator'       │                                          │
│ │               shell = False                         │                                          │
│ │           show_chat = None                          │                                          │
│ │           show_role = None                          │                                          │
│ │        stdin_passed = False                         │                                          │
│ │         temperature = 0.0                           │                                          │
│ │               top_p = 1.0                           │                                          │
│ │             version = None                          │                                          │
│ ╰─────────────────────────────────────────────────────╯                                          │
│                                                                                                  │
│ /usr/local/lib/python3.11/site-packages/sgpt/role.py:79 in get                                   │
│                                                                                                  │
│    76 │   │   file_path = cls.storage / f"{name}.json"                                           │
│    77 │   │   if not file_path.exists():                                                         │
│    78 │   │   │   raise BadArgumentUsage(f'Role "{name}" not found.')                            │
│ ❱  79 │   │   return cls(**json.loads(file_path.read_text()))                                    │
│    80 │                                                                                          │
│    81 │   @classmethod                                                                           │
│    82 │   @option_callback                                                                       │
│                                                                                                  │
│ ╭───────────────────────────────────────── locals ─────────────────────────────────────────╮     │
│ │       cls = <class 'sgpt.role.SystemRole'>                                               │     │
│ │ file_path = PosixPath('/Users/oorys/.config/shell_gpt/roles/bash_script_generator.json') │     │
│ │      name = 'bash_script_generator'                                                      │     │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────╯     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: SystemRole.__init__() got an unexpected keyword argument 'expecting'
TheR1D commented 4 months ago

Hi @eiger8, in one of our latest releases, there were significant changes to the roles logic. Old roles are not compatible with version 1.0.0 and above. You can read about the version 1.0.0 changes here. Given that I'm closing this issue, but feel free to reopen it.

Because of significant changes in roles, unfortunately previously created custom roles and chats will not work with ShellGPT v1.0.0 and you will need to re-create them using new version.