Skip to content
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

fix local test failures #2386

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ jobs:
- name: Test with pytest skipping openai tests
if: matrix.python-version != '3.10' && matrix.os == 'ubuntu-latest'
run: |
pytest test --skip-openai --durations=10 --durations-min=1.0
pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
- name: Test with pytest skipping openai and docker tests
if: matrix.python-version != '3.10' && matrix.os != 'ubuntu-latest'
run: |
pytest test --skip-openai --skip-docker --durations=10 --durations-min=1.0
pytest test --ignore=test/agentchat/contrib --skip-openai --skip-docker --durations=10 --durations-min=1.0
- name: Coverage
if: matrix.python-version == '3.10'
run: |
Expand Down
14 changes: 8 additions & 6 deletions autogen/agentchat/contrib/agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ def _create_agent(
Returns:
agent: a set-up agent.
"""
from huggingface_hub import HfApi
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError

config_list = autogen.config_list_from_json(
self.config_file_or_env,
file_location=self.config_file_location,
Expand All @@ -218,10 +215,15 @@ def _create_agent(
f"If you load configs from json, make sure the model in agent_configs is in the {self.config_file_or_env}."
)
try:
from huggingface_hub import HfApi
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError

hf_api = HfApi()
hf_api.model_info(model_name_or_hf_repo)
model_name = model_name_or_hf_repo.split("/")[-1]
server_id = f"{model_name}_{self.host}"
except ImportError:
server_id = self.online_server_name
except GatedRepoError as e:
raise e
except RepositoryNotFoundError:
Expand Down Expand Up @@ -495,9 +497,6 @@ def build_from_library(
agent_list: a list of agents.
cached_configs: cached configs.
"""
import chromadb
from chromadb.utils import embedding_functions

if code_execution_config is None:
code_execution_config = {
"last_n_messages": 2,
Expand Down Expand Up @@ -528,6 +527,9 @@ def build_from_library(

print("==> Looking for suitable agents in library...")
if embedding_model is not None:
import chromadb
from chromadb.utils import embedding_functions

chroma_client = chromadb.Client()
collection = chroma_client.create_collection(
name="agent_list",
Expand Down
2 changes: 1 addition & 1 deletion autogen/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.23"
__version__ = "0.2.24"
30 changes: 19 additions & 11 deletions test/agentchat/contrib/test_agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
from conftest import skip_openai as skip # noqa: E402
from conftest import reason, skip_openai # noqa: E402
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402

try:
import chromadb
import huggingface_hub
except ImportError:
skip = True
else:
skip = False

here = os.path.abspath(os.path.dirname(__file__))


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


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_build():
builder = AgentBuilder(
Expand Down Expand Up @@ -59,8 +67,8 @@ def test_build():


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai or skip,
reason=reason + "OR dependency not installed",
)
def test_build_from_library():
builder = AgentBuilder(
Expand Down Expand Up @@ -109,8 +117,8 @@ def test_build_from_library():


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_save():
builder = AgentBuilder(
Expand Down Expand Up @@ -143,8 +151,8 @@ def test_save():


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_load():
builder = AgentBuilder(
Expand All @@ -169,8 +177,8 @@ def test_load():


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_clear_agent():
builder = AgentBuilder(
Expand Down
17 changes: 10 additions & 7 deletions test/agentchat/contrib/test_agent_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import os
import sys

import pytest
from conftest import skip_openai as skip
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST

import autogen
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
from autogen import AssistantAgent, UserProxyAgent
from autogen.agentchat.contrib.agent_optimizer import AgentOptimizer

sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
from conftest import reason, skip_openai
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST

here = os.path.abspath(os.path.dirname(__file__))


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_record_conversation():
problem = "Simplify $\\sqrt[3]{1+8} \\cdot \\sqrt[3]{1+\\sqrt[3]{8}}"
Expand Down Expand Up @@ -54,8 +57,8 @@ def test_record_conversation():


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_step():
problem = "Simplify $\\sqrt[3]{1+8} \\cdot \\sqrt[3]{1+\\sqrt[3]{8}}"
Expand Down
44 changes: 22 additions & 22 deletions test/agentchat/contrib/test_gpt_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from autogen.oai.openai_utils import retrieve_assistants_by_name

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

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

if not skip:
if not skip_openai:
openai_config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
file_location=KEY_LOC,
Expand All @@ -45,17 +45,17 @@


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_config_list() -> None:
assert len(openai_config_list) > 0
assert len(aoai_config_list) > 0


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_gpt_assistant_chat() -> None:
for gpt_config in [openai_config_list, aoai_config_list]:
Expand Down Expand Up @@ -128,8 +128,8 @@ def ask_ossinsight(question: str) -> str:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_get_assistant_instructions() -> None:
for gpt_config in [openai_config_list, aoai_config_list]:
Expand Down Expand Up @@ -157,8 +157,8 @@ def _test_get_assistant_instructions(gpt_config) -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_gpt_assistant_instructions_overwrite() -> None:
for gpt_config in [openai_config_list, aoai_config_list]:
Expand Down Expand Up @@ -211,8 +211,8 @@ def _test_gpt_assistant_instructions_overwrite(gpt_config) -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_gpt_assistant_existing_no_instructions() -> None:
"""
Expand Down Expand Up @@ -251,8 +251,8 @@ def test_gpt_assistant_existing_no_instructions() -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_get_assistant_files() -> None:
"""
Expand Down Expand Up @@ -288,8 +288,8 @@ def test_get_assistant_files() -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_assistant_retrieval() -> None:
"""
Expand Down Expand Up @@ -365,8 +365,8 @@ def test_assistant_retrieval() -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_assistant_mismatch_retrieval() -> None:
"""Test function to check if the GPTAssistantAgent can filter out the mismatch assistant"""
Expand Down Expand Up @@ -487,8 +487,8 @@ def test_assistant_mismatch_retrieval() -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_gpt_assistant_tools_overwrite() -> None:
"""
Expand Down Expand Up @@ -609,8 +609,8 @@ def test_gpt_assistant_tools_overwrite() -> None:


@pytest.mark.skipif(
skip,
reason="requested to skip",
skip_openai,
reason=reason,
)
def test_gpt_reflection_with_llm() -> None:
gpt_assistant = GPTAssistantAgent(
Expand Down
15 changes: 4 additions & 11 deletions test/agentchat/contrib/test_web_surfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from autogen.oai.openai_utils import filter_config

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

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

try:
from openai import OpenAI
except ImportError:
skip_oai = True
else:
skip_oai = False or skip_openai

try:
BING_API_KEY = os.environ["BING_API_KEY"]
except KeyError:
skip_bing = True
else:
skip_bing = False

if not skip_oai:
if not skip_openai:
config_list = config_list_from_json(env_or_file=OAI_CONFIG_LIST, file_location=KEY_LOC)


Expand Down Expand Up @@ -104,8 +97,8 @@ def test_web_surfer() -> None:


@pytest.mark.skipif(
skip_oai,
reason="do not run if oai is not installed",
skip_all or skip_openai,
reason="dependency is not installed OR" + reason,
)
def test_web_surfer_oai() -> None:
llm_config = {"config_list": config_list, "timeout": 180, "cache_seed": 42}
Expand Down
8 changes: 6 additions & 2 deletions test/agentchat/test_agent_logging.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import json
import os
import sqlite3
import sys
import uuid

import pytest
from conftest import skip_openai
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST

import autogen
import autogen.runtime_logging

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))
from conftest import skip_openai # noqa: E402
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402

TEACHER_MESSAGE = """
You are roleplaying a math teacher, and your job is to help your students with linear algebra.
Keep your explanations short.
Expand Down
Loading
Loading