-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
246 additions
and
63 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
50 changes: 50 additions & 0 deletions
50
ansible_ai_connect/ai/api/model_pipelines/tests/test_config_loader.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import yaml | ||
from django.test import override_settings | ||
|
||
from ansible_ai_connect.ai.api.model_pipelines.config_loader import load_config | ||
from ansible_ai_connect.ai.api.model_pipelines.config_providers import Configuration | ||
from ansible_ai_connect.ai.api.model_pipelines.pipelines import MetaData | ||
from ansible_ai_connect.ai.api.model_pipelines.registry import REGISTRY_ENTRY | ||
from ansible_ai_connect.ai.api.model_pipelines.tests import mock_config | ||
from ansible_ai_connect.test_utils import WisdomTestCase | ||
|
||
|
||
def _convert_json_to_yaml(json_config: str): | ||
yaml_config = yaml.safe_load(json_config) | ||
return yaml.safe_dump(yaml_config) | ||
|
||
|
||
class TestConfigLoader(WisdomTestCase): | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=None) | ||
def test_config_undefined(self): | ||
with self.assertRaises(TypeError): | ||
load_config() | ||
|
||
def assert_config(self): | ||
config: Configuration = load_config() | ||
pipelines = [i for i in REGISTRY_ENTRY.keys() if issubclass(i, MetaData)] | ||
for k in pipelines: | ||
self.assertTrue(k.__name__ in config) | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=mock_config("ollama")) | ||
def test_config_json(self): | ||
self.assert_config() | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=_convert_json_to_yaml(mock_config("ollama"))) | ||
def test_config_yaml(self): | ||
self.assert_config() |
69 changes: 58 additions & 11 deletions
69
docs/config/examples/README-ANSIBLE_AI_MODEL_MESH_CONFIG.md
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 |
---|---|---|
@@ -1,40 +1,87 @@ | ||
# Example `ANSIBLE_AI_MODEL_MESH_CONFIG` configuration | ||
|
||
Pay close attention to the formatting of the blocks. | ||
`ANSIBLE_AI_MODEL_MESH_CONFIG` can be defined with either JSON or YAML. | ||
|
||
Each ends with `}},` otherwise conversion of the multi-line setting to a `str` can fail. | ||
## JSON Configuration | ||
|
||
```text | ||
ANSIBLE_AI_MODEL_MESH_CONFIG="{ | ||
```json | ||
{ | ||
"ModelPipelineCompletions": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"model_id": "mistral:instruct" | ||
} | ||
}, | ||
"ModelPipelineContentMatch": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"model_id": "mistral:instruct" | ||
} | ||
}, | ||
"ModelPipelinePlaybookGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"model_id": "mistral:instruct" | ||
} | ||
}, | ||
"ModelPipelineRoleGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"model_id": "mistral:instruct" | ||
} | ||
}, | ||
"ModelPipelinePlaybookExplanation": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"model_id": "mistral:instruct" | ||
} | ||
}, | ||
"ModelPipelineChatBot": { | ||
"provider": "http", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "granite3-8b"}} | ||
}" | ||
"model_id": "granite3-8b" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## YAML Configuration | ||
|
||
```yaml | ||
MetaData: | ||
provider: ollama | ||
config: | ||
inference_url: http://localhost | ||
model_id: a-model-id | ||
ModelPipelineCompletions: | ||
provider: ollama | ||
config: | ||
inference_url: http://localhost | ||
model_id: a-model-id | ||
ModelPipelinePlaybookGeneration: | ||
provider: ollama | ||
config: | ||
inference_url: http://localhost | ||
model_id: a-model-id | ||
ModelPipelineRoleGeneration: | ||
provider: ollama | ||
config: | ||
inference_url: http://localhost | ||
model_id: a-model-id | ||
ModelPipelinePlaybookExplanation: | ||
provider: ollama | ||
config: | ||
inference_url: http://localhost | ||
model_id: a-model-id | ||
ModelPipelineChatBot: | ||
provider: http, | ||
config: | ||
inference_url: http://localhost | ||
model_id: granite3-8b | ||
``` |
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 |
---|---|---|
@@ -1,46 +1,58 @@ | ||
# Example `ANSIBLE_AI_MODEL_MESH_CONFIG` configuration for `dummy` | ||
|
||
```text | ||
ANSIBLE_AI_MODEL_MESH_CONFIG="{ | ||
```json | ||
{ | ||
"ModelPipelineCompletions": { | ||
"provider": "dummy", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"body": "{\"predictions\":[\"ansible.builtin.apt:\\n name: nginx\\n update_cache: true\\n state: present\\n\"]}", | ||
"latency_max_msec": "3000", | ||
"latency_use_jitter": "False"}}, | ||
"latency_use_jitter": "False" | ||
} | ||
}, | ||
"ModelPipelineContentMatch": { | ||
"provider": "dummy", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"body": "{\"predictions\":[\"ansible.builtin.apt:\\n name: nginx\\n update_cache: true\\n state: present\\n\"]}", | ||
"latency_max_msec": "3000", | ||
"latency_use_jitter": "False"}}, | ||
"latency_use_jitter": "False" | ||
} | ||
}, | ||
"ModelPipelinePlaybookGeneration": { | ||
"provider": "dummy", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"body": "{\"predictions\":[\"ansible.builtin.apt:\\n name: nginx\\n update_cache: true\\n state: present\\n\"]}", | ||
"latency_max_msec": "3000", | ||
"latency_use_jitter": "False"}}, | ||
"latency_use_jitter": "False" | ||
} | ||
}, | ||
"ModelPipelineRoleGeneration": { | ||
"provider": "dummy", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"body": "{\"predictions\":[\"ansible.builtin.apt:\\n name: nginx\\n update_cache: true\\n state: present\\n\"]}", | ||
"latency_max_msec": "3000", | ||
"latency_use_jitter": "False"}}, | ||
"latency_use_jitter": "False" | ||
} | ||
}, | ||
"ModelPipelinePlaybookExplanation": { | ||
"provider": "dummy", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"body": "{\"predictions\":[\"ansible.builtin.apt:\\n name: nginx\\n update_cache: true\\n state: present\\n\"]}", | ||
"latency_max_msec": "3000", | ||
"latency_use_jitter": "False"}}, | ||
"latency_use_jitter": "False" | ||
} | ||
}, | ||
"ModelPipelineChatBot": { | ||
"provider": "http", | ||
"config": { | ||
"inference_url": "<CHATBOT_URL>", | ||
"model_id": "<CHATBOT_DEFAULT_MODEL>"}} | ||
}" | ||
"model_id": "<CHATBOT_DEFAULT_MODEL>" | ||
} | ||
} | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,36 +1,48 @@ | ||
# Example `ANSIBLE_AI_MODEL_MESH_CONFIG` configuration for `ollama` | ||
|
||
```text | ||
ANSIBLE_AI_MODEL_MESH_CONFIG="{ | ||
```json | ||
{ | ||
"ModelPipelineCompletions": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "ollama-model"}}, | ||
"model_id": "ollama-model" | ||
} | ||
}, | ||
"ModelPipelineContentMatch": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "ollama-model"}}, | ||
"model_id": "ollama-model" | ||
} | ||
}, | ||
"ModelPipelinePlaybookGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "ollama-model"}}, | ||
"model_id": "ollama-model" | ||
} | ||
}, | ||
"ModelPipelineRoleGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "ollama-model"}}, | ||
"model_id": "ollama-model" | ||
} | ||
}, | ||
"ModelPipelinePlaybookExplanation": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"model_id": "ollama-model"}}, | ||
"model_id": "ollama-model" | ||
} | ||
}, | ||
"ModelPipelineChatBot": { | ||
"provider": "http", | ||
"config": { | ||
"inference_url": "<CHATBOT_URL>", | ||
"model_id": "<CHATBOT_DEFAULT_MODEL>"}} | ||
}" | ||
"model_id": "<CHATBOT_DEFAULT_MODEL>" | ||
} | ||
} | ||
} | ||
``` |
Oops, something went wrong.