Skip to content

Commit 90b665c

Browse files
committed
OLS-1980: Add autodiscovery for indexID value
1 parent 363a3da commit 90b665c

File tree

3 files changed

+18
-45
lines changed

3 files changed

+18
-45
lines changed

ols/app/models/config.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ def validate_yaml(self) -> None:
874874
"""Validate reference content index config."""
875875
if self.product_docs_index_path is not None:
876876
try:
877-
fallback_to_default = False
878877
checks.dir_check(
879878
self.product_docs_index_path, "Reference content index path"
880879
)
@@ -887,22 +886,16 @@ def validate_yaml(self) -> None:
887886
try:
888887
checks.dir_check(default_path, "Reference content index path")
889888
self.product_docs_index_path = FilePath(default_path)
890-
# load all index in the default path
889+
# we don't know the index_id for "latest" so ignore what
890+
# the config says and load whatever index is there
891891
self.product_docs_index_id = None
892-
fallback_to_default = True
893892
except checks.InvalidConfigurationError:
894893
raise e_original
895-
if self.product_docs_index_id is None and not fallback_to_default:
894+
else:
895+
if self.product_docs_index_id is not None:
896896
raise checks.InvalidConfigurationError(
897-
"product_docs_index_path is specified but product_docs_index_id is missing"
897+
"product_docs_index_id is specified but product_docs_index_path is missing"
898898
)
899-
if (
900-
self.product_docs_index_id is not None
901-
and self.product_docs_index_path is None
902-
):
903-
raise checks.InvalidConfigurationError(
904-
"product_docs_index_id is specified but product_docs_index_path is missing"
905-
)
906899

907900

908901
class ReferenceContent(BaseModel):

tests/unit/app/models/test_config.py

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

33
import copy
4+
import errno
45
import logging
56
import os
67

78
import pytest
89
from pydantic import ValidationError
10+
from unittest import mock
911

1012
import ols.utils.tls as tls
1113
from ols import constants
@@ -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,10 @@ 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("os.stat", side_effect=PermissionError(errno.EACCES, "Permission denied")):
2963+
reference_content_index.product_docs_index_path = "/root"
2964+
with pytest.raises(InvalidConfigurationError):
2965+
reference_content_index.validate_yaml()
29582966

29592967

29602968
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)