Skip to content

chatbot-rag-app: updates to latest openai and uses uv to compile deps #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docker/docker-compose-elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ configs:

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
container_name: elasticsearch
ports:
- 9200:9200
Expand Down Expand Up @@ -98,7 +98,7 @@ services:
depends_on:
elasticsearch:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.0
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.1
container_name: elasticsearch_settings
restart: 'no'
# gen-ai assistants in kibana save state in a way that requires system
Expand All @@ -113,7 +113,7 @@ services:
'

kibana:
image: docker.elastic.co/kibana/kibana:9.0.0
image: docker.elastic.co/kibana/kibana:9.0.1
container_name: kibana
depends_on:
elasticsearch_settings:
Expand All @@ -137,7 +137,7 @@ services:
interval: 1s

otel-collector:
image: docker.elastic.co/elastic-agent/elastic-otel-collector:9.0.0
image: docker.elastic.co/elastic-agent/elastic-otel-collector:9.0.1
container_name: otel-collector
depends_on:
elasticsearch:
Expand Down
4 changes: 2 additions & 2 deletions example-apps/chatbot-rag-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM node:22-alpine AS build-step
FROM node:24-alpine AS build-step
WORKDIR /app
ENV PATH=/node_modules/.bin:$PATH
COPY frontend ./frontend
RUN cd frontend && yarn install
RUN cd frontend && REACT_APP_API_HOST=/api yarn build

# Use glibc-based image to get pre-compiled wheels for grpcio and tiktoken
FROM python:3.12-slim
FROM python:3.13-slim

WORKDIR /app
RUN mkdir -p ./frontend/build
Expand Down
31 changes: 8 additions & 23 deletions example-apps/chatbot-rag-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,18 @@ nvm use --lts
#### Configure your Python environment

Before we can run the app, we need a working Python environment with the
correct packages installed:
correct packages installed. This uses [uv][uv] for efficiency.

```bash
python3 -m venv .venv
source .venv/bin/activate
# Install dotenv which is a portable way to load environment variables.
pip install "python-dotenv[cli]"
pip install -r requirements.txt
uv venv --python 3.13
uv pip install -r requirements.txt
```

#### Create your Elasticsearch index

First, ingest the data into elasticsearch:
```bash
dotenv run -- flask create-index
uv run -q --env-file .env flask create-index
```

*Note*: This may take several minutes to complete
Expand All @@ -182,7 +179,7 @@ dotenv run -- flask create-index

Now, run the app, which listens on http://localhost:4000
```bash
dotenv run -- python api/app.py
uv run -q --env-file .env python api/app.py
```

## Advanced
Expand All @@ -196,7 +193,7 @@ This happens automatically, when using docker. If running with python directly,
prefix `python` with `opentelemetry-instrument` to enable OpenTelemetry.

```bash
dotenv run -- opentelemetry-instrument python api/app.py
uv run -q --env-file .env opentelemetry-instrument python api/app.py
```

[env.example](env.example) defaults to use an OpenTelemetry Collector,
Expand All @@ -219,20 +216,7 @@ To update package versions, recreate [requirements.txt](requirements.txt) and
reinstall like this. Once checked in, any commands above will use updates.

```bash
rm -rf .venv requirements.txt
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
# Install dev requirements for pip-compile and edot-bootstrap
pip install pip-tools elastic-opentelemetry
# Recreate requirements.txt
pip-compile
# Install main dependencies
pip install -r requirements.txt
# Add opentelemetry instrumentation for these dependencies
edot-bootstrap >> requirements.txt
# Install opentelemetry dependencies
pip install -r requirements.txt
docker compose run --rm recreate-requirements
```

### Elasticsearch index and chat_history index
Expand Down Expand Up @@ -265,3 +249,4 @@ docker compose up --build --force-recreate
[docker-compose]: ../../docker/docker-compose-elastic.yml
[edot-python]: https://github.com/elastic/elastic-otel-python
[k8s-manifest-elastic]: ../../k8s/k8s-manifest-elastic.yml
[uv]: https://docs.astral.sh/uv/getting-started/installation/
23 changes: 23 additions & 0 deletions example-apps/chatbot-rag-app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ services:
- "4000:4000"
extra_hosts: # send localhost traffic to the docker host, e.g. your laptop
- "localhost:host-gateway"

recreate-requirements:
image: python:3.13-slim
volumes:
- .:/src
working_dir: /build
profiles:
- util # don't start this as a service
command: >
bash -c "
pip install uv &&
uv venv &&
cp /src/requirements.in . &&
# First, install the application requirements into the venv
uv pip compile requirements.in -o requirements.txt &&
uv pip sync requirements.txt &&
# Next, detect and add instrumentation requirements
uv pip install elastic-opentelemetry &&
uv run edot-bootstrap >> requirements.in &&
# Finally, recreate a new pinned requirements.txt
uv pip compile requirements.in -o requirements.txt
cp requirements.txt /src/requirements.txt
"
Loading