-
Notifications
You must be signed in to change notification settings - Fork 11
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
AAP-36732: ModelPipelines: Configuration improvements: Remove env vars #1487
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,40 @@ | ||
# Example `ANSIBLE_AI_MODEL_MESH_CONFIG` configuration | ||
|
||
Pay close attention to the formatting of the blocks. | ||
|
||
Each ends with `}},` otherwise conversion of the multi-line setting to a `str` can fail. | ||
manstis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```text | ||
ANSIBLE_AI_MODEL_MESH_CONFIG="{ | ||
"ModelPipelineCompletions": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"ModelPipelineContentMatch": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"ModelPipelinePlaybookGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"ModelPipelineRoleGeneration": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"ModelPipelinePlaybookExplanation": { | ||
"provider": "ollama", | ||
"config": { | ||
"inference_url": "http://host.containers.internal:11434", | ||
"model_id": "mistral:instruct"}}, | ||
"ModelPipelineChatBot": { | ||
"provider": "http", | ||
"config": { | ||
"inference_url": "http://localhost:8000", | ||
"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
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
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
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
# 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 json | ||
from json import JSONDecodeError | ||
|
||
import yaml | ||
from django.test import override_settings | ||
from rest_framework.exceptions import ValidationError | ||
from yaml import YAMLError | ||
|
||
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 | ||
|
||
EMPTY = { | ||
"MetaData": { | ||
"provider": "dummy", | ||
}, | ||
} | ||
|
||
|
||
def _convert_json_to_yaml(json_config: str): | ||
yaml_config = yaml.safe_load(json_config) | ||
return yaml.safe_dump(yaml_config) | ||
|
||
|
||
class TestConfigLoader(WisdomTestCase): | ||
|
||
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) | ||
|
||
def assert_invalid_config(self): | ||
with self.assertRaises(ExceptionGroup) as e: | ||
load_config() | ||
exceptions = e.exception.exceptions | ||
self.assertEqual(len(exceptions), 2) | ||
self.assertIsInstance(exceptions[0], JSONDecodeError) | ||
self.assertIsInstance(exceptions[1], YAMLError) | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=None) | ||
def test_config_undefined(self): | ||
with self.assertRaises(TypeError): | ||
load_config() | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG=json.dumps(EMPTY)) | ||
def test_config_empty(self): | ||
self.assert_config() | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG="") | ||
def test_config_empty_string(self): | ||
with self.assertRaises(ValidationError): | ||
self.assert_config() | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG='{"MetaData" : {') | ||
def test_config_invalid_json(self): | ||
self.assert_invalid_config() | ||
|
||
@override_settings(ANSIBLE_AI_MODEL_MESH_CONFIG="MetaData:\nbanana") | ||
def test_config_invalid_yaml(self): | ||
self.assert_invalid_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() |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This aligns the Python version with the other GHA definition.
3.11
is needed to supportExceptionGroup
(used in this PR). It is also the version used to build the container.