Skip to content

Commit 57ea299

Browse files
authored
Merge pull request #30 from Prismadic/docker
🧲 feat(release): Docker image
2 parents 413ad10 + 3399b2d commit 57ea299

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

docker/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.11
2+
RUN python3.11 -m ensurepip
3+
RUN python3.11 -m pip install torch sentence-transformers pandas tqdm spacy pymilvus boto3 nats-py rich xxhash nkeys -U
4+
5+
WORKDIR /usr/src/app
6+
7+
# Install the required package
8+
RUN pip install --no-cache-dir llm-magnet -U
9+
10+
COPY ./scripts/ ./
11+
12+
ENTRYPOINT ["sh", "-c"]
13+
CMD ["python ./main.py"]

docker/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 🧲 docker
2+
3+
> [!NOTE]
4+
> Each runtime/worker has a `MAGNET_ROLE` environment variable.
5+
6+
Current role abstractions:
7+
8+
- "index"
9+
- Stream data from a `field`, encode using an embedding model, and upload to an index.

docker/docker-compose.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3.8'
2+
services:
3+
magnet-index:
4+
image: magnet
5+
environment:
6+
MILVUS_HOST: ""
7+
MILVUS_PORT: "19530"
8+
MILVUS_USER: ""
9+
MILVUS_PASSWORD: ""
10+
DIMENSION: ""
11+
MODEL: ""
12+
INDEX: ""
13+
efConstruction: ""
14+
M: ""
15+
RESONATOR_URI: ""
16+
CATEGORY: ""
17+
SESSION: ""
18+
STREAM: ""

docker/scripts/main.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os, asyncio
2+
from roles import index
3+
from magnet.utils.globals import _f
4+
magnet_role = os.getenv('MAGNET_ROLE')
5+
6+
def main():
7+
if magnet_role == 'index':
8+
asyncio.run(index.main())
9+
else:
10+
_f('fatal', 'No MAGNET_ROLE set! 😭')
11+
12+
if __name__ == "__main__":
13+
main()

docker/scripts/roles/index.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
from magnet.ize import memory
3+
from magnet.ic import field
4+
from magnet.utils.globals import _f
5+
6+
config = {
7+
"MILVUS_URI": os.getenv('MILVUS_HOST'),
8+
"MILVUS_PORT": int(os.getenv('MILVUS_PORT', 19530)),
9+
"MILVUS_USER": os.getenv('MILVUS_USER'),
10+
"MILVUS_PASSWORD": os.getenv('MILVUS_PASSWORD'),
11+
"DIMENSION": int(os.getenv('DIMENSION', 1024)),
12+
"MODEL": os.getenv('MODEL'),
13+
"INDEX": os.getenv('INDEX'),
14+
"INDEX_PARAMS": {
15+
'metric_type': 'COSINE',
16+
'index_type':'HNSW',
17+
'params': {
18+
"efConstruction": int(os.getenv('efConstruction', 40)),
19+
"M": int(os.getenv('M', 48))
20+
},
21+
}
22+
}
23+
24+
embedder = memory.Embedder(config)
25+
26+
async def handle_payload(payload, msg):
27+
await embedder.index(payload, msg, verbose=True)
28+
29+
async def main():
30+
try:
31+
reso = field.Resonator(os.getenv('RESONATOR_URI'))
32+
except Exception as e:
33+
_f('warn', e)
34+
main()
35+
await reso.on(category=os.getenv('CATEGORY'), session=os.getenv('SESSION'), stream=os.getenv('STREAM'))
36+
await reso.listen(cb=handle_payload)

0 commit comments

Comments
 (0)