Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llm embed-multi gives a stacktrace if the pattern matches a directory #280

Closed
stoerr opened this issue Sep 15, 2023 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@stoerr
Copy link

stoerr commented Sep 15, 2023

If you run this, you'll get a nasty error message:

mkdir bla.js
llm embed-multi aem -d aem.db -m ada --files . '**/*.js'

It's probably better to check whether the matched things are actually readable files, and print a warning if not. Right now you get this. And that aborts the indexing, too, right? Not quite sure whether it's better to continue. Anyway: HUGE thanks for this marvelous stuff!

  File "/opt/homebrew/bin/llm", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/cli.py", line 1328, in embed_multi
    collection_obj.embed_multi(tuples(), store=store)
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/embeddings.py", line 165, in embed_multi
    self.embed_multi_with_metadata(
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/embeddings.py", line 189, in embed_multi_with_metadata
    batch = list(islice(iterator, batch_size))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/embeddings.py", line 166, in <genexpr>
    ((id, value, None) for id, value in entries), store=store
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/cli.py", line 1319, in tuples
    for row in rows:
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/click/_termui_impl.py", line 344, in generator
    for rv in self.iter:
  File "/opt/homebrew/Cellar/llm/0.10/libexec/lib/python3.11/site-packages/llm/cli.py", line 1275, in iterate_files
    content = path.read_text(encoding=encoding)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py", line 1058, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py", line 1044, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: 'bla.js'
@simonw simonw added the bug Something isn't working label Sep 15, 2023
@simonw
Copy link
Owner

simonw commented Sep 15, 2023

The right thing to do here might to silently skip directories, since the --files argument is only meant to work with files in the first place I don't think that would surprise anyone.

@stoerr
Copy link
Author

stoerr commented Sep 15, 2023

Right, I agree. There is not much point in logging a warning, also in the cases I had.

@simonw simonw added this to the 0.11 milestone Sep 15, 2023
simonw added a commit to ealvar3z/llm that referenced this issue Sep 19, 2023
simonw added a commit that referenced this issue Sep 19, 2023
* Fix issue with reading directories in `iterate_files()` (#280)
* Add directory checking logic in `iterate_files()` (#274)
* Added tests for #282, #274, #280

---------

Co-authored-by: Simon Willison <[email protected]>
@simonw simonw closed this as completed Sep 19, 2023
simonw added a commit that referenced this issue Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants