From ac9f0c415049f6942981b2503152401984c35725 Mon Sep 17 00:00:00 2001 From: Mark Sze <66362098+marklysze@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:41:03 +1100 Subject: [PATCH 01/15] Update setup.py for python version support --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 735a89f07d..741803f17b 100644 --- a/setup.py +++ b/setup.py @@ -135,5 +135,5 @@ "Operating System :: OS Independent", ], license="Apache Software License 2.0", - python_requires=">=3.8,<3.13", + python_requires=">=3.8,<3.14", ) From e8f5e20e20eea815a956743623ef00ad696eaef6 Mon Sep 17 00:00:00 2001 From: Mark Sze <66362098+marklysze@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:42:21 +1100 Subject: [PATCH 02/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 396e669d1e..e2aa0dff71 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Find detailed instructions for users [here](https://ag2ai.github.io/ag2/docs/ins ### Option 2. Install AG2 Locally -AG2 requires **Python version >= 3.8, < 3.13**. It can be installed from pip: +AG2 requires **Python version >= 3.8, < 3.14**. It can be installed from pip: ```bash pip install ag2 From 33152cb1103382794419119b5a0a82f78e647c83 Mon Sep 17 00:00:00 2001 From: Mark Sze <66362098+marklysze@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:42:58 +1100 Subject: [PATCH 03/15] Update Installation.mdx --- website/docs/installation/Installation.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/installation/Installation.mdx b/website/docs/installation/Installation.mdx index 51f0e4cbbe..a74100fcd1 100644 --- a/website/docs/installation/Installation.mdx +++ b/website/docs/installation/Installation.mdx @@ -66,7 +66,7 @@ When installing AutoGen locally, we recommend using a virtual environment for th ## Install AutoGen -AutoGen requires **Python version >= 3.8, < 3.13**. It can be installed from pip: +AutoGen requires **Python version >= 3.8, < 3.14**. It can be installed from pip: ```bash pip install autogen From a3297dac1a9beb6d9a7be2ff151ba2c43f01fc80 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 18:56:19 +0000 Subject: [PATCH 04/15] Added support for Python 3.13 for testing --- .github/workflows/build.yml | 2 +- .github/workflows/contrib-openai.yml | 2 +- .github/workflows/contrib-tests.yml | 24 ++++++++++++------------ .github/workflows/openai.yml | 2 +- .github/workflows/type-check.yml | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a92044f15b..0bd7ee3d57 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.8" diff --git a/.github/workflows/contrib-openai.yml b/.github/workflows/contrib-openai.yml index 9a99caec96..5d74c59022 100644 --- a/.github/workflows/contrib-openai.yml +++ b/.github/workflows/contrib-openai.yml @@ -273,7 +273,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ["3.12"] + python-version: ["3.13"] runs-on: ${{ matrix.os }} environment: openai1 steps: diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index 9411222f87..2ac3bd34f0 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -239,7 +239,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.12"] + python-version: ["3.13"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -274,7 +274,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.12"] + python-version: ["3.13"] steps: - uses: actions/checkout@v4 with: @@ -300,7 +300,7 @@ jobs: run: | pytest test/agentchat/contrib/test_img_utils.py test/agentchat/contrib/test_lmm.py test/agentchat/contrib/test_llava.py test/agentchat/contrib/capabilities/test_vision_capability.py --skip-openai - name: Image Gen Coverage - if: ${{ matrix.os != 'windows-2019' && matrix.python-version != '3.12' }} + if: ${{ matrix.os != 'windows-2019' && matrix.python-version != '3.13' }} run: | pytest test/agentchat/contrib/capabilities/test_image_generation_capability.py --skip-openai - name: Upload coverage to Codecov @@ -315,7 +315,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -421,7 +421,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest", "windows-latest", "macos-latest"] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 @@ -463,7 +463,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -503,7 +503,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -543,7 +543,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -583,7 +583,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -622,7 +622,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 with: @@ -659,7 +659,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" @@ -699,7 +699,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-2019] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest python-version: "3.9" diff --git a/.github/workflows/openai.yml b/.github/workflows/openai.yml index a9ab8e9e0c..7dcf3175ba 100644 --- a/.github/workflows/openai.yml +++ b/.github/workflows/openai.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] runs-on: ${{ matrix.os }} environment: openai1 services: diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml index c66fb6ad7b..617dbe634c 100644 --- a/.github/workflows/type-check.yml +++ b/.github/workflows/type-check.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 2403d6b4aa7590b36ff58e594a5e2fabeb2adac5 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 21:30:04 +0000 Subject: [PATCH 05/15] Update of Windows MinGW for GCC version that numpy supports --- .github/workflows/contrib-tests.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index 2ac3bd34f0..a020212f9b 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -242,6 +242,18 @@ jobs: python-version: ["3.13"] steps: - uses: actions/checkout@v4 + - name: Setup MinGW (Windows) + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-gcc + mingw-w64-x86_64-gcc-fortran + - name: Check GCC version + if: runner.os == 'Windows' + run: gcc --version - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: From 5b7c8c3ecb35df6077bc6101e6e769c588a7078b Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 21:40:31 +0000 Subject: [PATCH 06/15] Further updates to change gcc version in action --- .github/workflows/contrib-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index a020212f9b..e522887691 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -251,6 +251,11 @@ jobs: install: >- mingw-w64-x86_64-gcc mingw-w64-x86_64-gcc-fortran + path-type: strict + location: D:\ + - name: Add MinGW to PATH + if: runner.os == 'Windows' + run: echo "D:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Check GCC version if: runner.os == 'Windows' run: gcc --version From a3ebbee35a780dc427920987bf4bfbb11dcb17e9 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 21:58:11 +0000 Subject: [PATCH 07/15] Changed windows-2019 runner to windows-latest --- .github/workflows/contrib-tests.yml | 47 +++++++++-------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index e522887691..9e93490ea7 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, windows-2019] + os: [macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11"] exclude: - os: macos-latest @@ -168,7 +168,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.10"] steps: - uses: actions/checkout@v4 @@ -203,7 +203,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.11"] steps: - uses: actions/checkout@v4 @@ -238,27 +238,10 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.13"] steps: - uses: actions/checkout@v4 - - name: Setup MinGW (Windows) - if: runner.os == 'Windows' - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW64 - update: true - install: >- - mingw-w64-x86_64-gcc - mingw-w64-x86_64-gcc-fortran - path-type: strict - location: D:\ - - name: Add MinGW to PATH - if: runner.os == 'Windows' - run: echo "D:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Check GCC version - if: runner.os == 'Windows' - run: gcc --version - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -290,7 +273,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.13"] steps: - uses: actions/checkout@v4 @@ -317,7 +300,7 @@ jobs: run: | pytest test/agentchat/contrib/test_img_utils.py test/agentchat/contrib/test_lmm.py test/agentchat/contrib/test_llava.py test/agentchat/contrib/capabilities/test_vision_capability.py --skip-openai - name: Image Gen Coverage - if: ${{ matrix.os != 'windows-2019' && matrix.python-version != '3.13' }} + if: ${{ matrix.os != 'windows-latest' && matrix.python-version != '3.13' }} run: | pytest test/agentchat/contrib/capabilities/test_image_generation_capability.py --skip-openai - name: Upload coverage to Codecov @@ -331,7 +314,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -371,7 +354,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.11"] steps: - uses: actions/checkout@v4 @@ -406,7 +389,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.11"] steps: - uses: actions/checkout@v4 @@ -479,7 +462,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -519,7 +502,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -559,7 +542,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -599,7 +582,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -675,7 +658,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -715,7 +698,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest From 6be11a42e29504bd52707f930435455b178e4861 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 22:17:09 +0000 Subject: [PATCH 08/15] Update to test numpy 2.1 install - WebSurfer --- .github/workflows/contrib-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index 9e93490ea7..82d3f44eb8 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -250,6 +250,8 @@ jobs: run: | python -m pip install --upgrade pip wheel pip install pytest-cov>=5 + pip install "numpy>=2.1.0" # Add this line + python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" # Verification - name: Install packages and dependencies for WebSurfer run: | pip install -e .[websurfer] From 73a081348bf2434924f916d4f247e9605de7f2e4 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 22:20:57 +0000 Subject: [PATCH 09/15] Separate numpy install --- .github/workflows/contrib-tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index 82d3f44eb8..b86f2ffd2f 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -250,11 +250,13 @@ jobs: run: | python -m pip install --upgrade pip wheel pip install pytest-cov>=5 - pip install "numpy>=2.1.0" # Add this line - python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" # Verification - name: Install packages and dependencies for WebSurfer run: | pip install -e .[websurfer] + - name: Upgrade NumPy for Python 3.13 support + run: | + pip install --upgrade "numpy>=2.1.0" + python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" - name: Set AUTOGEN_USE_DOCKER based on OS shell: bash run: | From 73ed8f6f7ea8e086d9443f1799131554264ec576 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 22:29:16 +0000 Subject: [PATCH 10/15] Update numpy to 2.1+ for Python 3.13 support --- setup.py | 2 +- test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 741803f17b..fb99646ce3 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ "termcolor", "flaml", # numpy is installed by flaml, but we want to pin the version to below 2.x (see https://github.com/microsoft/autogen/issues/1960) - "numpy>=1.17.0,<2", + "numpy>=2.1", # Note, updated to 2.1+ because 2.1 is the lowest version usable with Python 3.13 "python-dotenv", "tiktoken", # Disallowing 2.6.0 can be removed when this is fixed https://github.com/pydantic/pydantic/issues/8705 diff --git a/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py b/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py index 8814479da9..5b61454e9e 100644 --- a/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py +++ b/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py @@ -3,7 +3,7 @@ import pytest from conftest import reason, skip_openai # noqa: E402 from graphrag_sdk import KnowledgeGraph, Source -from graphrag_sdk.schema import Schema +from graphrag_sdk.ontology import Ontology try: from autogen.agentchat.contrib.graph_rag.document import ( @@ -34,7 +34,7 @@ def test_falkor_db_query_engine(): 3. Query it with a question and verify the result contains the critical information. """ # Arrange - test_schema = Schema() + test_schema = Ontology() actor = test_schema.add_entity("Actor").add_attribute("name", str, unique=True) movie = test_schema.add_entity("Movie").add_attribute("title", str, unique=True) test_schema.add_relation("ACTED", actor, movie) From cb7e881b1aeff429af2063adf1e1109ebbbf7914 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 22:36:17 +0000 Subject: [PATCH 11/15] Change to numpy version specific to python version --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fb99646ce3..435fa1a76c 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,8 @@ "termcolor", "flaml", # numpy is installed by flaml, but we want to pin the version to below 2.x (see https://github.com/microsoft/autogen/issues/1960) - "numpy>=2.1", # Note, updated to 2.1+ because 2.1 is the lowest version usable with Python 3.13 + "numpy>=2.1; python_version>='3.13'", # numpy 2.1+ required for Python 3.13 + "numpy>=1.24.0,<2.0.0; python_version<'3.13'", # numpy 1.24+ for older Python versions "python-dotenv", "tiktoken", # Disallowing 2.6.0 can be removed when this is fixed https://github.com/pydantic/pydantic/issues/8705 From ae43789911a01028e828b2511a607a0fb1a2a0e5 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 22:55:16 +0000 Subject: [PATCH 12/15] Testing LlamaIndex test fix --- .github/workflows/contrib-tests.yml | 4 ---- .../agentchat/contrib/llamaindex_conversable_agent.py | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index b86f2ffd2f..9e93490ea7 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -253,10 +253,6 @@ jobs: - name: Install packages and dependencies for WebSurfer run: | pip install -e .[websurfer] - - name: Upgrade NumPy for Python 3.13 support - run: | - pip install --upgrade "numpy>=2.1.0" - python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" - name: Set AUTOGEN_USE_DOCKER based on OS shell: bash run: | diff --git a/autogen/agentchat/contrib/llamaindex_conversable_agent.py b/autogen/agentchat/contrib/llamaindex_conversable_agent.py index b5bc79dec1..e883e76714 100644 --- a/autogen/agentchat/contrib/llamaindex_conversable_agent.py +++ b/autogen/agentchat/contrib/llamaindex_conversable_agent.py @@ -16,6 +16,15 @@ from llama_index.core.agent.runner.base import AgentRunner from llama_index.core.base.llms.types import ChatMessage from llama_index.core.chat_engine.types import AgentChatResponse + from pydantic import BaseModel + + # Add Pydantic configuration to allow arbitrary types + # Added to mitigate PydanticSchemaGenerationError + class Config: + arbitrary_types_allowed = True + + BaseModel.model_config = Config + except ImportError as e: logger.fatal("Failed to import llama-index. Try running 'pip install llama-index'") raise e From 9b281b1055b4d356faad41aa509f334befb3b224 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Wed, 20 Nov 2024 23:50:19 +0000 Subject: [PATCH 13/15] Changes to support json error message changes for Python 3.13 --- .../test_function_and_tool_calling.py | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/test/agentchat/test_function_and_tool_calling.py b/test/agentchat/test_function_and_tool_calling.py index cd7064cd7b..eaaea6a8a9 100644 --- a/test/agentchat/test_function_and_tool_calling.py +++ b/test/agentchat/test_function_and_tool_calling.py @@ -5,12 +5,16 @@ # Portions derived from https://github.com/microsoft/autogen are under the MIT License. # SPDX-License-Identifier: MIT import json +import sys from typing import Any, Callable, Dict, List import pytest from autogen.agentchat.conversable_agent import ConversableAgent +# Cater for Python version 3.13+ changes in json error messages +PYTHON131PLUS = sys.version_info >= (3, 13) + def _tool_func_1(arg1: str, arg2: str) -> str: return f"_tool_func_1: {arg1} {arg2}" @@ -107,6 +111,20 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4", } +# Python 3.13+ has different json error messages +_tool_use_message_1_bad_json_expected_reply_313 = { + "role": "tool", + "tool_responses": [ + { + "tool_call_id": "1", + "role": "tool", + "content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.", + }, + {"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"}, + ], + "content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4", +} + _tool_use_message_1_error_expected_reply = { "role": "tool", "tool_responses": [ @@ -163,6 +181,13 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.", } +# Python 3.13+ has different json error messages +_function_use_message_1_bad_json_expected_reply_313 = { + "name": "_tool_func_1", + "role": "function", + "content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.", +} + _function_use_message_1_error_expected_reply = { "name": "_tool_func_1", "role": "function", @@ -240,7 +265,14 @@ def test_generate_function_call_reply_on_function_call_message(is_function_async # bad JSON messages = [_function_use_message_1_bad_json] finished, retval = agent.generate_function_call_reply(messages) - assert (finished, retval) == (True, _function_use_message_1_bad_json_expected_reply) + assert (finished, retval) == ( + True, + ( + _function_use_message_1_bad_json_expected_reply_313 + if PYTHON131PLUS + else _function_use_message_1_bad_json_expected_reply + ), + ) # tool call messages = [_tool_use_message_1] @@ -282,7 +314,14 @@ async def test_a_generate_function_call_reply_on_function_call_message(is_functi # bad JSON messages = [_function_use_message_1_bad_json] finished, retval = await agent.a_generate_function_call_reply(messages) - assert (finished, retval) == (True, _function_use_message_1_bad_json_expected_reply) + assert (finished, retval) == ( + True, + ( + _function_use_message_1_bad_json_expected_reply_313 + if PYTHON131PLUS + else _function_use_message_1_bad_json_expected_reply + ), + ) # tool call messages = [_tool_use_message_1] @@ -323,7 +362,14 @@ def test_generate_tool_calls_reply_on_function_call_message(is_function_async: b # bad JSON messages = [_tool_use_message_1_bad_json] finished, retval = agent.generate_tool_calls_reply(messages) - assert (finished, retval) == (True, _tool_use_message_1_bad_json_expected_reply) + assert (finished, retval) == ( + True, + ( + _tool_use_message_1_bad_json_expected_reply_313 + if PYTHON131PLUS + else _tool_use_message_1_bad_json_expected_reply + ), + ) # function call messages = [_function_use_message_1] @@ -365,7 +411,14 @@ async def test_a_generate_tool_calls_reply_on_function_call_message(is_function_ # bad JSON messages = [_tool_use_message_1_bad_json] finished, retval = await agent.a_generate_tool_calls_reply(messages) - assert (finished, retval) == (True, _tool_use_message_1_bad_json_expected_reply) + assert (finished, retval) == ( + True, + ( + _tool_use_message_1_bad_json_expected_reply_313 + if PYTHON131PLUS + else _tool_use_message_1_bad_json_expected_reply + ), + ) # function call messages = [_function_use_message_1] From 731b3bd59bbdaf4ba708d2a4fa94ea714191de34 Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 21 Nov 2024 00:11:44 +0000 Subject: [PATCH 14/15] Added Python 3.13 to OpenAI tests --- test/test_notebook.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_notebook.py b/test/test_notebook.py index d6db43d711..2b09655a08 100755 --- a/test/test_notebook.py +++ b/test/test_notebook.py @@ -78,40 +78,40 @@ def test_agentchat_function_call(save=False): @pytest.mark.skipif( - skip or not sys.version.startswith("3.10"), - reason="do not run if openai is not installed or py!=3.10", + skip or not sys.version.startswith("3.13"), + reason="do not run if openai is not installed or py!=3.13", ) def test_agentchat_function_call_currency_calculator(save=False): run_notebook("agentchat_function_call_currency_calculator.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.11"), - reason="do not run if openai is not installed or py!=3.11", + skip or not sys.version.startswith("3.10"), + reason="do not run if openai is not installed or py!=3.10", ) def test_agentchat_function_call_async(save=False): run_notebook("agentchat_function_call_async.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.12"), - reason="do not run if openai is not installed or py!=3.12", + skip or not sys.version.startswith("3.11"), + reason="do not run if openai is not installed or py!=3.11", ) def _test_agentchat_MathChat(save=False): run_notebook("agentchat_MathChat.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.10"), - reason="do not run if openai is not installed or py!=3.10", + skip or not sys.version.startswith("3.12"), + reason="do not run if openai is not installed or py!=3.12", ) def _test_oai_chatgpt_gpt4(save=False): run_notebook("oai_chatgpt_gpt4.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.12"), - reason="do not run if openai is not installed or py!=3.12", + skip or not sys.version.startswith("3.13"), + reason="do not run if openai is not installed or py!=3.13", ) def test_agentchat_groupchat_finite_state_machine(save=False): run_notebook("agentchat_groupchat_finite_state_machine.ipynb", save=save) From e1a84027ff19bb3b09646a2b549f61d15c61b8eb Mon Sep 17 00:00:00 2001 From: Mark Sze Date: Thu, 21 Nov 2024 00:44:38 +0000 Subject: [PATCH 15/15] Update to OpenAI notebook tests --- test/test_notebook.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_notebook.py b/test/test_notebook.py index 2b09655a08..fb746a2ecb 100755 --- a/test/test_notebook.py +++ b/test/test_notebook.py @@ -54,8 +54,8 @@ def run_notebook(input_nb, output_nb="executed_openai_notebook.ipynb", save=Fals @pytest.mark.skipif( - skip or not sys.version.startswith("3.10"), - reason="do not run if openai is not installed or py!=3.10", + skip or not sys.version.startswith("3.13"), + reason="do not run if openai is not installed or py!=3.13", ) def test_agentchat_auto_feedback_from_code(save=False): run_notebook("agentchat_auto_feedback_from_code_execution.ipynb", save=save) @@ -78,48 +78,48 @@ def test_agentchat_function_call(save=False): @pytest.mark.skipif( - skip or not sys.version.startswith("3.13"), - reason="do not run if openai is not installed or py!=3.13", + skip or not sys.version.startswith("3.10"), + reason="do not run if openai is not installed or py!=3.10", ) def test_agentchat_function_call_currency_calculator(save=False): run_notebook("agentchat_function_call_currency_calculator.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.10"), - reason="do not run if openai is not installed or py!=3.10", + skip or not sys.version.startswith("3.13"), + reason="do not run if openai is not installed or py!=3.13", ) def test_agentchat_function_call_async(save=False): run_notebook("agentchat_function_call_async.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.11"), - reason="do not run if openai is not installed or py!=3.11", + skip or not sys.version.startswith("3.12"), + reason="do not run if openai is not installed or py!=3.12", ) def _test_agentchat_MathChat(save=False): run_notebook("agentchat_MathChat.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.12"), - reason="do not run if openai is not installed or py!=3.12", + skip or not sys.version.startswith("3.10"), + reason="do not run if openai is not installed or py!=3.10", ) def _test_oai_chatgpt_gpt4(save=False): run_notebook("oai_chatgpt_gpt4.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.13"), - reason="do not run if openai is not installed or py!=3.13", + skip or not sys.version.startswith("3.12"), + reason="do not run if openai is not installed or py!=3.12", ) def test_agentchat_groupchat_finite_state_machine(save=False): run_notebook("agentchat_groupchat_finite_state_machine.ipynb", save=save) @pytest.mark.skipif( - skip or not sys.version.startswith("3.10"), - reason="do not run if openai is not installed or py!=3.10", + skip or not sys.version.startswith("3.11"), + reason="do not run if openai is not installed or py!=3.11", ) def test_agentchat_cost_token_tracking(save=False): run_notebook("agentchat_cost_token_tracking.ipynb", save=save)