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.user_dir() should create it if it doesn't exist yet #275

Closed
simonw opened this issue Sep 13, 2023 · 2 comments
Closed

llm.user_dir() should create it if it doesn't exist yet #275

simonw opened this issue Sep 13, 2023 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Sep 13, 2023

Just fixed this bug:

The code in question did this:

 def register(name, aliases, lazy): 
     sentence_transformers_path = llm.user_dir() / "sentence-transformers.json" 
     if not sentence_transformers_path.exists(): 
         sentence_transformers_path.write_text("[]", "utf-8") 
     current = json.loads(sentence_transformers_path.read_text("utf-8")) 

It worked if llm.user_dir() already existed but failed otherwise.

Maybe llm.user_dir() should create the directory if it's missing before returning it?

@simonw simonw added the enhancement New feature or request label Sep 13, 2023
@simonw
Copy link
Owner Author

simonw commented Sep 13, 2023

Current implementation:

llm/llm/__init__.py

Lines 188 to 192 in 4711336

def user_dir():
llm_user_path = os.environ.get("LLM_USER_PATH")
if llm_user_path:
return pathlib.Path(llm_user_path)
return pathlib.Path(click.get_app_dir("io.datasette.llm"))

@simonw
Copy link
Owner Author

simonw commented Sep 13, 2023

I think it should create the directory. I think it's a reasonable API expectation for a plugin that the folder returned by llm.user_dir() should exist and not need to be created.

@simonw simonw changed the title Maybe llm.user_dir() should create it if it doesn't exist yet llm.user_dir() should create it if it doesn't exist yet Sep 13, 2023
@simonw simonw closed this as completed in 6c43948 Sep 13, 2023
@simonw simonw added this to the 0.11 milestone Sep 15, 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
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant