AnswerDotAI / AnswerDotAI/shell_sage

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

Open
#45 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
409
Forks
45
Avg merge
1m
Merged PRs (30d)
1

Description

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

```sh
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
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

```sh
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

```sh
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
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

```sh
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
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

```sh
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

```sh
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.

Contributor guide

Open the contributing guide

Research direction

Start in shell_sage/core.py around main and get_res, then inspect the provider initialization and the call paths shown in cosette/toolloop.py and claudette/core.py. Reproduce the commands with the listed dependency versions and compare normal and agent modes. Done means both OpenAI and Anthropic providers run without the reported TypeError or AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.