Comments (3)
Relevant code:
Lines 227 to 228 in 82c1923
Lines 109 to 118 in 82c1923
I'm also going to remove all use of os.path
and replace that with pathlib
.
from llm.
Cheated on that refactor:
llm --system "Refactor to use pathlib instead of os.path" < llm/cli.py
Here's the diff from what it produced:
diff --git a/llm/cli.py b/llm/cli.py
index 6562fa1..b5fc8dc 100644
--- a/llm/cli.py
+++ b/llm/cli.py
@@ -4,12 +4,11 @@ import datetime
import json
from .migrations import migrate
import openai
-import os
import pathlib
-from platformdirs import user_data_dir
import sqlite_utils
import sys
import warnings
+from platformdirs import user_data_dir
warnings.simplefilter("ignore", ResourceWarning)
@@ -110,10 +109,10 @@ def prompt(prompt, system, gpt4, model, no_stream, no_log, _continue, chat_id, k
def init_db():
"Ensure ~/.llm/log.db SQLite database exists"
path = get_log_db_path()
- if os.path.exists(path):
+ if path.exists():
return
# Ensure directory exists
- os.makedirs(os.path.dirname(path), exist_ok=True)
+ path.parent.mkdir(parents=True, exist_ok=True)
db = sqlite_utils.Database(path)
db.vacuum()
@@ -130,11 +129,7 @@ def path():
def keys_path():
- return os.environ.get("LLM_KEYS_PATH") or os.path.join(user_dir(), "keys.json")
-
-
-def user_dir():
- return user_data_dir("io.datasette.llm", "Datasette")
+ return os.environ.get("LLM_KEYS_PATH") or pathlib.Path(user_data_dir("io.datasette.llm", "Datasette")) / "keys.json"
@keys.command(name="set")
@@ -178,8 +173,8 @@ def set_(name, value):
)
@click.option("-t", "--truncate", is_flag=True, help="Truncate long strings in output")
def logs(count, path, truncate):
- path = path or get_log_db_path()
- if not os.path.exists(path):
+ path = pathlib.Path(path or get_log_db_path())
+ if not path.exists():
raise click.ClickException("No log database found at {}".format(path))
db = sqlite_utils.Database(path)
migrate(db)
@@ -225,14 +220,14 @@ def load_keys():
def get_log_db_path():
- return os.path.expanduser("~/.llm/log.db")
+ return pathlib.Path("~/.llm/log.db").expanduser()
def log(no_log, system, prompt, response, model, chat_id=None):
if no_log:
return
log_path = get_log_db_path()
- if not os.path.exists(log_path):
+ if not log_path.exists():
return
db = sqlite_utils.Database(log_path)
migrate(db)
@@ -252,7 +247,7 @@ def get_history(chat_id):
if chat_id is None:
return None, []
log_path = get_log_db_path()
- if not os.path.exists(log_path):
+ if not log_path.exists():
raise click.ClickException(
"This feature requires logging. Run `llm init-db` to create ~/.llm/log.db"
)
It shouldn't have removed import os
but other than that it looks good.
from llm.
This documentation is out-of-date:
Line 3 in 76dbbed
Lines 37 to 39 in 76dbbed
I think I need a llm logs path
command - except logs
isn't setup for sub-commands at the moment.
Options:
llm logs --path
- can work right now, but is inconsistent withllm keys path
llm logs path
- weird becausellm logs
is its own command right now. Maybe use another default command group?
from llm.
Related Issues (20)
- Support prefill HOT 8
- Mechanism for recording a different model ID from the one requested HOT 1
- How to handle fake messages that were not part of real coversations? HOT 3
- llm-llamafile is missing from plugin directory
- How to cut off the LLM in chat mode
- IndexError on Windows for llm chat HOT 1
- llm-groq does not support llama 3 HOT 2
- some plugins fail to install with "Connection refused" error HOT 1
- UI around chat history HOT 1
- [plugin] add IBM watsonx
- A rapidly convert Files to Prompts Using Rust
- Enhancement idea: implement a self help
- Asynchronous API support HOT 1
- Add API documentation on how to import and use this tool as a Python library
- Support for GPT-4o HOT 3
- Fix for latest mypy
- Rename the gpt-4-turbo aliases HOT 1
- All I ever get is "insufficient_quota" HOT 5
- llm 0.14: Can't run <<llm chat>> on Windows 11 HOT 1
- llm keys set openai
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llm.