Skip to content

Commit fbe8476

Browse files
authored
fix local test failures (#2386)
* fix local test failures * set skip
1 parent 59daf78 commit fbe8476

14 files changed

+97
-94
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ jobs:
5757
- name: Test with pytest skipping openai tests
5858
if: matrix.python-version != '3.10' && matrix.os == 'ubuntu-latest'
5959
run: |
60-
pytest test --skip-openai --durations=10 --durations-min=1.0
60+
pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
6161
- name: Test with pytest skipping openai and docker tests
6262
if: matrix.python-version != '3.10' && matrix.os != 'ubuntu-latest'
6363
run: |
64-
pytest test --skip-openai --skip-docker --durations=10 --durations-min=1.0
64+
pytest test --ignore=test/agentchat/contrib --skip-openai --skip-docker --durations=10 --durations-min=1.0
6565
- name: Coverage
6666
if: matrix.python-version == '3.10'
6767
run: |

autogen/agentchat/contrib/agent_builder.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ def _create_agent(
203203
Returns:
204204
agent: a set-up agent.
205205
"""
206-
from huggingface_hub import HfApi
207-
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError
208-
209206
config_list = autogen.config_list_from_json(
210207
self.config_file_or_env,
211208
file_location=self.config_file_location,
@@ -218,10 +215,15 @@ def _create_agent(
218215
f"If you load configs from json, make sure the model in agent_configs is in the {self.config_file_or_env}."
219216
)
220217
try:
218+
from huggingface_hub import HfApi
219+
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError
220+
221221
hf_api = HfApi()
222222
hf_api.model_info(model_name_or_hf_repo)
223223
model_name = model_name_or_hf_repo.split("/")[-1]
224224
server_id = f"{model_name}_{self.host}"
225+
except ImportError:
226+
server_id = self.online_server_name
225227
except GatedRepoError as e:
226228
raise e
227229
except RepositoryNotFoundError:
@@ -495,9 +497,6 @@ def build_from_library(
495497
agent_list: a list of agents.
496498
cached_configs: cached configs.
497499
"""
498-
import chromadb
499-
from chromadb.utils import embedding_functions
500-
501500
if code_execution_config is None:
502501
code_execution_config = {
503502
"last_n_messages": 2,
@@ -528,6 +527,9 @@ def build_from_library(
528527

529528
print("==> Looking for suitable agents in library...")
530529
if embedding_model is not None:
530+
import chromadb
531+
from chromadb.utils import embedding_functions
532+
531533
chroma_client = chromadb.Client()
532534
collection = chroma_client.create_collection(
533535
name="agent_list",

autogen/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.23"
1+
__version__ = "0.2.24"

test/agentchat/contrib/test_agent_builder.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010

1111
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
1212
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
13-
from conftest import skip_openai as skip # noqa: E402
13+
from conftest import reason, skip_openai # noqa: E402
1414
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
1515

16+
try:
17+
import chromadb
18+
import huggingface_hub
19+
except ImportError:
20+
skip = True
21+
else:
22+
skip = False
23+
1624
here = os.path.abspath(os.path.dirname(__file__))
1725

1826

@@ -30,8 +38,8 @@ def _config_check(config):
3038

3139

3240
@pytest.mark.skipif(
33-
skip,
34-
reason="requested to skip",
41+
skip_openai,
42+
reason=reason,
3543
)
3644
def test_build():
3745
builder = AgentBuilder(
@@ -59,8 +67,8 @@ def test_build():
5967

6068

6169
@pytest.mark.skipif(
62-
skip,
63-
reason="requested to skip",
70+
skip_openai or skip,
71+
reason=reason + "OR dependency not installed",
6472
)
6573
def test_build_from_library():
6674
builder = AgentBuilder(
@@ -109,8 +117,8 @@ def test_build_from_library():
109117

110118

111119
@pytest.mark.skipif(
112-
skip,
113-
reason="requested to skip",
120+
skip_openai,
121+
reason=reason,
114122
)
115123
def test_save():
116124
builder = AgentBuilder(
@@ -143,8 +151,8 @@ def test_save():
143151

144152

145153
@pytest.mark.skipif(
146-
skip,
147-
reason="requested to skip",
154+
skip_openai,
155+
reason=reason,
148156
)
149157
def test_load():
150158
builder = AgentBuilder(
@@ -169,8 +177,8 @@ def test_load():
169177

170178

171179
@pytest.mark.skipif(
172-
skip,
173-
reason="requested to skip",
180+
skip_openai,
181+
reason=reason,
174182
)
175183
def test_clear_agent():
176184
builder = AgentBuilder(

test/agentchat/contrib/test_agent_optimizer.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import os
2+
import sys
23

34
import pytest
4-
from conftest import skip_openai as skip
5-
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
65

76
import autogen
8-
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
7+
from autogen import AssistantAgent, UserProxyAgent
98
from autogen.agentchat.contrib.agent_optimizer import AgentOptimizer
109

10+
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
11+
from conftest import reason, skip_openai
12+
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
13+
1114
here = os.path.abspath(os.path.dirname(__file__))
1215

1316

1417
@pytest.mark.skipif(
15-
skip,
16-
reason="requested to skip",
18+
skip_openai,
19+
reason=reason,
1720
)
1821
def test_record_conversation():
1922
problem = "Simplify $\\sqrt[3]{1+8} \\cdot \\sqrt[3]{1+\\sqrt[3]{8}}"
@@ -54,8 +57,8 @@ def test_record_conversation():
5457

5558

5659
@pytest.mark.skipif(
57-
skip,
58-
reason="requested to skip",
60+
skip_openai,
61+
reason=reason,
5962
)
6063
def test_step():
6164
problem = "Simplify $\\sqrt[3]{1+8} \\cdot \\sqrt[3]{1+\\sqrt[3]{8}}"

test/agentchat/contrib/test_gpt_assistant.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from autogen.oai.openai_utils import retrieve_assistants_by_name
1515

1616
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
17-
from conftest import skip_openai as skip # noqa: E402
17+
from conftest import reason, skip_openai # noqa: E402
1818

1919
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
2020
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
2121

22-
if not skip:
22+
if not skip_openai:
2323
openai_config_list = autogen.config_list_from_json(
2424
OAI_CONFIG_LIST,
2525
file_location=KEY_LOC,
@@ -45,17 +45,17 @@
4545

4646

4747
@pytest.mark.skipif(
48-
skip,
49-
reason="requested to skip",
48+
skip_openai,
49+
reason=reason,
5050
)
5151
def test_config_list() -> None:
5252
assert len(openai_config_list) > 0
5353
assert len(aoai_config_list) > 0
5454

5555

5656
@pytest.mark.skipif(
57-
skip,
58-
reason="requested to skip",
57+
skip_openai,
58+
reason=reason,
5959
)
6060
def test_gpt_assistant_chat() -> None:
6161
for gpt_config in [openai_config_list, aoai_config_list]:
@@ -128,8 +128,8 @@ def ask_ossinsight(question: str) -> str:
128128

129129

130130
@pytest.mark.skipif(
131-
skip,
132-
reason="requested to skip",
131+
skip_openai,
132+
reason=reason,
133133
)
134134
def test_get_assistant_instructions() -> None:
135135
for gpt_config in [openai_config_list, aoai_config_list]:
@@ -157,8 +157,8 @@ def _test_get_assistant_instructions(gpt_config) -> None:
157157

158158

159159
@pytest.mark.skipif(
160-
skip,
161-
reason="requested to skip",
160+
skip_openai,
161+
reason=reason,
162162
)
163163
def test_gpt_assistant_instructions_overwrite() -> None:
164164
for gpt_config in [openai_config_list, aoai_config_list]:
@@ -211,8 +211,8 @@ def _test_gpt_assistant_instructions_overwrite(gpt_config) -> None:
211211

212212

213213
@pytest.mark.skipif(
214-
skip,
215-
reason="requested to skip",
214+
skip_openai,
215+
reason=reason,
216216
)
217217
def test_gpt_assistant_existing_no_instructions() -> None:
218218
"""
@@ -251,8 +251,8 @@ def test_gpt_assistant_existing_no_instructions() -> None:
251251

252252

253253
@pytest.mark.skipif(
254-
skip,
255-
reason="requested to skip",
254+
skip_openai,
255+
reason=reason,
256256
)
257257
def test_get_assistant_files() -> None:
258258
"""
@@ -288,8 +288,8 @@ def test_get_assistant_files() -> None:
288288

289289

290290
@pytest.mark.skipif(
291-
skip,
292-
reason="requested to skip",
291+
skip_openai,
292+
reason=reason,
293293
)
294294
def test_assistant_retrieval() -> None:
295295
"""
@@ -365,8 +365,8 @@ def test_assistant_retrieval() -> None:
365365

366366

367367
@pytest.mark.skipif(
368-
skip,
369-
reason="requested to skip",
368+
skip_openai,
369+
reason=reason,
370370
)
371371
def test_assistant_mismatch_retrieval() -> None:
372372
"""Test function to check if the GPTAssistantAgent can filter out the mismatch assistant"""
@@ -487,8 +487,8 @@ def test_assistant_mismatch_retrieval() -> None:
487487

488488

489489
@pytest.mark.skipif(
490-
skip,
491-
reason="requested to skip",
490+
skip_openai,
491+
reason=reason,
492492
)
493493
def test_gpt_assistant_tools_overwrite() -> None:
494494
"""
@@ -609,8 +609,8 @@ def test_gpt_assistant_tools_overwrite() -> None:
609609

610610

611611
@pytest.mark.skipif(
612-
skip,
613-
reason="requested to skip",
612+
skip_openai,
613+
reason=reason,
614614
)
615615
def test_gpt_reflection_with_llm() -> None:
616616
gpt_assistant = GPTAssistantAgent(

test/agentchat/contrib/test_web_surfer.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from autogen.oai.openai_utils import filter_config
1111

1212
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
13-
from conftest import MOCK_OPEN_AI_API_KEY, skip_openai # noqa: E402
13+
from conftest import MOCK_OPEN_AI_API_KEY, reason, skip_openai # noqa: E402
1414

1515
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
1616
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
@@ -26,21 +26,14 @@
2626
else:
2727
skip_all = False
2828

29-
try:
30-
from openai import OpenAI
31-
except ImportError:
32-
skip_oai = True
33-
else:
34-
skip_oai = False or skip_openai
35-
3629
try:
3730
BING_API_KEY = os.environ["BING_API_KEY"]
3831
except KeyError:
3932
skip_bing = True
4033
else:
4134
skip_bing = False
4235

43-
if not skip_oai:
36+
if not skip_openai:
4437
config_list = config_list_from_json(env_or_file=OAI_CONFIG_LIST, file_location=KEY_LOC)
4538

4639

@@ -104,8 +97,8 @@ def test_web_surfer() -> None:
10497

10598

10699
@pytest.mark.skipif(
107-
skip_oai,
108-
reason="do not run if oai is not installed",
100+
skip_all or skip_openai,
101+
reason="dependency is not installed OR" + reason,
109102
)
110103
def test_web_surfer_oai() -> None:
111104
llm_config = {"config_list": config_list, "timeout": 180, "cache_seed": 42}

test/agentchat/test_agent_logging.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import json
2+
import os
23
import sqlite3
34
import sys
45
import uuid
56

67
import pytest
7-
from conftest import skip_openai
8-
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
98

109
import autogen
1110
import autogen.runtime_logging
1211

12+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
13+
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
14+
from conftest import skip_openai # noqa: E402
15+
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
16+
1317
TEACHER_MESSAGE = """
1418
You are roleplaying a math teacher, and your job is to help your students with linear algebra.
1519
Keep your explanations short.

0 commit comments

Comments
 (0)