Skip to content
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
10 changes: 0 additions & 10 deletions .github/workflows/Build_Push_Image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ jobs:
echo "sha-short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "sha-long=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: Retrieve ari knowledge base from s3
run: |
aws s3 cp --only-show-errors --recursive ${KB_ARI_PATH}/data ari/kb/data
aws s3 cp --only-show-errors --recursive ${KB_ARI_PATH}/rules ari/kb/rules
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
KB_ARI_PATH: ${{ secrets.KB_ARI_PATH }}

- name: Free space on build machine
run: |
rm -rf /opt/hostedtoolcache/Java*
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:
ANSIBLE_AI_DATABASE_NAME: wisdom
ANSIBLE_AI_DATABASE_PASSWORD: wisdom
ANSIBLE_AI_DATABASE_USER: wisdom
ARI_KB_PATH: /etc/ari/kb/
DJANGO_SETTINGS_MODULE: ansible_ai_connect.main.settings.development
ENABLE_ARI_POSTPROCESS: False
ENABLE_ANSIBLE_LINT_POSTPROCESS: True
PYTHONUNBUFFERED: 1
SECRET_KEY: somesecret
Expand Down Expand Up @@ -59,18 +57,6 @@ jobs:
pip install -r requirements-dev.txt
pip install .

- name: Retrieve ari knowledge base from s3
run: |
sudo mkdir -p /etc/ari/kb
sudo chown -R $USER:$USER /etc/ari/kb
aws s3 cp --only-show-errors --recursive ${KB_ARI_PATH}/data /etc/ari/kb/data
aws s3 cp --only-show-errors --recursive ${KB_ARI_PATH}/rules /etc/ari/kb/rules
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
KB_ARI_PATH: ${{ secrets.KB_ARI_PATH }}

- name: Create CA symlink to use RH's certifi on ubuntu-latest
run: |
sudo mkdir -p /etc/pki/tls/certs
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ ifeq ($(ENVIRONMENT),development)
export ANSIBLE_AI_DATABASE_NAME := wisdom
export ANSIBLE_AI_DATABASE_PASSWORD := wisdom
export ANSIBLE_AI_DATABASE_USER := wisdom
export ARI_KB_PATH := ../ari/kb/
export DJANGO_SETTINGS_MODULE := ansible_ai_connect.main.settings.development
export ENABLE_ARI_POSTPROCESS := False
export PYTHONUNBUFFERED := 1
export SECRET_KEY := somesecret
export DJANGO_SUPERUSER_PASSWORD := somesecret
Expand Down
53 changes: 1 addition & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Populate the `tools/docker-compose/.env` file with the following values:
```bash
DEPLOYMENT_MODE="upstream"
SECRET_KEY="somesecretvalue"
ENABLE_ARI_POSTPROCESS="False"
WCA_SECRET_BACKEND_TYPE="dummy"
# configure model server
ANSIBLE_AI_MODEL_MESH_CONFIG="..."
Expand Down Expand Up @@ -350,41 +349,6 @@ To get an authentication token without logging in via GitHub, you also:

To test the API with no authentication, you can empty out `REST_FRAMEWORK.DEFAULT_PERMISSION_CLASSES` in base.py.

## Enabling postprocess with ARI

You can enable postprocess with [Ansible Risk Insight (ARI)](https://github.com/ansible/ansible-risk-insight) for
improving the completion output just by following these 2 steps below.

1. Set the environment variable `ENABLE_ARI_POSTPROCESS` to True

```bash
$ export ENABLE_ARI_POSTPROCESS=True
```


2. Prepare `rules` and `data` directory inside `ari/kb` directory.

`rules` should contain mutation rules for the postprocess, you can refer
to [here](https://github.com/ansible/ari-metrics-for-wisdom/tree/main/rules) for some examples.

`data` should contain the backend data for ARI. We will host this data somewhere in the future, but currently this
file must be placed manually if you want to enable the postprocess.

Once the files are ready, the `ari/kb` directory should look like this.

```bash
ari/kb/
├── data
│   ├── collections
│   └── indices
└── rules
├── W001_module_name_metrics.py
├── W002_module_key_metrics.py
├── ...
```

Then you can build the django image or just run `make docker-compose`.

## Enabling postprocess with Ansible Lint

You can enable postprocess with [Ansible Lint](https://github.com/ansible/ansible-lint) for improving the completion output just by setting the environment variable `ENABLE_ANSIBLE_LINT_POSTPROCESS` to True
Expand Down Expand Up @@ -460,7 +424,6 @@ To connect to the Mistal 7b Instruct model running on locally on [llama.cpp](htt
1. Set the appropriate environment variables
```bash
ANSIBLE_AI_MODEL_MESH_CONFIG="..."
ENABLE_ARI_POSTPROCESS=False
```
See the example [ANSIBLE_AI_MODEL_MESH_CONFIG](./docs/config/examples/README-ANSIBLE_AI_MODEL_MESH_CONFIG.md).

Expand Down Expand Up @@ -522,17 +485,11 @@ ANSIBLE_AI_DATABASE_HOST=localhost
ANSIBLE_AI_DATABASE_NAME=wisdom
ANSIBLE_AI_DATABASE_PASSWORD=wisdom
ANSIBLE_AI_DATABASE_USER=wisdom
ARI_KB_PATH=../ari/kb/
DJANGO_SETTINGS_MODULE=ansible_wisdom.main.settings.development
ENABLE_ARI_POSTPROCESS=True
PYTHONUNBUFFERED=1
SECRET_KEY=somesecret
```

Note that this `.env` file assumes that the Django
service is executed in the `ansible_wisdom` subdirectory
as `ARI_KB_PATH` is defined as `../ari/kb`.

It is recommended to use `make` to run unit tests since it helps to configure default values.
If you want to execute only specific file/class/method you can use $WISDOM_TEST variable:

Expand Down Expand Up @@ -611,20 +568,12 @@ E.g:

If you get a permission denied error when attempting to start the
containers, you may need to set the permissions on the
`ansible_wisdom/`, `prometheus/` and `ari/` directories:
`ansible_wisdom/` and `prometheus/` directories:

```bash
chcon -t container_file_t -R ansible_wisdom/
chcon -t container_file_t -R prometheus/
chcon -t container_file_t -R grafana/
chcon -t container_file_t -R ari/
```

Also run `chmod` against the `ari/` directory so that ARI can
write temporary data in it:

```bash
chmod -R 777 ari/
```

If your django container build fails with the following error, you've
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def setUp(self):
retry_count=3,
api_key="test-api-key",
enable_health_check=True,
enable_ari_postprocessing=False,
health_check_api_key="test-health-key",
health_check_model_id="test-health-model",
username="test-user",
Expand Down Expand Up @@ -122,7 +121,6 @@ def test_wca_pipeline_ssl_disabled(self):
retry_count=3,
api_key="test-api-key",
enable_health_check=True,
enable_ari_postprocessing=False,
health_check_api_key="test-health-key",
health_check_model_id="test-health-model",
username="test-user",
Expand Down
4 changes: 0 additions & 4 deletions ansible_ai_connect/ai/api/model_pipelines/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from typing import Any, Dict, Generic, Optional

from attrs import define, field
from django.conf import settings
from django.http import StreamingHttpResponse
from rest_framework import serializers
from rest_framework.request import Request
Expand Down Expand Up @@ -306,9 +305,6 @@ def __init__(self, config: PIPELINE_CONFIGURATION):
def get_model_id(self, user, requested_model_id: Optional[str] = None) -> str:
return requested_model_id or self.config.model_id

def supports_ari_postprocessing(self):
return settings.ENABLE_ARI_POSTPROCESS


class ModelPipeline(
MetaData[PIPELINE_CONFIGURATION],
Expand Down
2 changes: 0 additions & 2 deletions ansible_ai_connect/ai/api/model_pipelines/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def mock_pipeline_config(pipeline_provider: t_model_mesh_api_type, **kwargs):
enable_health_check=extract("enable_health_check", False, **kwargs),
verify_ssl=extract("verify_ssl", False, **kwargs),
retry_count=extract("retry_count", 4, **kwargs),
enable_ari_postprocessing=extract("enable_ari_postprocessing", False, **kwargs),
health_check_api_key=extract(
"health_check_api_key", "a-healthcheck-api-key", **kwargs
),
Expand All @@ -144,7 +143,6 @@ def mock_pipeline_config(pipeline_provider: t_model_mesh_api_type, **kwargs):
enable_health_check=extract("enable_health_check", False, **kwargs),
verify_ssl=extract("verify_ssl", False, **kwargs),
retry_count=extract("retry_count", 4, **kwargs),
enable_ari_postprocessing=extract("enable_ari_postprocessing", False, **kwargs),
health_check_api_key=extract(
"health_check_api_key", "a-healthcheck-api-key", **kwargs
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ def test_infer_wca_validation_failure(self):
"scope": "ibm openid",
}
response = MockResponse(
json={"detail": "ARI processing failed"},
json={"detail": "Validation failed"},
status_code=422,
headers={"Content-Type": "application/json"},
)
Expand All @@ -1150,7 +1150,7 @@ def test_infer_wca_validation_failure(self):
self.assertEqual(e.exception.model_id, model_id)
self.assertInLog(
"WCA request failed with 422. Content-Type:application/json, "
'Content:b\'{"detail": "ARI processing failed"}\'',
'Content:b\'{"detail": "Validation failed"}\'',
log,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# ENABLE_HEALTHCHECK_XXX
# ANSIBLE_AI_MODEL_MESH_API_VERIFY_SSL
# ANSIBLE_WCA_RETRY_COUNT
# WCA_ENABLE_ARI_POSTPROCESS
# ANSIBLE_WCA_HEALTHCHECK_API_KEY
# ANSIBLE_WCA_HEALTHCHECK_MODEL_ID

Expand All @@ -49,7 +48,6 @@ def __init__(
enable_health_check: Optional[bool],
verify_ssl: bool,
retry_count: int,
enable_ari_postprocessing: bool,
health_check_api_key: str,
health_check_model_id: str,
enable_anonymization: bool,
Expand All @@ -58,15 +56,13 @@ def __init__(
self.api_key = api_key
self.verify_ssl = verify_ssl
self.retry_count = retry_count
self.enable_ari_postprocessing = enable_ari_postprocessing
self.health_check_api_key = health_check_api_key
self.health_check_model_id = health_check_model_id
self.enable_anonymization = enable_anonymization

api_key: str
verify_ssl: bool
retry_count: int
enable_ari_postprocessing: bool
health_check_url: str
health_check_model_id: str

Expand All @@ -81,7 +77,6 @@ class WCABaseConfigurationSerializer(BaseConfigSerializer):
api_key = serializers.CharField(required=False, allow_null=True, allow_blank=True)
verify_ssl = serializers.BooleanField(required=False, default=True)
retry_count = serializers.IntegerField(required=False, default=4)
enable_ari_postprocessing = serializers.BooleanField(required=False, default=False)
health_check_api_key = serializers.CharField(required=True)
health_check_model_id = serializers.CharField(required=True)
enable_anonymization = serializers.BooleanField(required=False, default=True)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# ENABLE_HEALTHCHECK_XXX
# ANSIBLE_AI_MODEL_MESH_API_VERIFY_SSL
# ANSIBLE_WCA_RETRY_COUNT
# WCA_ENABLE_ARI_POSTPROCESS
# ANSIBLE_WCA_HEALTHCHECK_API_KEY
# ANSIBLE_WCA_HEALTHCHECK_MODEL_ID

Expand All @@ -51,7 +50,6 @@ def __init__(
enable_health_check: Optional[bool],
verify_ssl: bool,
retry_count: int,
enable_ari_postprocessing: bool,
health_check_api_key: str,
health_check_model_id: str,
username: str,
Expand All @@ -65,7 +63,6 @@ def __init__(
enable_health_check,
verify_ssl,
retry_count,
enable_ari_postprocessing,
health_check_api_key,
health_check_model_id,
enable_anonymization,
Expand All @@ -90,7 +87,6 @@ def __init__(self, **kwargs):
enable_health_check=kwargs["enable_health_check"],
verify_ssl=kwargs["verify_ssl"],
retry_count=kwargs["retry_count"],
enable_ari_postprocessing=kwargs["enable_ari_postprocessing"],
health_check_api_key=kwargs["health_check_api_key"],
health_check_model_id=kwargs["health_check_model_id"],
username=kwargs["username"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# ENABLE_HEALTHCHECK_XXX
# ANSIBLE_AI_MODEL_MESH_API_VERIFY_SSL
# ANSIBLE_WCA_RETRY_COUNT
# WCA_ENABLE_ARI_POSTPROCESS
# ANSIBLE_WCA_HEALTHCHECK_API_KEY
# ANSIBLE_WCA_HEALTHCHECK_MODEL_ID

Expand All @@ -55,7 +54,6 @@ def __init__(
enable_health_check: Optional[bool],
verify_ssl: bool,
retry_count: int,
enable_ari_postprocessing: bool,
health_check_api_key: str,
health_check_model_id: str,
idp_url: str,
Expand All @@ -73,7 +71,6 @@ def __init__(
enable_health_check,
verify_ssl,
retry_count,
enable_ari_postprocessing,
health_check_api_key,
health_check_model_id,
enable_anonymization,
Expand Down Expand Up @@ -108,7 +105,6 @@ def __init__(self, **kwargs):
enable_health_check=kwargs["enable_health_check"],
verify_ssl=kwargs["verify_ssl"],
retry_count=kwargs["retry_count"],
enable_ari_postprocessing=kwargs["enable_ari_postprocessing"],
health_check_api_key=kwargs["health_check_api_key"],
health_check_model_id=kwargs["health_check_model_id"],
idp_url=kwargs["idp_url"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ def on_backoff_ibm_cloud_identity_token(details):
def get_api_key(self, user) -> str:
raise NotImplementedError

def supports_ari_postprocessing(self) -> bool:
return settings.ENABLE_ARI_POSTPROCESS and self.config.enable_ari_postprocessing


class WCABasePipeline(
WCABaseMetaData,
Expand Down
2 changes: 1 addition & 1 deletion ansible_ai_connect/ai/api/model_pipelines/wca/wca_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def check(self, context: Context):
payload_json = context.result.json()
if isinstance(payload_json, dict):
payload_detail = payload_json.get("detail")
if payload_detail and "ari processing failed" in payload_detail.lower():
if payload_detail and "validation failed" in payload_detail.lower():
raise WcaValidationFailure(
model_id=context.model_id, json_response=context.result.json()
)
Expand Down
Loading
Loading