Skip to content

Commit

Permalink
feat: watsonx support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsinggggg committed Nov 8, 2024
1 parent 23c14bc commit 0e730ef
Show file tree
Hide file tree
Showing 8 changed files with 988 additions and 1 deletion.
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

0 comments on commit 0e730ef

Please sign in to comment.