Skip to content

Commit

Permalink
required deps cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davorrunje committed Feb 20, 2025
1 parent 8541b30 commit f5e2b3b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
"filename": "test/agentchat/contrib/test_img_utils.py",
"hashed_secret": "dcce26510eb892e4c25cd8fabf1778261002ae1e",
"is_verified": false,
"line_number": 40,
"line_number": 41,
"is_secret": false
}
],
Expand Down Expand Up @@ -1596,5 +1596,5 @@
}
]
},
"generated_at": "2025-02-20T13:06:27Z"
"generated_at": "2025-02-20T21:59:30Z"
}
4 changes: 2 additions & 2 deletions autogen/agentchat/contrib/vectordb/couchbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
from datetime import timedelta
from typing import Any, Callable, Literal, Optional

import numpy as np

from ....import_utils import optional_import_block, require_optional_import
from .base import Document, ItemID, QueryResults, VectorDB
from .utils import get_logger

with optional_import_block():
import numpy as np
from couchbase import search
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster, ClusterOptions
Expand All @@ -26,6 +25,7 @@
from couchbase.vector_search import VectorQuery, VectorSearch
from sentence_transformers import SentenceTransformer


logger = get_logger(__name__)

DEFAULT_BATCH_SIZE = 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
from typing import TYPE_CHECKING, Any, Callable, Optional

from ......doc_utils import export_module
from ......import_utils import optional_import_block, require_optional_import
from ...realtime_events import AudioDelta, FunctionCall, RealtimeEvent, SessionCreated
from ..realtime_client import RealtimeClientBase, Role, register_realtime_client

with optional_import_block():
from websockets.asyncio.client import connect


if TYPE_CHECKING:
from websockets.asyncio.client import ClientConnection

from ..realtime_client import RealtimeClientProtocol

from websockets.asyncio.client import connect

__all__ = ["GeminiRealtimeClient"]

global_logger = getLogger(__name__)
Expand All @@ -29,6 +32,7 @@


@register_realtime_client()
@require_optional_import("websockets", "gemini")
@export_module("autogen.agentchat.realtime.experimental.clients")
class GeminiRealtimeClient(RealtimeClientBase):
"""(Experimental) Client for Gemini Realtime API."""
Expand Down
3 changes: 0 additions & 3 deletions autogen/io/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ def __init__(self, websocket: ServerConnection) -> None:
Args:
websocket (ServerConnection): The websocket server.
Raises:
ImportError: If the websockets module is not available.
"""
self._websocket = websocket

Expand Down
5 changes: 3 additions & 2 deletions autogen/oai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from time import sleep
from typing import Any, Callable, Optional, Union

import numpy as np

from ..doc_utils import export_module

# Adding a NullHandler to silence FLAML log warning during
Expand All @@ -26,6 +24,7 @@
from ..import_utils import optional_import_block, require_optional_import

with optional_import_block() as result:
import numpy as np
from flaml import BlendSearch, tune
from flaml.tune.space import is_constant

Expand Down Expand Up @@ -362,6 +361,7 @@ def _get_params_for_create(cls, config: dict) -> dict:
return params

@classmethod
@require_optional_import("numpy", "flaml")
def _eval(cls, config: dict[str, Any], prune: bool = True, eval_only: bool = False):
"""Evaluate the given config as the hyperparameter setting for the openai api call.
Expand Down Expand Up @@ -919,6 +919,7 @@ def _construct_params(cls, context, config, prompt=None, messages=None, allow_fo
return params

@classmethod
@require_optional_import("numpy", "flaml")
def test(
cls,
data,
Expand Down
7 changes: 2 additions & 5 deletions autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import tempfile
import time
from copy import deepcopy
from distutils.version import LooseVersion
from pathlib import Path
from typing import Any, Optional, Union

from dotenv import find_dotenv, load_dotenv
from openai import OpenAI
from openai.types.beta.assistant import Assistant
from packaging.version import parse

from ..doc_utils import export_module

Expand Down Expand Up @@ -740,10 +740,7 @@ def retrieve_assistants_by_name(client: OpenAI, name: str) -> list[Assistant]:
def detect_gpt_assistant_api_version() -> str:
"""Detect the openai assistant API version"""
oai_version = importlib.metadata.version("openai")
if parse(oai_version) < parse("1.21"):
return "v1"
else:
return "v2"
return "v1" if LooseVersion(oai_version) < LooseVersion("1.21") else "v2"


def create_gpt_vector_store(client: OpenAI, name: str, fild_ids: list[str]) -> Any:
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ dependencies = [
"termcolor",
"python-dotenv",
"tiktoken",
"numpy",
# Disallowing 2.6.0 can be removed when this is fixed https://github.com/pydantic/pydantic/issues/8705
"pydantic>=2.6.1,<3",
"docker",
"packaging",
"websockets>=14,<15",
"asyncer==0.0.8",
"fast_depends>=2.4.12,<3",
"fast-depends>=2.4.12,<3",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -115,6 +112,7 @@ retrievechat-qdrant = [
retrievechat-couchbase = [
"pyautogen[retrievechat]",
"couchbase>=4.3.0",
"numpy",
]

graph-rag-falkor-db = [
Expand Down Expand Up @@ -180,8 +178,9 @@ gemini = [
"google-auth",
"pillow",
"jsonschema",
"jsonref>=1,<2"
"jsonref>=1,<2",
]

together = ["together>=1.2"]
websurfer = ["beautifulsoup4", "markdownify", "pdfminer.six", "pathvalidate"]
redis = ["redis"]
Expand Down
7 changes: 5 additions & 2 deletions test/agentchat/contrib/test_img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import unittest
from unittest.mock import patch

import numpy as np
import requests

from autogen.agentchat.contrib.img_utils import (
Expand All @@ -26,10 +25,12 @@
)
from autogen.import_utils import optional_import_block, skip_on_missing_imports

with optional_import_block():
import numpy as np

with optional_import_block() as result:
from PIL import Image


if result.is_successful:
raw_pil_image = Image.new("RGB", (10, 10), color="red")

Expand All @@ -47,6 +48,7 @@


@skip_on_missing_imports(["PIL"], "unknown")
@skip_on_missing_imports(["numpy"], "flaml")
class TestGetPilImage(unittest.TestCase):
def test_read_local_file(self):
# Create a small red image for testing
Expand All @@ -61,6 +63,7 @@ def test_read_pil(self):
self.assertTrue((np.array(raw_pil_image) == np.array(img2)).all())


@skip_on_missing_imports(["numpy"], "flaml")
def are_b64_images_equal(x: str, y: str):
"""Asserts that two base64 encoded images are equal."""
img1 = get_pil_image(x)
Expand Down

0 comments on commit f5e2b3b

Please sign in to comment.