Skip to content

Commit

Permalink
Merge branch 'development' into feat/support-otlp-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Feb 3, 2025
2 parents 9a6b7bb + 04e303b commit 54db1e9
Show file tree
Hide file tree
Showing 24 changed files with 1,456 additions and 497 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
gitlab-dev-deploy:
if: ${{ github.event.registry_package.package_version.container_metadata.tag.name == 'development' }}
uses: epam/ai-dial-ci/.github/workflows/deploy-development.yml@1.10.0
uses: epam/ai-dial-ci/.github/workflows/deploy-development.yml@1.11.1
with:
gitlab-project-id: '1830'
gitlab-project-ref: 'master'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ on:

jobs:
pr-title-check:
uses: epam/ai-dial-ci/.github/workflows/pr-title-check.yml@1.10.0
uses: epam/ai-dial-ci/.github/workflows/pr-title-check.yml@1.11.1
secrets:
ACTIONS_BOT_TOKEN: ${{ secrets.ACTIONS_BOT_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
run_tests:
uses: epam/ai-dial-ci/.github/workflows/python_docker_pr.yml@1.10.0
uses: epam/ai-dial-ci/.github/workflows/python_docker_pr.yml@1.11.1
secrets: inherit
with:
python_version: "3.10"
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
release:
uses: epam/ai-dial-ci/.github/workflows/python_docker_release.yml@1.10.0
uses: epam/ai-dial-ci/.github/workflows/python_docker_release.yml@1.11.1
secrets: inherit
with:
python_version: "3.10"
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ ENV PYTHONUNBUFFERED 1

RUN apt-get update && \
apt-get install -y python3 \
python3-venv \
python3-dev \
python3-pip && \
python3-venv \
python3-dev \
python3-pip && \
pip install "poetry==1.6.1" && \
python3 -m venv /opt/venv

Expand Down Expand Up @@ -49,6 +49,9 @@ ENV PATH="/opt/venv/bin:$PATH"

USER appuser

HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=6 \
CMD wget --no-verbose --tries=1 --spider http://localhost:5000/health || exit 1

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
EXPOSE 5000
CMD ["uvicorn", "aidial_analytics_realtime.app:app", "--host", "0.0.0.0", "--port", "5000"]
48 changes: 28 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
PORT = 5001
IMAGE_NAME = ai-dial-analytics-realtime
PORT ?= 5001
IMAGE_NAME ?= ai-dial-analytics-realtime
VENV_DIR ?= .venv
POETRY ?= $(VENV_DIR)/bin/poetry
POETRY_VERSION ?= 1.6.1
ARGS =


.PHONY: all build serve docker_build docker_serve lint format test test_all docs clean help
.PHONY: all init_env build serve docker_build docker_serve lint format test test_all docs clean help


all: build


build:
poetry build
init_env:
python -m venv $(VENV_DIR)
$(VENV_DIR)/bin/pip install poetry==$(POETRY_VERSION) --quiet


serve:
poetry install --only main
poetry run uvicorn aidial_analytics_realtime.app:app --port=$(PORT) --env-file .env
build: init_env
$(POETRY) build


serve: init_env
$(POETRY) install --only main
$(POETRY) run uvicorn aidial_analytics_realtime.app:app --reload --port=$(PORT) --env-file .env


docker_build:
Expand All @@ -26,24 +34,24 @@ docker_serve: docker_build
docker run --platform linux/amd64 --env-file ./.env --rm -p $(PORT):5000 $(IMAGE_NAME):dev


lint:
poetry install --only nox
poetry run nox -s lint
lint: init_env
$(POETRY) install --only nox
$(POETRY) run nox -s lint


format:
poetry install --only nox
poetry run nox -s format
format: init_env
$(POETRY) install --only nox
$(POETRY) run nox -s format


test:
poetry install --only nox
poetry run -- nox -s tests -- -m "not with_external" $(ARGS)
test: init_env
$(POETRY) install --only nox
$(POETRY) run -- nox -s tests -- -m "not with_external" $(ARGS)


test_all:
poetry install --only nox
poetry run -- nox -s tests -- $(ARGS)
test_all: init_env
$(POETRY) install --only nox
$(POETRY) run -- nox -s tests -- $(ARGS)


docs:
Expand Down
79 changes: 54 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,64 @@ Realtime analytics server for [AI DIAL](https://epam-rail.com). The service cons

Refer to [Documentation](https://github.com/epam/ai-dial/blob/main/docs/tutorials/realtime-analytics.md) to learn how to configure AI DAL Core and other necessary components.

# Usage
## Usage

Check the [AI DIAL Core](https://github.com/epam/ai-dial-core) documentation to configure the way to send the logs to the instance of the realtime analytics server.

The realtime analytics server analyzes the logs stream in the realtime and writes the metric `analytics` to the InfluxDB with the following data:
The realtime analytics server analyzes the logs stream provided by [Vector](https://vector.dev/docs/reference/configuration/sinks/http/) in the realtime and writes metrics to the InfluxDB.

The logs for `/chat/completions` and `/embeddings` endpoints are saved to the `analytics` measurement with the following tags and fields:

|Tag|Description|
|---|---|
|model| The model name for the completion request. |
|deployment| The deployment name of the model or application for the completion request. |
|project_id| The project ID for the completion request |
|language| The language of the conversation detected by the messages content. |
|topic| The topic of the conversation detected by the messages content. |
|model| The model name for the request. |
|deployment| The deployment name of the model or application for the request. |
|parent_deployment| The deployment name of the model or application that called the current deployment. |
|execution_path| A list of deployment calls representing the call stack of the request. E.g. `['app1', 'app2', 'model1']` means `app1` called `app2` and `app2` called `model1`. The last element of the list equals to the `deployment` tag. The penultimate element of the list *(when present)* equals to the `parent_deployment` tag. |
|trace_id| OpenTelemetry trace ID. |
|core_span_id| OpenTelemetry span ID generated by DIAL Core. |
|core_parent_span_id| OpenTelemetry span ID generated by DIAL Core that called the span `core_span_id`. |
|project_id| The project ID for the request. |
|language| The language detected for the content of the request. |
|upstream| The upstream endpoint used by the DIAL model. |
|topic| The topic detected for the content of the request. |
|title| The title of the person making the request. |
|response_id| Unique ID of this response. |
|response_id| Unique ID of the response. |

|Field|Description|
|---|---|
|user_hash| The unique hash for the user. |
|price| The calculated price of the request. |
|number_request_messages| The total number of messages in history for this request. |
|chat_id| The unique ID of this convestation. |
|prompt_tokens| The number of tokens in the prompt including conversation history and the current message |
|completion_tokens| The number of completion tokens generated for this request |
|user_hash| The unique hash identifying the user. |
|deployment_price| The cost of this specific request, excluding the cost of any requests it directly or indirectly initiated. |
|price| The total cost of the request, including the cost of this request and all related requests it directly or indirectly triggered. |
|number_request_messages| The total number of messages in the request. For chat completion requests it's number of messages in the chat history. For embedding requests it's number of inputs. |
|chat_id| The unique identifier for the conversation that this request is part of. |
|prompt_tokens| The number of tokens in the request. |
|completion_tokens| The number of tokens in the response. |

The logs for the `/rate` endpoint are saved to the `rate_analytics` measurement:

# Configuration
|Tag|Description|
|---|---|
|deployment| The deployment name of the model or application for the request. |
|project_id| The project ID for the request. |
|title| The title of the person making the request. |
|response_id| Unique ID of the response. |
|user_hash| The unique hash identifying the user. |
|chat_id| The unique identifier for the conversation that this request is part of. |

|Field|Description|
|---|---|
|dislike_count| 1 for a thumbs up request, otherwise 0. |
|like_count| 1 for a thumbs down request, otherwise 0. |

## Configuration

Copy `.env.example` to `.env` and customize it for your environment.

### Connection to the InfluxDB

You need to specify the connection options to the InfluxDB instance using the environment variables:

|Variable|Description|
|---|---|
|INFLUX_URL|Url to the InfluxDB to write the analytics data |
Expand All @@ -46,6 +72,7 @@ You need to specify the connection options to the InfluxDB instance using the en
You can follow the [InfluxDB documentation](https://docs.influxdata.com/influxdb/v2/get-started/) to setup InfluxDB locally and acquire the required configuration parameters.

### Other configuration

Also, following environment valuables can be used to configure the service behavior:

|Variable|Default|Description|
Expand All @@ -56,6 +83,7 @@ Also, following environment valuables can be used to configure the service behav
|LOG_LEVEL|INFO|Log level. Use DEBUG for dev purposes and INFO in prod|

Example of the MODEL_RATES configuration:

```json
{
"gpt-4": {
Expand Down Expand Up @@ -85,29 +113,28 @@ Example of the MODEL_RATES configuration:
}
```


______
# Developer environment
## Developer environment

This project uses [Python>=3.11](https://www.python.org/downloads/) and [Poetry>=1.6.1](https://python-poetry.org/) as a dependency manager.
Check out Poetry's [documentation on how to install it](https://python-poetry.org/docs/#installation) on your system before proceeding.

To install requirements:

```
```sh
poetry install
```

This will install all requirements for running the package, linting, formatting and tests.

# Build
## Build

To build the wheel packages run:

```sh
make build
```

# Run
## Run

To run the development server locally run:

Expand All @@ -117,21 +144,23 @@ make serve

The server will be running as http://localhost:5001

# Docker
## Docker

To build the docker image run:

```sh
make docker_build
```

To run the server locally from the docker image run:

```sh
make docker_serve
```

The server will be running as http://localhost:5001

# Lint
## Lint

Run the linting before committing:

Expand All @@ -145,15 +174,15 @@ To auto-fix formatting issues run:
make format
```

# Test
## Test

Run unit tests locally:

```sh
make test
```

# Clean
## Clean

To remove the virtual environment and build artifacts:

Expand Down
Loading

0 comments on commit 54db1e9

Please sign in to comment.