aorwall / moatless-tools

MIT License
216 stars 20 forks source link

Token error with example notebook? #10

Closed JensRoland closed 2 months ago

JensRoland commented 2 months ago

Running the first cell of the example notebook, I get:

LocalProtocolError: Illegal header value b'Bearer '

I have added the OPENAI_API_KEY as an env var. Not sure what the problem is. I am using an M1 Mac so had to build the tree-sitter-python wheel and downgrade Numpy to get i to run, but this error doesn't seem related to that?

Partial error log:

File ~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/httpcore/_exceptions.py:14, in map_exceptions(map)
     [13](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/httpcore/_exceptions.py:13)     if isinstance(exc, from_exc):
---> [14](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/httpcore/_exceptions.py:14)         raise to_exc(exc) from exc
     [15](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/httpcore/_exceptions.py:15) raise

LocalProtocolError: Illegal header value b'Bearer '

The above exception was the direct cause of the following exception:

LocalProtocolError                        Traceback (most recent call last)
File ~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:952, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    [951](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:951) try:
--> [952](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:952)     response = self._client.send(
    [953](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:953)         request,
    [954](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:954)         stream=stream or self._should_stream_response_body(request=request),
    [955](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:955)         **kwargs,
    [956](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:956)     )
    [957](https://file+.vscode-resource.vscode-cdn.net/Users/jensr/Documents/Code/git-repositories/moatless-tools/notebooks/~/Documents/Code/git-repositories/moatless-tools/.venv/lib/python3.12/site-packages/openai/_base_client.py:957) except httpx.TimeoutException as err:
aorwall commented 2 months ago

The error indicates that no bearer token was provided. So it sounds like OPENAI_API_KEY is empty

JensRoland commented 2 months ago

That's what I thought but I couldn't work out why my env var wasn't available despite being set globally and in a .env file.

Turns out to be because notebook support in VS Code is a little quirky. Moving the .env file to the /notebooks folder solved it.