saulpw / aipl

Array-Inspired Pipeline Language
MIT License
119 stars 7 forks source link

`!llm` and `IndexError` #40

Closed dovinmu closed 1 year ago

dovinmu commented 1 year ago

running into this weird aipl-breaking bug, which I am not getting in my main aipl dev folder but is only happening when I clone the repo and install it in a new environment:

rowan@seshat test % python3 -V
Python 3.11.3
rowan@seshat test % git clone https://github.com/saulpw/aipl
<snip>
rowan@seshat test % python3 -m venv venv-aipl-test
rowan@seshat test % source venv-aipl-test/bin/activate
(venv-aipl-test) rowan@seshat test % python3 -m pip install ./aipl
<snip>
(venv-aipl-test) rowan@seshat test % aipl -i
> !format
hi!

<Table [1 _0] <LazyRow row={'_': '...(35 bytes)> -> format (line 1)
┏━━━━━┓
┃ _1  ┃
┡━━━━━┩
│ hi! │
└─────┘
> !llm
<Table [1 _1] <LazyRow row={'_': '...(38 bytes)> -> llm (line 1)
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/repl.py", line 46, in repl
    rich.print(inputs[-1])
  File "/opt/homebrew/lib/python3.11/site-packages/rich/__init__.py", line 74, in print
    return write_console.print(*objects, sep=sep, end=end)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/rich/console.py", line 1699, in print
    extend(render(renderable, render_options))
  File "/opt/homebrew/lib/python3.11/site-packages/rich/console.py", line 1311, in render
    render_iterable = renderable.__rich_console__(self, _options)  # type: ignore[union-attr]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/ops/debug.py", line 72, in _rich_table
    cell = str(cell)
           ^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/__init__.py", line 12, in __str__
    return f'AIPL Error (line {self.linenum} !{self.opname}): {self.exception}'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/__init__.py", line 25, in __str__
    return f'{self.args[1]}: {self.args[0]}'
              ~~~~~~~~~^^^
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/aipl", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/main.py", line 90, in main
    repl(aipl, inputs)
  File "/opt/homebrew/lib/python3.11/site-packages/aipl/repl.py", line 50, in repl
    traceback.print_exc()
    ^^^^^^^^^
NameError: name 'traceback' is not defined
(venv-aipl-test) rowan@seshat test % 

I get the same thing with those commands in a file, although I have to add a command after !llm that tries to do something with what it outputs.

dovinmu commented 1 year ago

ohooo, okay which aipl gives me /opt/homebrew/bin/aipl hmmm

dovinmu commented 1 year ago

wait a minute...

(venv-aipl-test) rowan@seshat test % whereis aipl
aipl: /Users/rowan/Documents/test/venv-aipl-test/bin/aipl
(venv-aipl-test) rowan@seshat test % which aipl
/opt/homebrew/bin/aipl
dovinmu commented 1 year ago

ah okay which is the one to go by

whereis searches for "possibly useful" files, while which only searches for executables

dovinmu commented 1 year ago

okay I removed the aipl file from my homebrew bin and now I'm running aipl from the local dir, which is on the latest develop version of saulpw/aipl. Still getting this error.

dovinmu commented 1 year ago

Ah this is being caused by this:

    if 'OPENAI_API_KEY' not in os.environ or 'OPENAI_API_ORG' not in os.environ:
        raise AIPLException('''OPENAI_API_KEY and OPENAI_API_ORG envvars must be set for !llm''')

I forgot to source my envvars, but somehow wasn't getting this nice error message