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

feat: watsonx support #4094

Open
wants to merge 2 commits into
base: 0.2
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -741,3 +741,39 @@ jobs:
with:
file: ./coverage.xml
flags: unittests

WatsonxTest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install packages and dependencies for all tests
run: |
python -m pip install --upgrade pip wheel
pip install pytest-cov>=5
- name: Install packages and dependencies for Watsonx
run: |
pip install -e .[watsonx,test]
- name: Set AUTOGEN_USE_DOCKER based on OS
shell: bash
run: |
if [[ ${{ matrix.os }} != ubuntu-latest ]]; then
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV
fi
- name: Coverage
run: |
pytest test/oai/test_watsonx.py --skip-openai
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
12 changes: 12 additions & 0 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@
except ImportError as e:
bedrock_import_exception = e

try:
from autogen.oai.watsonx import WatsonxClient

watsonx_import_exception: Optional[ImportError] = None
except ImportError as e:
watsonx_import_exception = e

logger = logging.getLogger(__name__)
if not logger.handlers:
# Add the console handler.
Expand Down Expand Up @@ -563,6 +570,11 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s
raise ImportError("Please install `boto3` to use the Amazon Bedrock API.")
client = BedrockClient(**openai_config)
self._clients.append(client)
elif api_type is not None and api_type.startswith("watsonx"):
if watsonx_import_exception:
raise ImportError("Please install `ibm-watsonx-ai` to use the Watsonx API.")
client = WatsonxClient(**openai_config)
self._clients.append(client)
else:
client = OpenAI(**openai_config)
self._clients.append(OpenAIClient(client))
Expand Down
2 changes: 1 addition & 1 deletion autogen/oai/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def validate_parameter(
allow_None: bool,
default_value: Any,
numerical_bound: Tuple,
allowed_values: list,
allowed_values: list | None,
) -> Any:
"""
Validates a given config parameter, checking its type, values, and setting defaults
Expand Down
Loading
Loading