From 12d71e3ed915ffce3dd80001cd6498228baec78f Mon Sep 17 00:00:00 2001 From: DylanAlloy Date: Fri, 19 Jul 2024 16:54:32 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20fix(wip):=20docker=20milvus=20in?= =?UTF-8?q?it=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/conf.py | 2 +- magnet/base.py | 69 +++++++++++++++++++++++++------------------------- pyproject.toml | 2 +- setup.py | 2 +- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5a7509b..d8c6fd2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,7 @@ project = 'magnet' copyright = '2023, Prismadic, LLC' author = 'Prismadic, LLC.' -release = '0.3.15' +release = '0.3.16' # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/magnet/base.py b/magnet/base.py index 19ec362..af501c6 100644 --- a/magnet/base.py +++ b/magnet/base.py @@ -1,13 +1,22 @@ - -import nats, asyncio, docker, platform, os +import nats +import asyncio +import docker +import platform +import os +import importlib from magnet.utils.globals import _f from magnet.utils.data_classes import MagnetConfig, IndexConfig -milvus_server = default_server +milvus_server = None # Set to None initially os_name = platform.system() + if os_name == 'Darwin' and not os.getenv('DOCKER_ENV'): - from milvus import default_server + try: + milvus_module = importlib.import_module('milvus') + milvus_server = milvus_module.default_server # Initialize milvus_server only if imported + except ImportError: + _f("warn", "milvus module not found on macOS without DOCKER_ENV") auto_config = { "host": "127.0.0.1", @@ -28,10 +37,10 @@ "name": "test", "options": { 'metric_type': 'COSINE', - 'index_type':'HNSW', + 'index_type': 'HNSW', 'params': { - "efConstruction": 40 - , "M": 48 + "efConstruction": 40, + "M": 48 } } } @@ -68,7 +77,7 @@ async def align(self, backoff_strategy: str = 'eul'): attempt = 0 eulers_number = 2.71828 golden_ratio = 1.61803398875 - + while True: try: _server = f'{"nats://" if not self.config.credentials else "tls://"}{self.config.host}:4222' @@ -78,7 +87,7 @@ async def align(self, backoff_strategy: str = 'eul'): error_cb=self._cre_handler ) _f("success", f"šŸ§² connected to \nšŸ’Ž {_server} ") - + try: self.js = self.nc.jetstream(domain=self.config.domain) _f("info", f"šŸ§² initialized client ") @@ -156,11 +165,11 @@ def __init__(self): def start(self): try: nats_container = self.client.containers.run( - self.nats_image - , name="magnet-embedded-nats" - , detach=True - , ports={'4222/tcp': 4222} - , command="-js" + self.nats_image, + name="magnet-embedded-nats", + detach=True, + ports={'4222/tcp': 4222}, + command="-js" ) except Exception as e: return _f('fatal', e) @@ -169,18 +178,19 @@ def start(self): if container.id == nats_container.id: _f("wait", f"{container.name} container progressing with id {container.id}") nats_logs = container.logs().decode('utf-8').split('[INF]') - + if container.name == "magnet-embedded-nats" and container.status == "running": _f("info", f"nats logs") for log in nats_logs: _f("warn", f"{log}", luxe=True) - + if container.status == "exited": _f("fatal", f"{container.name} has exited") break try: - milvus_server.start() - _f("success", "milvus server started") + if milvus_server: # Only try to start if milvus_server is initialized + milvus_server.start() + _f("success", "milvus server started") except Exception as e: _f("fatal", f"milvus failure\n{e}") @@ -194,8 +204,9 @@ def stop(self): container.remove() _f("success", f"embedded nats removed") try: - milvus_server.stop() - _f("success", "embedded milvus server stopped") + if milvus_server: # Only try to stop if milvus_server is initialized + milvus_server.stop() + _f("success", "embedded milvus server stopped") except Exception as e: _f("warn", f"embedded milvus can't be stopped\n{e}") @@ -209,18 +220,8 @@ def cleanup(self): self.client.volumes.prune() _f("warn", "container engine pruned") try: - milvus_server.cleanup() - _f("success", "embedded cluster cleaned up") + if milvus_server: # Only try to cleanup if milvus_server is initialized + milvus_server.cleanup() + _f("success", "embedded cluster cleaned up") except Exception as e: - _f("fatal",f"error cleaning up milvus\n{e}") - -# class Electrode: -# def __init__(self, config: dict = None): -# self.config = config if config else _f('fatal', 'no config applied') -# async def auto(self): -# match self.config['JOB_TYPE']: -# case 'index': -# self.reso = field.Resonator(f"{self.config['NATS_USER']}:{self.config['NATS_PASSWORD']}@{self.config['NATS_URL']}") -# self.embedder = memory.Embedder(self.config, create=self.config["CREATE"]) -# await self.reso.on(category=self.config['NATS_CATEGORY'], session=self.config['NATS_SESSION'], stream=self.config['NATS_STREAM'], job=True) -# await self.reso.listen(cb=self.embedder.index, job_n=self.config['JOB_N']) \ No newline at end of file + _f("fatal", f"error cleaning up milvus\n{e}") diff --git a/pyproject.toml b/pyproject.toml index 9e95529..b7424bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "llm_magnet" -version = "0.3.15" +version = "0.3.16" description = "the small distributed language model toolkit. fine-tune state-of-the-art LLMs anywhere, rapidly." readme = "dynamic" diff --git a/setup.py b/setup.py index b6b0100..7c9a1cf 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='llm_magnet', - version='0.3.15', + version='0.3.16', description="the small distributed language model toolkit. fine-tune state-of-the-art LLMs anywhere, rapidly.", long_description=open('README.md').read(), long_description_content_type='text/markdown',