-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from hemajv/oc-templates
Add openshift deployment files for react agent,streamlit
- Loading branch information
Showing
19 changed files
with
416 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
# Check if the config.yaml file exists and copy it | ||
if [ -f /opt/app-root/config/config.yaml ]; then | ||
cp /opt/app-root/config/config.yaml /opt/app-root/src/config.yaml | ||
fi | ||
|
||
# Start the agent server | ||
${POETRY_HOME}/bin/poetry run python react_agent/api.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Builder image to install dependencies from pyproject and lock file | ||
FROM quay.io/fedora/python-310:latest AS builder | ||
USER root | ||
ENV POETRY_HOME=/opt/poetry \ | ||
POETRY_VERSION=1.8.2 | ||
|
||
# Install Poetry | ||
RUN wget -P /tmp/ https://certs.corp.redhat.com/certs/Current-IT-Root-CAs.pem && \ | ||
curl -sSL https://install.python-poetry.org | python - && \ | ||
${POETRY_HOME}/bin/poetry config virtualenvs.in-project true && \ | ||
${POETRY_HOME}/bin/poetry config certificates.de-cop-nexus.cert /tmp/Current-IT-Root-CAs.pem | ||
|
||
# Copy the source code and install dependencies | ||
COPY . /opt/app-root/src/ | ||
WORKDIR /opt/app-root/src/ | ||
RUN ${POETRY_HOME}/bin/poetry install --only main | ||
|
||
# Final image | ||
FROM quay.io/fedora/python-310:latest | ||
LABEL maintainer="et@redhat.com" \ | ||
io.k8s.description="ReAct Agent" \ | ||
io.k8s.display-name="react_agent" \ | ||
io.openshift.tags="et" | ||
|
||
USER root | ||
|
||
# Update OS and install necessary packages | ||
RUN dnf -y update && \ | ||
dnf -y install java-17-openjdk tini wget && \ | ||
dnf -y autoremove && \ | ||
dnf -y clean all && \ | ||
wget -P /etc/pki/ca-trust/source/anchors https://certs.corp.redhat.com/certs/Current-IT-Root-CAs.pem && \ | ||
keytool -import -noprompt -keystore /etc/pki/java/cacerts -file /etc/pki/ca-trust/source/anchors/Current-IT-Root-CAs.pem -alias RH-IT-Root-CA -storepass changeit && \ | ||
update-ca-trust enable && \ | ||
update-ca-trust extract | ||
|
||
# Install Poetry in the final stage | ||
ENV POETRY_HOME=/opt/poetry \ | ||
PATH="/opt/poetry/bin:$PATH" | ||
RUN curl -sSL https://install.python-poetry.org | python - | ||
|
||
# Copy the source code and set up the environment | ||
COPY . /opt/app-root/src/ | ||
WORKDIR /opt/app-root/src/ | ||
RUN fix-permissions /opt/app-root/src -P && \ | ||
echo "" > /opt/app-root/bin/activate | ||
|
||
# Copy virtual environment from the builder stage | ||
COPY --from=builder --chown=1001:0 /opt/app-root/src/.venv /opt/app-root/src/.venv | ||
|
||
# Install streamlit directly | ||
RUN /opt/app-root/src/.venv/bin/pip install streamlit | ||
|
||
# Copy the starter.sh script and set permissions | ||
COPY agent-starter.sh /opt/app-root/src/ | ||
RUN chmod +x /opt/app-root/src/agent-starter.sh | ||
|
||
USER 1001 | ||
|
||
EXPOSE 2113 8501 | ||
|
||
# Ensure the virtual environment is included in the PATH | ||
ENV PATH="/opt/app-root/src/.venv/bin:$PATH" | ||
|
||
# Start the API server using agent-starter.sh | ||
CMD ["/opt/app-root/src/agent-starter.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# OpenShift Deployment Instructions | ||
|
||
To deploy the ReAct agent on an OpenShift cluster, you can follow the below instructions. | ||
|
||
## Prerequisites | ||
|
||
- OpenShift CLI (`oc`) installed and configured | ||
- (**Optional**) `kubectl` and `kustomize` installed and configured | ||
|
||
## Deployment Instructions | ||
|
||
### Step 1: Clone the Repository | ||
|
||
```sh | ||
git clone git@github.com:redhat-et/llm-agents.git | ||
cd llm-agents/react_agent | ||
``` | ||
|
||
### Step 2: Deploy the ReAct Agent API Server | ||
|
||
The agent API server is responsible for handling requests and interacting with the LLM. It exposes endpoints for different functionalities of the tool-based agent. The API server processes incoming requests, sends them to the appropriate tools or models, and returns the results to the clients. This deployment step sets up the necessary backend infrastructure for the ReAct agent. | ||
|
||
|
||
```sh | ||
oc apply -f openshift/deployment.yaml | ||
``` | ||
|
||
```sh | ||
oc apply -f openshift/service.yaml | ||
``` | ||
|
||
```sh | ||
oc apply -f openshift/route.yaml | ||
``` | ||
|
||
```sh | ||
oc apply -f openshift/configmap.yaml | ||
``` | ||
|
||
### Containerfile | ||
|
||
The Containerfiles used to build the deployment images can be found [here](https://github.com/redhat-et/llm-agents/react-agent-Containerfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: react-agent-config | ||
namespace: react-agent-test | ||
data: | ||
APP_HOST: "0.0.0.0" | ||
APP_PORT: "2113" | ||
OPENAI_URI: "<model-endpoint>" | ||
OPENAI_MODEL: "<model-name>" | ||
OPENAI_IGNORE_SSL: "True" | ||
MLFLOW_TRACKING_URI: "<mlflow-url>" | ||
MLFLOW_TRACKING_TOKEN: "<mlflow-token>" | ||
MLFLOW_EXPERIMENT_NAME: "ReAct Agent" | ||
config.yaml: | | ||
tools: | ||
- name: "constitution_tool" | ||
description: "Answers questions about the U.S. Constitution." | ||
url: "https://my.app/v1/completions" | ||
config: | ||
method: 'POST' | ||
headers: | ||
'Content-Type': 'application/json' | ||
'Authorization': 'Basic 12345' | ||
body: | ||
prompt: '{{prompt}}' | ||
responseParser: 'json.answer' | ||
responseMetadata: | ||
- name: 'sources' | ||
loc: 'json.sources' | ||
responseFormat: | ||
agent: '{{response}}' | ||
json: | ||
- "response" | ||
- "sources" | ||
examples: | ||
- "What is the definition of a citizen in the U.S. Constitution?" | ||
- "What article describes the power of the judiciary branch?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: react-agent-server | ||
namespace: react-agent-test | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: react-agent-server | ||
template: | ||
metadata: | ||
labels: | ||
app: react-agent-server | ||
spec: | ||
containers: | ||
- name: react-agent-server | ||
image: docker.io/hemaveeradhi/llm-agent:latest | ||
ports: | ||
- containerPort: 2113 | ||
envFrom: | ||
- configMapRef: | ||
name: react-agent-config | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /opt/app-root/config/config.yaml | ||
subPath: config.yaml | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: react-agent-config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: route.openshift.io/v1 | ||
kind: Route | ||
metadata: | ||
name: react-agent-route | ||
namespace: react-agent-test | ||
spec: | ||
to: | ||
kind: Service | ||
name: react-agent-server | ||
port: | ||
targetPort: react-agent-port | ||
tls: | ||
termination: edge | ||
wildcardPolicy: None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: react-agent-server | ||
namespace: react-agent-test | ||
spec: | ||
selector: | ||
app: react-agent-server | ||
ports: | ||
- name: react-agent-port | ||
protocol: TCP | ||
port: 2113 | ||
targetPort: 2113 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Builder image to install dependencies from pyproject and lock file | ||
FROM quay.io/fedora/python-310:latest AS builder | ||
USER root | ||
ENV POETRY_HOME=/opt/poetry \ | ||
POETRY_VERSION=1.8.2 | ||
|
||
# Install Poetry | ||
RUN wget -P /tmp/ https://certs.corp.redhat.com/certs/Current-IT-Root-CAs.pem && \ | ||
curl -sSL https://install.python-poetry.org | python - && \ | ||
${POETRY_HOME}/bin/poetry config virtualenvs.in-project true && \ | ||
${POETRY_HOME}/bin/poetry config certificates.de-cop-nexus.cert /tmp/Current-IT-Root-CAs.pem | ||
|
||
# Copy the source code and install dependencies | ||
COPY . /opt/app-root/src/ | ||
WORKDIR /opt/app-root/src/ | ||
RUN ${POETRY_HOME}/bin/poetry install --only main | ||
|
||
# Final image | ||
FROM quay.io/fedora/python-310:latest | ||
LABEL maintainer="et@redhat.com" \ | ||
io.k8s.description="Streamlit" \ | ||
io.k8s.display-name="Streamlit" \ | ||
io.openshift.tags="et" | ||
|
||
USER root | ||
|
||
# Update OS and install necessary packages | ||
RUN dnf -y update && \ | ||
dnf -y install java-17-openjdk tini wget && \ | ||
dnf -y autoremove && \ | ||
dnf -y clean all && \ | ||
wget -P /etc/pki/ca-trust/source/anchors https://certs.corp.redhat.com/certs/Current-IT-Root-CAs.pem && \ | ||
keytool -import -noprompt -keystore /etc/pki/java/cacerts -file /etc/pki/ca-trust/source/anchors/Current-IT-Root-CAs.pem -alias RH-IT-Root-CA -storepass changeit && \ | ||
update-ca-trust enable && \ | ||
update-ca-trust extract | ||
|
||
# Install Poetry in the final stage | ||
ENV POETRY_HOME=/opt/poetry \ | ||
PATH="/opt/poetry/bin:$PATH" | ||
RUN curl -sSL https://install.python-poetry.org | python - | ||
|
||
# Copy the source code and set up the environment | ||
COPY . /opt/app-root/src/ | ||
WORKDIR /opt/app-root/src/ | ||
RUN fix-permissions /opt/app-root/src -P && \ | ||
echo "" > /opt/app-root/bin/activate | ||
|
||
# Copy virtual environment from the builder stage | ||
COPY --from=builder --chown=1001:0 /opt/app-root/src/.venv /opt/app-root/src/.venv | ||
|
||
# Install streamlit directly | ||
RUN /opt/app-root/src/.venv/bin/pip install streamlit | ||
|
||
# Copy the starter.sh script and set permissions | ||
COPY streamlit-starter.sh /opt/app-root/src/ | ||
RUN chmod +x /opt/app-root/src/streamlit-starter.sh | ||
|
||
USER 1001 | ||
|
||
EXPOSE 8501 | ||
|
||
# Ensure the virtual environment is included in the PATH | ||
ENV PATH="/opt/app-root/src/.venv/bin:$PATH" | ||
|
||
# Start the Streamlit app using streamlit-starter.sh | ||
CMD ["/opt/app-root/src/streamlit-starter.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
# Check if the config.yaml file exists and copy it | ||
if [ -f /opt/app-root/config/config.yaml ]; then | ||
cp /opt/app-root/config/config.yaml /opt/app-root/src/config.yaml | ||
fi | ||
|
||
# Start the Streamlit app | ||
${POETRY_HOME}/bin/poetry run streamlit run streamlit/intro.py |
Oops, something went wrong.