💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add docker configuration for AWS Lambda, closes #228
davidmezzettif610745ab2ae
diff --git a/docker/aws/Dockerfile b/docker/aws/Dockerfilenew file mode 100644index 00000000..704f1f5e--- /dev/null+++ b/docker/aws/Dockerfile@@ -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')"++# Copy application+COPY $APP ./app.py++# Start runtime client using default application handler+ENV CONFIG "config.yml"+ENTRYPOINT ["python", "-m", "awslambdaric"]+CMD ["app.handler"]diff --git a/docker/aws/api.py b/docker/aws/api.pynew file mode 100644index 00000000..94c49a6b--- /dev/null+++ b/docker/aws/api.py@@ -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")diff --git a/docker/aws/workflow.py b/docker/aws/workflow.pynew file mode 100644index 00000000..d768bfd4--- /dev/null+++ b/docker/aws/workflow.py@@ -0,0 +1,27 @@+"""+Lambda handler for txtai workflows+"""++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")++ # Run workflow and return results+ return list(APP.workflow(event["name"], event["elements"]))