Skip to content

Commit a0a8cf9

Browse files
authored
Add a warning message if docs_path not explicitly set (microsoft#814)
* Add a warning message if docs_path not explicitly set * update * Add how to suppress warning message * Fix tests errors * Fix tests errors * Fix tests errors
1 parent 5f72e17 commit a0a8cf9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

autogen/agentchat/contrib/retrieve_user_proxy_agent.py

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from autogen.retrieve_utils import create_vector_db_from_dir, query_vector_db, TEXT_FORMATS
1010
from autogen.token_count_utils import count_token
1111
from autogen.code_utils import extract_code
12+
from autogen import logger
1213

1314
from typing import Callable, Dict, Optional, Union, List, Tuple, Any
1415
from IPython import get_ipython
@@ -171,6 +172,12 @@ def retrieve_docs(self, problem: str, n_results: int = 20, search_string: str =
171172
self._client = self._retrieve_config.get("client", chromadb.Client())
172173
self._docs_path = self._retrieve_config.get("docs_path", None)
173174
self._collection_name = self._retrieve_config.get("collection_name", "autogen-docs")
175+
if "docs_path" not in self._retrieve_config:
176+
logger.warning(
177+
"docs_path is not provided in retrieve_config. "
178+
f"Will raise ValueError if the collection `{self._collection_name}` doesn't exist. "
179+
"Set docs_path to None to suppress this warning."
180+
)
174181
self._model = self._retrieve_config.get("model", "gpt-4")
175182
self._max_tokens = self.get_max_tokens(self._model)
176183
self._chunk_token_size = int(self._retrieve_config.get("chunk_token_size", self._max_tokens * 0.4))

test/agentchat/contrib/test_retrievechat.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,34 @@ def test_retrievechat():
6868
print(conversations)
6969

7070

71+
@pytest.mark.skipif(
72+
sys.platform in ["darwin", "win32"] or skip_test,
73+
reason="do not run on MacOS or windows or dependency is not installed",
74+
)
75+
def test_retrieve_config(caplog):
76+
# test warning message when no docs_path is provided
77+
ragproxyagent = RetrieveUserProxyAgent(
78+
name="ragproxyagent",
79+
human_input_mode="NEVER",
80+
max_consecutive_auto_reply=2,
81+
retrieve_config={
82+
"chunk_token_size": 2000,
83+
"get_or_create": True,
84+
},
85+
)
86+
87+
# Capture the printed content
88+
captured_logs = caplog.records[0]
89+
print(captured_logs)
90+
91+
# Assert on the printed content
92+
assert (
93+
f"docs_path is not provided in retrieve_config. Will raise ValueError if the collection `{ragproxyagent._collection_name}` doesn't exist."
94+
in captured_logs.message
95+
)
96+
assert captured_logs.levelname == "WARNING"
97+
98+
7199
if __name__ == "__main__":
72-
test_retrievechat()
100+
# test_retrievechat()
101+
test_retrieve_config()

0 commit comments

Comments
 (0)