Skip to content

Commit

Permalink
Fixed bug if LLM directory does not exist, closes #193
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 1, 2023
1 parent 5a9269a commit b30f689
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def read_prompt():
# Log to the database
if (logs_on() or log) and not no_log:
log_path = logs_db_path()
(log_path.parent).mkdir(parents=True, exist_ok=True)
db = sqlite_utils.Database(log_path)
migrate(db)
response.log_to_db(db)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ def _insert(id, text):
assert [record["id"] for record in records] == expected


def test_llm_prompt_creates_log_database(mocked_openai, tmpdir, monkeypatch):
user_path = tmpdir / "user"
monkeypatch.setenv("LLM_USER_PATH", str(user_path))
runner = CliRunner()
result = runner.invoke(
cli,
["three names \nfor a pet pelican", "--no-stream", "--key", "x"],
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.output == "Bob, Alice, Eve\n"
# Should have created user_path and put a logs.db in it
assert (user_path / "logs.db").exists()
assert sqlite_utils.Database(str(user_path / "logs.db"))["responses"].count == 1


@mock.patch.dict(os.environ, {"OPENAI_API_KEY": "X"})
@pytest.mark.parametrize("use_stdin", (True, False, "split"))
@pytest.mark.parametrize(
Expand Down

0 comments on commit b30f689

Please sign in to comment.