Skip to content

Commit

Permalink
Together AI Client (#2919)
Browse files Browse the repository at this point in the history
* First pass together.ai client class

* Config handling, models and cost

* Added tests, moved param management to create function

* Tests, parameter, validation, logging updates

* Added use of client_utils PR 2949

* Updated to return OAI response

* Notebook example

* Improved function calling, updated tests, updated notebook with Chess example

* Tidied up together client class, better parameter handling, simpler exception capture, warning for no cost, reuse in tests, cleaner tests

* Update of documentation notebook, replacement of old version

* Fix of messages parameter for hide_tools function call

* Update autogen/oai/together.py

Co-authored-by: Qingyun Wu <[email protected]>

* Update together.py to fix text

---------

Co-authored-by: Qingyun Wu <[email protected]>
Co-authored-by: Yiran Wu <[email protected]>
Co-authored-by: Chi Wang <[email protected]>
  • Loading branch information
4 people authored Jun 21, 2024
1 parent 843c343 commit b1ec3ae
Show file tree
Hide file tree
Showing 10 changed files with 1,701 additions and 185 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,43 @@ jobs:
with:
file: ./coverage.xml
flags: unittests

TogetherTest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
exclude:
- os: macos-latest
python-version: "3.9"
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 Together
run: |
pip install -e .[together,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_together.py --skip-openai
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
3 changes: 2 additions & 1 deletion autogen/logger/file_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from autogen.oai.anthropic import AnthropicClient
from autogen.oai.gemini import GeminiClient
from autogen.oai.mistral import MistralAIClient
from autogen.oai.together import TogetherClient

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -203,7 +204,7 @@ def log_new_wrapper(

def log_new_client(
self,
client: AzureOpenAI | OpenAI | GeminiClient | AnthropicClient | MistralAIClient,
client: AzureOpenAI | OpenAI | GeminiClient | AnthropicClient | MistralAIClient | TogetherClient,
wrapper: OpenAIWrapper,
init_args: Dict[str, Any],
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion autogen/logger/sqlite_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from autogen.oai.anthropic import AnthropicClient
from autogen.oai.gemini import GeminiClient
from autogen.oai.mistral import MistralAIClient
from autogen.oai.together import TogetherClient

logger = logging.getLogger(__name__)
lock = threading.Lock()
Expand Down Expand Up @@ -390,7 +391,7 @@ def log_function_use(self, source: Union[str, Agent], function: F, args: Dict[st

def log_new_client(
self,
client: Union[AzureOpenAI, OpenAI, GeminiClient, AnthropicClient, MistralAIClient],
client: Union[AzureOpenAI, OpenAI, GeminiClient, AnthropicClient, MistralAIClient, TogetherClient],
wrapper: OpenAIWrapper,
init_args: Dict[str, Any],
) -> None:
Expand Down
11 changes: 11 additions & 0 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
except ImportError as e:
mistral_import_exception = e

try:
from autogen.oai.together import TogetherClient

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

logger = logging.getLogger(__name__)
if not logger.handlers:
# Add the console handler.
Expand Down Expand Up @@ -473,6 +480,10 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s
raise ImportError("Please install `mistralai` to use the Mistral.AI API.")
client = MistralAIClient(**openai_config)
self._clients.append(client)
elif api_type is not None and api_type.startswith("together"):
if together_import_exception:
raise ImportError("Please install `together` to use the Together.AI API.")
self._clients.append(TogetherClient(**config))
else:
client = OpenAI(**openai_config)
self._clients.append(OpenAIClient(client))
Expand Down
Loading

0 comments on commit b1ec3ae

Please sign in to comment.