Skip to content

using agent with --provider openai throws TypeError: 'OpenAI' object is not callable #45

@YoungPhlo

Description

@YoungPhlo

To be fair I am getting the same error for openai and anthropic so maybe i'm doing something wrong here:

Reproducing the bug

Step 1

  • reproducing object not callable error
onyx@SRV-ONYX: ~ % echo reproducing a bug
reproducing a bug

onyx@SRV-ONYX: ~ % ls
total 188K
drwxr-x--- 18 onyx 4.0K Mar 25 16:15 ./
drwxr-xr-x  3 root 4.0K Mar 19 06:33 ../
-rw-------  1 onyx 2.1K Mar 21 01:07 .bash_history
-rw-r--r--  1 onyx  220 Mar 31  2024 .bash_logout
-rw-r--r--  1 onyx 3.7K Mar 19 23:30 .bashrc
drwx------ 13 onyx 4.0K Mar 20 01:26 .cache/
drwxrwxr-x  4 onyx 4.0K Mar 20 19:58 code/
drwx------ 15 onyx 4.0K Mar 21 03:22 .config/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Desktop/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Documents/
drwxr-xr-x  2 onyx 4.0K Mar 21 01:46 Downloads/
drwx------  2 onyx 4.0K Mar 21 01:39 .gnupg/
-rw-------  1 onyx   20 Mar 20 19:51 .lesshst
drwx------  4 onyx 4.0K Mar 19 06:36 .local/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Music/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Pictures/
-rw-r--r--  1 onyx  955 Mar 20 02:13 .profile
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Public/
drwxrwxr-x  3 onyx 4.0K Mar 25 13:28 .shell_sage/
drwx------  5 onyx 4.0K Mar 19 22:09 snap/
drwx------  2 onyx 4.0K Mar 20 23:45 .ssh/
-rw-r--r--  1 onyx    0 Mar 19 23:24 .sudo_as_admin_successful
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Templates/
-rw-rw-r--  1 onyx  633 Mar 25 13:24 .tmux.conf
drwxr-xr-x  3 onyx 4.0K Mar 21 00:16 Videos/
-rw-------  1 onyx  12K Mar 25 16:05 .viminfo
-rw-rw-r--  1 onyx  246 Mar 20 23:35 .vimrc
-rw-rw-r--  1 onyx  165 Mar 21 00:03 .wget-hsts
-rw-rw-r--  1 onyx  50K Mar 21 00:04 .zcompdump
-rw-rw-r--  1 onyx  291 Mar 20 19:27 .zprofile
-rw-------  1 onyx  12K Mar 25 16:15 .zsh_history
-rw-r--r--  1 onyx 2.2K Mar 25 16:05 .zshrc

onyx@SRV-ONYX: ~ % ssage --provider openai --model "deepseek/deepseek-chat:free" --base_url "https://openrouter.ai/api/v1" --api_key "sk-or-v1-" --log --mode agent "move me to the shell sage folder"
Traceback (most recent call last):
  File "/home/onyx/code/ai/text/generation/sage/venv/bin/ssage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/fastcore/script.py", line 125, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 326, in main
    res = get_res(sage, query, opts.provider, mode=mode, verbosity=verbosity)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 259, in get_res
    return conts[provider](sage.toolloop(q, trace_func=trace if verbosity else None))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/cosette/toolloop.py", line 23, in toolloop
    r = self(pr, **kwargs)
        ^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/cosette/core.py", line 235, in __call__
    res = self.c(self.h, sp=self.sp, stream=stream, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'OpenAI' object is not callable

Step 2

  • Making sure ssage works if not in agent mode
onyx@SRV-ONYX: ~ % ssage --provider openai --model "deepseek/deepseek-chat:free" --base_url "https://openrouter.ai/api/v1" --api_key "sk-or-v1-" --log "does this work without agent mode?"
Based on the error message from your previous attempt, it seems there's an issue with the OpenAI
provider configuration when using agent mode. Let's try without agent mode as you suggested:


 ssage --provider openai --model "deepseek/deepseek-chat:free" \
 --base_url "https://openrouter.ai/api/v1" \
 --api_key "sk-or-v1-" \
 "test query"


Important notes:

 1 Remove the --mode agent flag as this was causing the TypeError
 2 Verify your API key is still valid
 3 Check your Python package versions if the error persists

If you still encounter issues, consider:


 pip install --upgrade shell-sage cosette


Remember to keep your API key secure and never share it publicly. Consider using environment variables
for sensitive information.

Step 3

  • Testing if agent mode works with anthropic
onyx@SRV-ONYX: ~ % ls
total 188K
drwxr-x--- 18 onyx 4.0K Mar 25 16:20 ./
drwxr-xr-x  3 root 4.0K Mar 19 06:33 ../
-rw-------  1 onyx 2.1K Mar 21 01:07 .bash_history
-rw-r--r--  1 onyx  220 Mar 31  2024 .bash_logout
-rw-r--r--  1 onyx 3.7K Mar 19 23:30 .bashrc
drwx------ 13 onyx 4.0K Mar 20 01:26 .cache/
drwxrwxr-x  4 onyx 4.0K Mar 20 19:58 code/
drwx------ 15 onyx 4.0K Mar 21 03:22 .config/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Desktop/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Documents/
drwxr-xr-x  2 onyx 4.0K Mar 21 01:46 Downloads/
drwx------  2 onyx 4.0K Mar 21 01:39 .gnupg/
-rw-------  1 onyx   20 Mar 20 19:51 .lesshst
drwx------  4 onyx 4.0K Mar 19 06:36 .local/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Music/
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Pictures/
-rw-r--r--  1 onyx  955 Mar 20 02:13 .profile
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Public/
drwxrwxr-x  3 onyx 4.0K Mar 25 13:28 .shell_sage/
drwx------  5 onyx 4.0K Mar 19 22:09 snap/
drwx------  2 onyx 4.0K Mar 20 23:45 .ssh/
-rw-r--r--  1 onyx    0 Mar 19 23:24 .sudo_as_admin_successful
drwxr-xr-x  2 onyx 4.0K Mar 19 06:36 Templates/
-rw-rw-r--  1 onyx  633 Mar 25 13:24 .tmux.conf
drwxr-xr-x  3 onyx 4.0K Mar 21 00:16 Videos/
-rw-------  1 onyx  12K Mar 25 16:05 .viminfo
-rw-rw-r--  1 onyx  246 Mar 20 23:35 .vimrc
-rw-rw-r--  1 onyx  165 Mar 21 00:03 .wget-hsts
-rw-rw-r--  1 onyx  50K Mar 21 00:04 .zcompdump
-rw-rw-r--  1 onyx  291 Mar 20 19:27 .zprofile
-rw-------  1 onyx  12K Mar 25 16:20 .zsh_history
-rw-r--r--  1 onyx 2.2K Mar 25 16:05 .zshrc
onyx@SRV-ONYX: ~ % ssage --provider anthropic --model "claude-3-7-sonnet-latest" --api_key "sk-ant-api03-" --log --mode agent "move me to the shell sage folder"
Traceback (most recent call last):
  File "/home/onyx/code/ai/text/generation/sage/venv/bin/ssage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/fastcore/script.py", line 125, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 326, in main
    res = get_res(sage, query, opts.provider, mode=mode, verbosity=verbosity)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 259, in get_res
    return conts[provider](sage.toolloop(q, trace_func=trace if verbosity else None))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/claudette/toolloop.py", line 24, in toolloop
    r = self(pr, **kwargs)
        ^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/claudette/core.py", line 394, in __call__
    res = self.c(self.h, stream=stream, prefill=prefill, sp=self.sp, temp=temp, maxtok=maxtok,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'OpenAI' object is not callable

Step 4

  • Testing if anthropic works without agent mode
onyx@SRV-ONYX: ~ % ssage --provider anthropic --model "claude-3-7-sonnet-latest" --api_key "sk-ant-api03" --log "does anthropic work without agent mode?"
Traceback (most recent call last):
  File "/home/onyx/code/ai/text/generation/sage/venv/bin/ssage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/fastcore/script.py", line 125, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 326, in main
    res = get_res(sage, query, opts.provider, mode=mode, verbosity=verbosity)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/shell_sage/core.py", line 260, in get_res
    else: return conts[provider](sage(q))
                                 ^^^^^^^
  File "/home/onyx/code/ai/text/generation/sage/venv/lib/python3.12/site-packages/claudette/core.py", line 291, in __call__
    res = self.c.messages.create(model=self.model, messages=msgs, max_tokens=maxtok, system=sp, temperature=temp, **kwargs)
          ^^^^^^^^^^^^^^^
AttributeError: 'OpenAI' object has no attribute 'messages'
onyx@SRV-ONYX: ~ %

Step 5

  • Checking ssage version
onyx@SRV-ONYX: ~ % ssage --version
usage: ssage [-h] [--v] [--pid PID] [--skip_system] [--history_lines HISTORY_LINES] [--mode MODE]
             [--log] [--provider PROVIDER] [--model MODEL] [--base_url BASE_URL] [--api_key API_KEY]
             [--code_theme CODE_THEME] [--code_lexer CODE_LEXER] [--verbosity VERBOSITY]
             query [query ...]
ssage: error: the following arguments are required: query
onyx@SRV-ONYX: ~ % ssage --v
ssage 0.1.0
onyx@SRV-ONYX: ~ %

Step 6

  • Checking versions of dependencies
onyx@SRV-ONYX: ~ % which ssage
ssage: aliased to /home/onyx/code/ai/text/generation/sage/venv/bin/ssage
onyx@SRV-ONYX: ~ % code/ai/text/generation/sage/venv/bin/pip list
Package           Version
----------------- ---------
annotated-types   0.7.0
anthropic         0.49.0
anyio             4.9.0
apsw              3.49.1.0
apswutils         0.0.2
beautifulsoup4    4.13.3
certifi           2025.1.31
claudette         0.1.4
cosette           0.0.4
distro            1.9.0
fastcore          1.8.0
fastlite          0.1.2
h11               0.14.0
html2text         2024.2.26
httpcore          1.0.7
httpx             0.28.1
idna              3.10
jiter             0.9.0
llms-txt          0.0.4
markdown-it-py    3.0.0
mdurl             0.1.2
msglm             0.0.6
openai            1.68.2
packaging         24.2
pip               25.0.1
pydantic          2.10.6
pydantic_core     2.27.2
Pygments          2.19.1
rich              13.9.4
setuptools        77.0.1
shell_sage        0.1.0
sniffio           1.3.1
soupsieve         2.6
toolslm           0.1.0
tqdm              4.67.1
typing_extensions 4.12.2
wheel             0.45.1
onyx@SRV-ONYX: ~ %

i have been using openai as a provider this whole time so maybe the config file conflicts?
also interesting that the model brought up cosette, wonder if there's something there.
wish we could use Word Wrap here in issues so you dont have to horizontal scroll to see the full command.

anyway, thats what im seeing on my end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions