chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=neuml/txtai-cpu
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Copy configuration
|
||||
COPY config.yml .
|
||||
|
||||
# Run local API instance to cache models in container
|
||||
RUN python -c "from txtai.api import API; API('config.yml', False)"
|
||||
|
||||
# Start server and listen on all interfaces
|
||||
ENV CONFIG "config.yml"
|
||||
ENTRYPOINT ["uvicorn", "--host", "0.0.0.0", "txtai.api:app"]
|
||||
@@ -0,0 +1,23 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=neuml/txtai-cpu
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Application script to copy into image
|
||||
ARG APP=api.py
|
||||
|
||||
# Install Lambda Runtime Interface Client and Mangum ASGI bindings
|
||||
RUN pip install awslambdaric mangum
|
||||
|
||||
# Copy configuration
|
||||
COPY config.yml .
|
||||
|
||||
# Run local API instance to cache models in container
|
||||
RUN python -c "from txtai.api import API; API('config.yml', False)"
|
||||
|
||||
# Copy application
|
||||
COPY $APP ./app.py
|
||||
|
||||
# Start runtime client using default application handler
|
||||
ENV CONFIG "config.yml"
|
||||
ENTRYPOINT ["python", "-m", "awslambdaric"]
|
||||
CMD ["app.handler"]
|
||||
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Lambda handler for a txtai API instance
|
||||
"""
|
||||
|
||||
from mangum import Mangum
|
||||
|
||||
from txtai.api import app, start
|
||||
|
||||
# pylint: disable=C0103
|
||||
# Create FastAPI application instance wrapped by Mangum
|
||||
handler = None
|
||||
if not handler:
|
||||
# Start application
|
||||
start()
|
||||
|
||||
# Create handler
|
||||
handler = Mangum(app, lifespan="off")
|
||||
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Lambda handler for txtai workflows
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from txtai.api import API
|
||||
|
||||
APP = None
|
||||
|
||||
|
||||
# pylint: disable=W0603,W0613
|
||||
def handler(event, context):
|
||||
"""
|
||||
Runs a workflow using input event parameters.
|
||||
|
||||
Args:
|
||||
event: input event
|
||||
context: input context
|
||||
|
||||
Returns:
|
||||
Workflow results
|
||||
"""
|
||||
|
||||
# Create (or get) global app instance
|
||||
global APP
|
||||
APP = APP if APP else API("config.yml")
|
||||
|
||||
# Get parameters from event body
|
||||
event = json.loads(event["body"])
|
||||
|
||||
# Run workflow and return results
|
||||
return {"statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": list(APP.workflow(event["name"], event["elements"]))}
|
||||
@@ -0,0 +1,38 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=python:3.10-slim
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Install GPU-enabled version of PyTorch if set
|
||||
ARG GPU
|
||||
|
||||
# Target CPU architecture
|
||||
ARG TARGETARCH
|
||||
|
||||
# Set Python version (i.e. 3, 3.10)
|
||||
ARG PYTHON_VERSION=3
|
||||
|
||||
# List of txtai components to install
|
||||
ARG COMPONENTS=[all]
|
||||
|
||||
# Locale environment variables
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
RUN \
|
||||
# Install required packages
|
||||
apt-get update && \
|
||||
apt-get -y --no-install-recommends install libgomp1 libportaudio2 libsndfile1 libegl1 libgles2 libvulkan1 git gcc g++ python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python3-pip && \
|
||||
rm -rf /var/lib/apt/lists && \
|
||||
\
|
||||
# Install txtai project and dependencies
|
||||
ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
|
||||
python -m pip install --no-cache-dir -U pip wheel setuptools && \
|
||||
if [ -z ${GPU} ]; then pip install --no-cache-dir torch==2.12.1+cpu torchvision==0.27.1+cpu -f https://download.pytorch.org/whl/torch -f https://download.pytorch.org/whl/torchvision; fi && \
|
||||
python -m pip install --no-cache-dir txtai${COMPONENTS} && \
|
||||
python -c "import sys, importlib.util as util; 1 if util.find_spec('nltk') else sys.exit(); import nltk; nltk.download(['punkt', 'punkt_tab', 'averaged_perceptron_tagger_eng'])" && \
|
||||
\
|
||||
# Cleanup build packages
|
||||
apt-get -y purge git gcc g++ python${PYTHON_VERSION}-dev && apt-get -y autoremove
|
||||
|
||||
# Set default working directory
|
||||
WORKDIR /app
|
||||
@@ -0,0 +1,20 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=python:3.10-slim
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Target CPU architecture
|
||||
ARG TARGETARCH
|
||||
|
||||
# Set Python version (i.e. 3, 3.10)
|
||||
ARG PYTHON_VERSION=3
|
||||
|
||||
# Locale environment variables
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
RUN \
|
||||
# Install minimal txtai project and dependencies
|
||||
MINIMAL=1 python -m pip install --no-cache-dir txtai_minimal
|
||||
|
||||
# Set default working directory
|
||||
WORKDIR /app
|
||||
@@ -0,0 +1,12 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=neuml/txtai-cpu
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Copy configuration
|
||||
COPY config.yml .
|
||||
|
||||
# Run local API instance to cache models in container
|
||||
RUN python -c "from txtai.api import API; API('config.yml', False)"
|
||||
|
||||
# Start application and wait for completion. Scheduled workflows can run indefinitely.
|
||||
ENTRYPOINT ["python", "-c", "from txtai.api import API; API('config.yml').wait()"]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Set base image
|
||||
ARG BASE_IMAGE=neuml/txtai-cpu
|
||||
FROM $BASE_IMAGE
|
||||
|
||||
# Copy configuration
|
||||
COPY config.yml .
|
||||
|
||||
# Run local API instance to cache models in container
|
||||
RUN python -c "from txtai.api import API; API('config.yml', False)"
|
||||
|
||||
# Run workflow. Requires two command line arguments: name of workflow and input elements
|
||||
ENTRYPOINT ["python", "-c", "import sys; from txtai.api import API\nfor _ in API('config.yml').workflow(sys.argv[1], sys.argv[2:]): pass"]
|
||||
CMD ["workflow"]
|
||||
Reference in New Issue
Block a user