summaryrefslogtreecommitdiff
path: root/Biz/Que/Client.py
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-02-04 21:18:03 -0500
committerBen Sima <ben@bsima.me>2025-02-04 21:18:03 -0500
commit9f5b334eb6d0f64460f14d76255b096777a46332 (patch)
treedb357ca2a933456e1f35c17a1c85000fb5a64b9d /Biz/Que/Client.py
parent86ea51353c223cdc82cb8ebd013d58d70a7e646a (diff)
Update ollama, llm-ollama, openai-python, llm
I couldn't use llm-ollama because it required some package upgrades, so I started going down that rabbit hole and ended up 1) realizing that these packages are way out of date now, and 2) fiddling with overrides to get everything to work. I finally figured it out, the `postPatch` in ollama-python was throwing me off for like half a day. Anyway, one thing to note is that these are changing fast and I need to either move onto nixpkgs unstable for python stuff, or maintain my own builds of all of these. Not sure which is more appropriate right now. Oh and I had to fixup some logging stuff in Biz/Storybook.py because ruff started complaining about something, which is weird because I don't think the version changed? But it was easy enough to change.
Diffstat (limited to 'Biz/Que/Client.py')
-rwxr-xr-xBiz/Que/Client.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/Biz/Que/Client.py b/Biz/Que/Client.py
index 671b464..6248a79 100755
--- a/Biz/Que/Client.py
+++ b/Biz/Que/Client.py
@@ -22,10 +22,17 @@ RETRIES = 10
DELAY = 3
BACKOFF = 1
+LOGLEVEL = logging.ERROR
+LOG = logging.basicConfig(
+ format="%(asctime)s: %(levelname)s: %(message)s",
+ level=LOGLEVEL,
+ datefmt="%Y.%m.%d..%H.%M.%S",
+)
+
def auth(args: argparse.Namespace) -> str | None:
"""Return the auth key for the given ns from ~/.config/que.conf."""
- logging.debug("auth")
+ LOG.debug("auth")
namespace = args.target.split("/")[0]
if namespace == "pub":
return None
@@ -48,7 +55,7 @@ def autodecode(bytestring: bytes) -> typing.Any:
<https://docs.python.org/3/library/codecs.html#standard-encodings>
"""
- logging.debug("autodecode")
+ LOG.debug("autodecode")
codecs = ["utf-8", "ascii"]
for codec in codecs:
try:
@@ -75,8 +82,8 @@ def retry(
try:
return func(*args, **kwargs)
except exception as ex:
- logging.debug(ex)
- logging.debug("retrying...")
+ LOG.debug(ex)
+ LOG.debug("retrying...")
time.sleep(mdelay)
mtries -= 1
mdelay *= backoff
@@ -93,7 +100,7 @@ def retry(
@retry(http.client.RemoteDisconnected)
def send(args: argparse.Namespace) -> None:
"""Send a message to the que."""
- logging.debug("send")
+ LOG.debug("send")
key = auth(args)
data = args.infile
req = request.Request(f"{args.host}/{args.target}")
@@ -102,7 +109,7 @@ def send(args: argparse.Namespace) -> None:
if key:
req.add_header("Authorization", key)
if args.serve:
- logging.debug("serve")
+ LOG.debug("serve")
while not time.sleep(1):
request.urlopen(req, data=data, timeout=MAX_TIMEOUT)
else:
@@ -112,7 +119,7 @@ def send(args: argparse.Namespace) -> None:
def then(args: argparse.Namespace, msg: str) -> None:
"""Perform an action when passed `--then`."""
if args.then:
- logging.debug("then")
+ LOG.debug("then")
subprocess.run( # noqa: S602
args.then.format(msg=msg, que=args.target),
check=False,
@@ -131,7 +138,7 @@ def recv(args: argparse.Namespace) -> None:
Raises:
ValueError: if url is malformed
"""
- logging.debug("recv on: %s", args.target)
+ LOG.debug("recv on: %s", args.target)
if args.poll:
req = request.Request(f"{args.host}/{args.target}/stream")
else:
@@ -145,12 +152,12 @@ def recv(args: argparse.Namespace) -> None:
raise ValueError(msg)
with request.urlopen(req) as _req:
if args.poll:
- logging.debug("polling")
+ LOG.debug("polling")
while not time.sleep(1):
reply = _req.readline()
if reply:
msg = autodecode(reply)
- logging.debug("read")
+ LOG.debug("read")
sys.stdout.write(msg)
then(args, msg)
else:
@@ -223,11 +230,8 @@ def main() -> None:
sys.stdout.write("ok\n")
sys.exit()
if argv.debug:
- logging.basicConfig(
- format="%(asctime)s: %(levelname)s: %(message)s",
- level=logging.DEBUG,
- datefmt="%Y.%m.%d..%H.%M.%S",
- )
+ global LOGLEVEL # noqa: PLW0603
+ LOGLEVEL = logging.DEBUG
try:
if argv.infile:
send(argv)