Skip to content

Commit bb39a8f

Browse files
committed
ver
1 parent dfc809e commit bb39a8f

8 files changed

+60
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ai_worker/version.py
2+
13
# lib stuff
24
CLBlast/
35
build-cuda/

ai_worker/main.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from gguf_loader.main import get_size
2727

2828
from .gguf_reader import GGUFReader
29+
from .version import VERSION
2930

3031
APP_NAME = "gputopia"
3132
DEFAULT_COORDINATOR = "wss://queenbee.gputopia.ai/worker"
@@ -47,6 +48,7 @@ class GpuInfo(BaseModel):
4748

4849

4950
class ConnectMessage(BaseModel):
51+
worker_version: str
5052
ln_url: str
5153
auth_key: str
5254
cpu_count: int
@@ -189,6 +191,7 @@ def _get_connect_info(self) -> ConnectMessage:
189191
disk_space = get_free_space_mb(".")
190192

191193
connect_msg = ConnectMessage(
194+
worker_version=VERSION,
192195
ln_url=self.conf.ln_url,
193196
auth_key=self.conf.auth_key,
194197
disk_space=int(disk_space),
@@ -301,11 +304,12 @@ async def free_up_space(self, size):
301304
pass
302305

303306

304-
def main():
307+
def main(argv=None):
305308
logging.basicConfig(level=logging.INFO,
306309
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
307310
stream=sys.stdout)
308311
parser = argparse.ArgumentParser()
312+
arg_names = []
309313
for name, field in Config.model_fields.items():
310314
description = field.description
311315
if field.default is not None and description is not None:
@@ -318,16 +322,23 @@ def main():
318322
)
319323
if field.annotation is bool:
320324
args.pop("type")
325+
arg_names.append(name)
321326
parser.add_argument(f"--{name}", **args)
327+
328+
parser.add_argument(f"--version", action="store_true")
322329

323-
args = parser.parse_args()
330+
args = parser.parse_args(args=argv)
324331
if args.debug:
325332
log.setLevel(logging.DEBUG)
326333

334+
if args.version:
335+
print(VERSION)
336+
exit(0)
337+
327338
if os.path.exists("gputopia-worker.ini"):
328339
logging.config.fileConfig("gputopia-worker.ini")
329340

330-
conf = Config(**{k: v for k, v in vars(args).items() if v is not None})
341+
conf = Config(**{k: getattr(args, k) for k in arg_names if getattr(args, k) is not None})
331342

332343
wm = WorkerMain(conf)
333344

ai_worker/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = '0.1.3'

build-bin.sh

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ python -mvenv "build-$gpu"
1616
# python is absurd putting these in different places
1717
. build-$gpu/bin/activate 2> /dev/null || . build-$gpu/scripts/activate
1818

19+
python build-version.py
20+
1921
pip uninstall -y llama-cpp-python
2022

2123
# windows/linux cache rm (poetry cache control is kinda blunt/broken)

build-version.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import toml
2+
3+
with open("pyproject.toml", "r") as file:
4+
pyproject_content = toml.load(file)
5+
version = pyproject_content["tool"]["poetry"]["version"]
6+
7+
with open("ai_worker/version.py", "w") as file:
8+
file.write(f"VERSION = '{version}'\n")

poetry.lock

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pytest-asyncio = "^0.21.1"
3232
pyinstaller = "^5.13.2"
3333
boto3 = "^1.28.43"
3434
ruff = "^0.0.288"
35+
toml = "^0.10.2"
3536

3637

3738
[tool.poetry.scripts]

tests/test_conn.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import asyncio
22
import json
3+
import re
34
import time
45
from threading import Thread
56
from typing import Any, Optional
67

78
import pytest
89
import websockets
9-
from ai_worker.main import WorkerMain, Config
10+
from ai_worker.main import WorkerMain, Config, main as worker_main
1011
from gguf_loader.main import download_gguf, main as loader_main, get_size
1112

1213
from pynvml.smi import nvidia_smi
@@ -113,3 +114,21 @@ def test_download_main(capsys):
113114
loader_main(["TheBloke/WizardLM-7B-uncensored-GGML:q4_K_M"])
114115
oe = capsys.readouterr().out
115116
assert "q4_K_M" in oe
117+
118+
119+
def test_version(capsys):
120+
try:
121+
worker_main(["--version"])
122+
except SystemExit:
123+
pass
124+
oe = capsys.readouterr().out
125+
re.match(r"\d+\.\d+\.\d+", oe)
126+
127+
128+
def test_main(capsys):
129+
try:
130+
worker_main(["--version"])
131+
except SystemExit:
132+
pass
133+
oe = capsys.readouterr().out
134+
re.match(r"\d+\.\d+\.\d+", oe)

0 commit comments

Comments
 (0)