Skip to content

Commit 5a778c0

Browse files
Merge pull request #2626 from syedriko/syedriko-ols-1980
OLS-1980: Add autodiscovery for indexID value
2 parents 9fff282 + 39d3b30 commit 5a778c0

File tree

3 files changed

+20
-45
lines changed

3 files changed

+20
-45
lines changed

ols/app/models/config.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ def validate_yaml(self) -> None:
878878
"""Validate reference content index config."""
879879
if self.product_docs_index_path is not None:
880880
try:
881-
fallback_to_default = False
882881
checks.dir_check(
883882
self.product_docs_index_path, "Reference content index path"
884883
)
@@ -891,22 +890,16 @@ def validate_yaml(self) -> None:
891890
try:
892891
checks.dir_check(default_path, "Reference content index path")
893892
self.product_docs_index_path = FilePath(default_path)
894-
# load all index in the default path
893+
# we don't know the index_id for "latest" so ignore what
894+
# the config says and load whatever index is there
895895
self.product_docs_index_id = None
896-
fallback_to_default = True
897896
except checks.InvalidConfigurationError:
898897
raise e_original
899-
if self.product_docs_index_id is None and not fallback_to_default:
898+
else:
899+
if self.product_docs_index_id is not None:
900900
raise checks.InvalidConfigurationError(
901-
"product_docs_index_path is specified but product_docs_index_id is missing"
901+
"product_docs_index_id is specified but product_docs_index_path is missing"
902902
)
903-
if (
904-
self.product_docs_index_id is not None
905-
and self.product_docs_index_path is None
906-
):
907-
raise checks.InvalidConfigurationError(
908-
"product_docs_index_id is specified but product_docs_index_path is missing"
909-
)
910903

911904

912905
class ReferenceContent(BaseModel):

tests/unit/app/models/test_config.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Unit tests for data models."""
22

33
import copy
4+
import errno
45
import logging
56
import os
7+
from unittest import mock
68

79
import pytest
810
from pydantic import ValidationError
@@ -2928,14 +2930,19 @@ def test_reference_content_index_yaml_validation():
29282930
# should not raise an exception
29292931
reference_content_index.validate_yaml()
29302932

2931-
# existing docs index path with set up product ID
2933+
# existing docs index path with set up index ID
29322934
reference_content_index.product_docs_index_path = "."
29332935
reference_content_index.product_docs_index_id = "foo"
29342936
reference_content_index.validate_yaml()
29352937

2936-
# existing docs index path, but no product ID
2938+
# existing docs index path, but no index ID
29372939
reference_content_index.product_docs_index_path = "."
29382940
reference_content_index.product_docs_index_id = None
2941+
reference_content_index.validate_yaml()
2942+
2943+
# no docs index path, but with index id
2944+
reference_content_index.product_docs_index_path = None
2945+
reference_content_index.product_docs_index_id = "foo"
29392946
with pytest.raises(InvalidConfigurationError):
29402947
reference_content_index.validate_yaml()
29412948

@@ -2952,9 +2959,12 @@ def test_reference_content_index_yaml_validation():
29522959

29532960
# docs index point to a proper directory, that is not
29542961
# readable by the service
2955-
reference_content_index.product_docs_index_path = "/root"
2956-
with pytest.raises(InvalidConfigurationError):
2957-
reference_content_index.validate_yaml()
2962+
with mock.patch(
2963+
"os.stat", side_effect=PermissionError(errno.EACCES, "Permission denied")
2964+
):
2965+
reference_content_index.product_docs_index_path = "/root"
2966+
with pytest.raises(InvalidConfigurationError):
2967+
reference_content_index.validate_yaml()
29582968

29592969

29602970
def test_reference_content_constructor():

tests/unit/utils/test_config.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -544,34 +544,6 @@ def test_invalid_config_improper_reference_content():
544544
check_expected_exception(
545545
"""
546546
---
547-
llm_providers:
548-
- name: p1
549-
type: bam
550-
credentials_path: tests/config/secret/apitoken
551-
models:
552-
- name: m1
553-
credentials_path: tests/config/secret/apitoken
554-
ols_config:
555-
reference_content:
556-
indexes:
557-
- product_docs_index_path: "/tmp"
558-
conversation_cache:
559-
type: memory
560-
memory:
561-
max_entries: 1000
562-
dev_config:
563-
temperature_override: 0.1
564-
enable_dev_ui: true
565-
disable_auth: false
566-
567-
""",
568-
InvalidConfigurationError,
569-
"product_docs_index_path is specified but product_docs_index_id is missing",
570-
)
571-
572-
check_expected_exception(
573-
"""
574-
---
575547
llm_providers:
576548
- name: p1
577549
type: bam

0 commit comments

Comments
 (0)