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

change type of cli "embed -c" to be STR not FILE #263

Merged
merged 2 commits into from
Sep 12, 2023
Merged

Conversation

mhalle
Copy link
Contributor

@mhalle mhalle commented Sep 12, 2023

The type of the "content" argument was erroneously set to be FILE with a "type=click.Path(...)" argument, which content is a string.

The type of the "content" argument was erroneously set to be FILE with a "type=click.Path(...)" argument, which content is a string.
@simonw
Copy link
Owner

simonw commented Sep 12, 2023

Huh! I'm surprised that didn't result in any test failures. Here's the commit with the mistake: 77cf56e

@simonw simonw added the bug Something isn't working label Sep 12, 2023
@simonw
Copy link
Owner

simonw commented Sep 12, 2023

I think this is the test that exercised that:

def test_embed_output_format(tmpdir, format_, expected, scenario):
runner = CliRunner()
args = ["embed", "--format", format_, "-m", "embed-demo"]
input = None
if scenario == "argument":
args.extend(["-c", "hello world"])
elif scenario == "file":
path = tmpdir / "input.txt"
path.write_text("hello world", "utf-8")
args.extend(["-i", str(path)])
elif scenario == "stdin":
input = "hello world"
args.extend(["-i", "-"])
result = runner.invoke(cli, args, input=input)
assert result.exit_code == 0
assert result.output == expected

@simonw
Copy link
Owner

simonw commented Sep 12, 2023

I figured out why it was mostly working - it's because this just said it had to be a writable path, and most strings are also writable paths:

llm/llm/cli.py

Lines 1039 to 1044 in 5ba34db

@click.option(
"-c",
"--content",
help="Content to embed",
type=click.Path(file_okay=True, allow_dash=False, dir_okay=False, writable=True),
)

But if I do this:

touch no-write
chmod -w no-write
llm embed -c no-write -m ada-002

I get this error:

Usage: llm embed [OPTIONS] [COLLECTION] [ID]
Try 'llm embed --help' for help.

Error: Invalid value for '-c' / '--content': File 'no-write' is not writable.

Which is fixed by this PR.

@simonw simonw merged commit f07b291 into simonw:main Sep 12, 2023
10 checks passed
@simonw simonw added this to the 0.10 milestone Sep 12, 2023
simonw added a commit that referenced this pull request Sep 12, 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

Successfully merging this pull request may close these issues.

None yet

2 participants