From f675f177f2a35c40e43cbed42582da8be3c1d292 Mon Sep 17 00:00:00 2001 From: Jean-Malo Delignon <56539593+jean-malo@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:12:57 +0200 Subject: [PATCH] deps: compat with pydantic v1 --- .github/workflows/build_publish.yaml | 16 ++- poetry.lock | 155 +++++++----------------- pyproject.toml | 6 +- src/mistralai/client_base.py | 2 +- src/mistralai/jobs.py | 4 +- src/mistralai/models/base_model.py | 25 ++++ src/mistralai/models/chat_completion.py | 23 ++-- src/mistralai/models/common.py | 4 +- src/mistralai/models/embeddings.py | 7 +- src/mistralai/models/files.py | 8 +- src/mistralai/models/jobs.py | 28 +++-- src/mistralai/models/models.py | 8 +- tests/test_files.py | 6 +- tests/test_files_async.py | 6 +- tests/test_jobs.py | 6 +- tests/test_jobs_async.py | 6 +- 16 files changed, 138 insertions(+), 172 deletions(-) create mode 100644 src/mistralai/models/base_model.py diff --git a/.github/workflows/build_publish.yaml b/.github/workflows/build_publish.yaml index a696f10..d72e534 100644 --- a/.github/workflows/build_publish.yaml +++ b/.github/workflows/build_publish.yaml @@ -18,13 +18,22 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: [ + "3.9", + "3.10", + "3.11", + "3.12" + ] + pydantic-version: + [ + "^1.10,<2", + "^2,<3" + ] steps: # Checkout the repository - name: Checkout uses: actions/checkout@v4 - # Set python version to 3.11 - name: set python version uses: actions/setup-python@v4 with: @@ -35,7 +44,8 @@ jobs: run: | pip install poetry \ && poetry config virtualenvs.create false \ - && poetry install + && poetry install \ + && poetry add "pydantic==${{ matrix.pydantic-version }}" # Ruff - name: Ruff check diff --git a/poetry.lock b/poetry.lock index 636856c..3efae5b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,16 +1,5 @@ # This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. -[[package]] -name = "annotated-types" -version = "0.6.0" -description = "Reusable constraint types to use with typing.Annotated" -optional = false -python-versions = ">=3.8" -files = [ - {file = "annotated_types-0.6.0-py3-none-any.whl", hash = "sha256:0641064de18ba7a25dee8f96403ebc39113d0cb953a01429249d5c7564666a43"}, - {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, -] - [[package]] name = "anyio" version = "4.3.0" @@ -292,113 +281,55 @@ testing = ["pytest", "pytest-benchmark"] [[package]] name = "pydantic" -version = "2.6.4" -description = "Data validation using Python type hints" +version = "1.10.15" +description = "Data validation and settings management using python type hints" optional = false -python-versions = ">=3.8" +python-versions = ">=3.7" files = [ - {file = "pydantic-2.6.4-py3-none-any.whl", hash = "sha256:cc46fce86607580867bdc3361ad462bab9c222ef042d3da86f2fb333e1d916c5"}, - {file = "pydantic-2.6.4.tar.gz", hash = "sha256:b1704e0847db01817624a6b86766967f552dd9dbf3afba4004409f908dcc84e6"}, + {file = "pydantic-1.10.15-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:22ed12ee588b1df028a2aa5d66f07bf8f8b4c8579c2e96d5a9c1f96b77f3bb55"}, + {file = "pydantic-1.10.15-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:75279d3cac98186b6ebc2597b06bcbc7244744f6b0b44a23e4ef01e5683cc0d2"}, + {file = "pydantic-1.10.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:50f1666a9940d3d68683c9d96e39640f709d7a72ff8702987dab1761036206bb"}, + {file = "pydantic-1.10.15-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:82790d4753ee5d00739d6cb5cf56bceb186d9d6ce134aca3ba7befb1eedbc2c8"}, + {file = "pydantic-1.10.15-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:d207d5b87f6cbefbdb1198154292faee8017d7495a54ae58db06762004500d00"}, + {file = "pydantic-1.10.15-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e49db944fad339b2ccb80128ffd3f8af076f9f287197a480bf1e4ca053a866f0"}, + {file = "pydantic-1.10.15-cp310-cp310-win_amd64.whl", hash = "sha256:d3b5c4cbd0c9cb61bbbb19ce335e1f8ab87a811f6d589ed52b0254cf585d709c"}, + {file = "pydantic-1.10.15-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c3d5731a120752248844676bf92f25a12f6e45425e63ce22e0849297a093b5b0"}, + {file = "pydantic-1.10.15-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c365ad9c394f9eeffcb30a82f4246c0006417f03a7c0f8315d6211f25f7cb654"}, + {file = "pydantic-1.10.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3287e1614393119c67bd4404f46e33ae3be3ed4cd10360b48d0a4459f420c6a3"}, + {file = "pydantic-1.10.15-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:be51dd2c8596b25fe43c0a4a59c2bee4f18d88efb8031188f9e7ddc6b469cf44"}, + {file = "pydantic-1.10.15-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:6a51a1dd4aa7b3f1317f65493a182d3cff708385327c1c82c81e4a9d6d65b2e4"}, + {file = "pydantic-1.10.15-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:4e316e54b5775d1eb59187f9290aeb38acf620e10f7fd2f776d97bb788199e53"}, + {file = "pydantic-1.10.15-cp311-cp311-win_amd64.whl", hash = "sha256:0d142fa1b8f2f0ae11ddd5e3e317dcac060b951d605fda26ca9b234b92214986"}, + {file = "pydantic-1.10.15-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7ea210336b891f5ea334f8fc9f8f862b87acd5d4a0cbc9e3e208e7aa1775dabf"}, + {file = "pydantic-1.10.15-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3453685ccd7140715e05f2193d64030101eaad26076fad4e246c1cc97e1bb30d"}, + {file = "pydantic-1.10.15-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9bea1f03b8d4e8e86702c918ccfd5d947ac268f0f0cc6ed71782e4b09353b26f"}, + {file = "pydantic-1.10.15-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:005655cabc29081de8243126e036f2065bd7ea5b9dff95fde6d2c642d39755de"}, + {file = "pydantic-1.10.15-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:af9850d98fc21e5bc24ea9e35dd80a29faf6462c608728a110c0a30b595e58b7"}, + {file = "pydantic-1.10.15-cp37-cp37m-win_amd64.whl", hash = "sha256:d31ee5b14a82c9afe2bd26aaa405293d4237d0591527d9129ce36e58f19f95c1"}, + {file = "pydantic-1.10.15-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:5e09c19df304b8123938dc3c53d3d3be6ec74b9d7d0d80f4f4b5432ae16c2022"}, + {file = "pydantic-1.10.15-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7ac9237cd62947db00a0d16acf2f3e00d1ae9d3bd602b9c415f93e7a9fc10528"}, + {file = "pydantic-1.10.15-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:584f2d4c98ffec420e02305cf675857bae03c9d617fcfdc34946b1160213a948"}, + {file = "pydantic-1.10.15-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bbc6989fad0c030bd70a0b6f626f98a862224bc2b1e36bfc531ea2facc0a340c"}, + {file = "pydantic-1.10.15-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d573082c6ef99336f2cb5b667b781d2f776d4af311574fb53d908517ba523c22"}, + {file = "pydantic-1.10.15-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6bd7030c9abc80134087d8b6e7aa957e43d35714daa116aced57269a445b8f7b"}, + {file = "pydantic-1.10.15-cp38-cp38-win_amd64.whl", hash = "sha256:3350f527bb04138f8aff932dc828f154847fbdc7a1a44c240fbfff1b57f49a12"}, + {file = "pydantic-1.10.15-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:51d405b42f1b86703555797270e4970a9f9bd7953f3990142e69d1037f9d9e51"}, + {file = "pydantic-1.10.15-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a980a77c52723b0dc56640ced396b73a024d4b74f02bcb2d21dbbac1debbe9d0"}, + {file = "pydantic-1.10.15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:67f1a1fb467d3f49e1708a3f632b11c69fccb4e748a325d5a491ddc7b5d22383"}, + {file = "pydantic-1.10.15-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:676ed48f2c5bbad835f1a8ed8a6d44c1cd5a21121116d2ac40bd1cd3619746ed"}, + {file = "pydantic-1.10.15-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:92229f73400b80c13afcd050687f4d7e88de9234d74b27e6728aa689abcf58cc"}, + {file = "pydantic-1.10.15-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:2746189100c646682eff0bce95efa7d2e203420d8e1c613dc0c6b4c1d9c1fde4"}, + {file = "pydantic-1.10.15-cp39-cp39-win_amd64.whl", hash = "sha256:394f08750bd8eaad714718812e7fab615f873b3cdd0b9d84e76e51ef3b50b6b7"}, + {file = "pydantic-1.10.15-py3-none-any.whl", hash = "sha256:28e552a060ba2740d0d2aabe35162652c1459a0b9069fe0db7f4ee0e18e74d58"}, + {file = "pydantic-1.10.15.tar.gz", hash = "sha256:ca832e124eda231a60a041da4f013e3ff24949d94a01154b137fc2f2a43c3ffb"}, ] [package.dependencies] -annotated-types = ">=0.4.0" -pydantic-core = "2.16.3" -typing-extensions = ">=4.6.1" +typing-extensions = ">=4.2.0" [package.extras] -email = ["email-validator (>=2.0.0)"] - -[[package]] -name = "pydantic-core" -version = "2.16.3" -description = "" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pydantic_core-2.16.3-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:75b81e678d1c1ede0785c7f46690621e4c6e63ccd9192af1f0bd9d504bbb6bf4"}, - {file = "pydantic_core-2.16.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9c865a7ee6f93783bd5d781af5a4c43dadc37053a5b42f7d18dc019f8c9d2bd1"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:162e498303d2b1c036b957a1278fa0899d02b2842f1ff901b6395104c5554a45"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2f583bd01bbfbff4eaee0868e6fc607efdfcc2b03c1c766b06a707abbc856187"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b926dd38db1519ed3043a4de50214e0d600d404099c3392f098a7f9d75029ff8"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:716b542728d4c742353448765aa7cdaa519a7b82f9564130e2b3f6766018c9ec"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fc4ad7f7ee1a13d9cb49d8198cd7d7e3aa93e425f371a68235f784e99741561f"}, - {file = "pydantic_core-2.16.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:bd87f48924f360e5d1c5f770d6155ce0e7d83f7b4e10c2f9ec001c73cf475c99"}, - {file = "pydantic_core-2.16.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:0df446663464884297c793874573549229f9eca73b59360878f382a0fc085979"}, - {file = "pydantic_core-2.16.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:4df8a199d9f6afc5ae9a65f8f95ee52cae389a8c6b20163762bde0426275b7db"}, - {file = "pydantic_core-2.16.3-cp310-none-win32.whl", hash = "sha256:456855f57b413f077dff513a5a28ed838dbbb15082ba00f80750377eed23d132"}, - {file = "pydantic_core-2.16.3-cp310-none-win_amd64.whl", hash = "sha256:732da3243e1b8d3eab8c6ae23ae6a58548849d2e4a4e03a1924c8ddf71a387cb"}, - {file = "pydantic_core-2.16.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:519ae0312616026bf4cedc0fe459e982734f3ca82ee8c7246c19b650b60a5ee4"}, - {file = "pydantic_core-2.16.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:b3992a322a5617ded0a9f23fd06dbc1e4bd7cf39bc4ccf344b10f80af58beacd"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8d62da299c6ecb04df729e4b5c52dc0d53f4f8430b4492b93aa8de1f541c4aac"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2acca2be4bb2f2147ada8cac612f8a98fc09f41c89f87add7256ad27332c2fda"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1b662180108c55dfbf1280d865b2d116633d436cfc0bba82323554873967b340"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e7c6ed0dc9d8e65f24f5824291550139fe6f37fac03788d4580da0d33bc00c97"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a6b1bb0827f56654b4437955555dc3aeeebeddc47c2d7ed575477f082622c49e"}, - {file = "pydantic_core-2.16.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:e56f8186d6210ac7ece503193ec84104da7ceb98f68ce18c07282fcc2452e76f"}, - {file = "pydantic_core-2.16.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:936e5db01dd49476fa8f4383c259b8b1303d5dd5fb34c97de194560698cc2c5e"}, - {file = "pydantic_core-2.16.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:33809aebac276089b78db106ee692bdc9044710e26f24a9a2eaa35a0f9fa70ba"}, - {file = "pydantic_core-2.16.3-cp311-none-win32.whl", hash = "sha256:ded1c35f15c9dea16ead9bffcde9bb5c7c031bff076355dc58dcb1cb436c4721"}, - {file = "pydantic_core-2.16.3-cp311-none-win_amd64.whl", hash = "sha256:d89ca19cdd0dd5f31606a9329e309d4fcbb3df860960acec32630297d61820df"}, - {file = "pydantic_core-2.16.3-cp311-none-win_arm64.whl", hash = "sha256:6162f8d2dc27ba21027f261e4fa26f8bcb3cf9784b7f9499466a311ac284b5b9"}, - {file = "pydantic_core-2.16.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:0f56ae86b60ea987ae8bcd6654a887238fd53d1384f9b222ac457070b7ac4cff"}, - {file = "pydantic_core-2.16.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c9bd22a2a639e26171068f8ebb5400ce2c1bc7d17959f60a3b753ae13c632975"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4204e773b4b408062960e65468d5346bdfe139247ee5f1ca2a378983e11388a2"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f651dd19363c632f4abe3480a7c87a9773be27cfe1341aef06e8759599454120"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:aaf09e615a0bf98d406657e0008e4a8701b11481840be7d31755dc9f97c44053"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8e47755d8152c1ab5b55928ab422a76e2e7b22b5ed8e90a7d584268dd49e9c6b"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:500960cb3a0543a724a81ba859da816e8cf01b0e6aaeedf2c3775d12ee49cade"}, - {file = "pydantic_core-2.16.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:cf6204fe865da605285c34cf1172879d0314ff267b1c35ff59de7154f35fdc2e"}, - {file = "pydantic_core-2.16.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d33dd21f572545649f90c38c227cc8631268ba25c460b5569abebdd0ec5974ca"}, - {file = "pydantic_core-2.16.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:49d5d58abd4b83fb8ce763be7794d09b2f50f10aa65c0f0c1696c677edeb7cbf"}, - {file = "pydantic_core-2.16.3-cp312-none-win32.whl", hash = "sha256:f53aace168a2a10582e570b7736cc5bef12cae9cf21775e3eafac597e8551fbe"}, - {file = "pydantic_core-2.16.3-cp312-none-win_amd64.whl", hash = "sha256:0d32576b1de5a30d9a97f300cc6a3f4694c428d956adbc7e6e2f9cad279e45ed"}, - {file = "pydantic_core-2.16.3-cp312-none-win_arm64.whl", hash = "sha256:ec08be75bb268473677edb83ba71e7e74b43c008e4a7b1907c6d57e940bf34b6"}, - {file = "pydantic_core-2.16.3-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:b1f6f5938d63c6139860f044e2538baeee6f0b251a1816e7adb6cbce106a1f01"}, - {file = "pydantic_core-2.16.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:2a1ef6a36fdbf71538142ed604ad19b82f67b05749512e47f247a6ddd06afdc7"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:704d35ecc7e9c31d48926150afada60401c55efa3b46cd1ded5a01bdffaf1d48"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d937653a696465677ed583124b94a4b2d79f5e30b2c46115a68e482c6a591c8a"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c9803edf8e29bd825f43481f19c37f50d2b01899448273b3a7758441b512acf8"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:72282ad4892a9fb2da25defeac8c2e84352c108705c972db82ab121d15f14e6d"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7f752826b5b8361193df55afcdf8ca6a57d0232653494ba473630a83ba50d8c9"}, - {file = "pydantic_core-2.16.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4384a8f68ddb31a0b0c3deae88765f5868a1b9148939c3f4121233314ad5532c"}, - {file = "pydantic_core-2.16.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:a4b2bf78342c40b3dc830880106f54328928ff03e357935ad26c7128bbd66ce8"}, - {file = "pydantic_core-2.16.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:13dcc4802961b5f843a9385fc821a0b0135e8c07fc3d9949fd49627c1a5e6ae5"}, - {file = "pydantic_core-2.16.3-cp38-none-win32.whl", hash = "sha256:e3e70c94a0c3841e6aa831edab1619ad5c511199be94d0c11ba75fe06efe107a"}, - {file = "pydantic_core-2.16.3-cp38-none-win_amd64.whl", hash = "sha256:ecdf6bf5f578615f2e985a5e1f6572e23aa632c4bd1dc67f8f406d445ac115ed"}, - {file = "pydantic_core-2.16.3-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:bda1ee3e08252b8d41fa5537413ffdddd58fa73107171a126d3b9ff001b9b820"}, - {file = "pydantic_core-2.16.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:21b888c973e4f26b7a96491c0965a8a312e13be108022ee510248fe379a5fa23"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:be0ec334369316fa73448cc8c982c01e5d2a81c95969d58b8f6e272884df0074"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b5b6079cc452a7c53dd378c6f881ac528246b3ac9aae0f8eef98498a75657805"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7ee8d5f878dccb6d499ba4d30d757111847b6849ae07acdd1205fffa1fc1253c"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7233d65d9d651242a68801159763d09e9ec96e8a158dbf118dc090cd77a104c9"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c6119dc90483a5cb50a1306adb8d52c66e447da88ea44f323e0ae1a5fcb14256"}, - {file = "pydantic_core-2.16.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:578114bc803a4c1ff9946d977c221e4376620a46cf78da267d946397dc9514a8"}, - {file = "pydantic_core-2.16.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d8f99b147ff3fcf6b3cc60cb0c39ea443884d5559a30b1481e92495f2310ff2b"}, - {file = "pydantic_core-2.16.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:4ac6b4ce1e7283d715c4b729d8f9dab9627586dafce81d9eaa009dd7f25dd972"}, - {file = "pydantic_core-2.16.3-cp39-none-win32.whl", hash = "sha256:e7774b570e61cb998490c5235740d475413a1f6de823169b4cf94e2fe9e9f6b2"}, - {file = "pydantic_core-2.16.3-cp39-none-win_amd64.whl", hash = "sha256:9091632a25b8b87b9a605ec0e61f241c456e9248bfdcf7abdf344fdb169c81cf"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:36fa178aacbc277bc6b62a2c3da95226520da4f4e9e206fdf076484363895d2c"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:dcca5d2bf65c6fb591fff92da03f94cd4f315972f97c21975398bd4bd046854a"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2a72fb9963cba4cd5793854fd12f4cfee731e86df140f59ff52a49b3552db241"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b60cc1a081f80a2105a59385b92d82278b15d80ebb3adb200542ae165cd7d183"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:cbcc558401de90a746d02ef330c528f2e668c83350f045833543cd57ecead1ad"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:fee427241c2d9fb7192b658190f9f5fd6dfe41e02f3c1489d2ec1e6a5ab1e04a"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:f4cb85f693044e0f71f394ff76c98ddc1bc0953e48c061725e540396d5c8a2e1"}, - {file = "pydantic_core-2.16.3-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:b29eeb887aa931c2fcef5aa515d9d176d25006794610c264ddc114c053bf96fe"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:a425479ee40ff021f8216c9d07a6a3b54b31c8267c6e17aa88b70d7ebd0e5e5b"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:5c5cbc703168d1b7a838668998308018a2718c2130595e8e190220238addc96f"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:99b6add4c0b39a513d323d3b93bc173dac663c27b99860dd5bf491b240d26137"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:75f76ee558751746d6a38f89d60b6228fa174e5172d143886af0f85aa306fd89"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:00ee1c97b5364b84cb0bd82e9bbf645d5e2871fb8c58059d158412fee2d33d8a"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:287073c66748f624be4cef893ef9174e3eb88fe0b8a78dc22e88eca4bc357ca6"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:ed25e1835c00a332cb10c683cd39da96a719ab1dfc08427d476bce41b92531fc"}, - {file = "pydantic_core-2.16.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:86b3d0033580bd6bbe07590152007275bd7af95f98eaa5bd36f3da219dcd93da"}, - {file = "pydantic_core-2.16.3.tar.gz", hash = "sha256:1cac689f80a3abab2d3c0048b29eea5751114054f032a941a32de4c852c59cad"}, -] - -[package.dependencies] -typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +dotenv = ["python-dotenv (>=0.10.4)"] +email = ["email-validator (>=1.0.3)"] [[package]] name = "pytest" @@ -533,4 +464,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.9,<4.0" -content-hash = "015db2d023aef624cb1df559074f6e3760d4029e637d3f259f5d2c76730b8d6a" +content-hash = "f6b7f4def0a3ee5555c198dfa0f88ad6f0ee67a98c6217e13eed22004f21a278" diff --git a/pyproject.toml b/pyproject.toml index f6b31b0..ed6a7d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mistralai" -version = "0.4.0" +version = "0.4.1" description = "" authors = ["Bam4d "] readme = "README.md" @@ -18,14 +18,14 @@ disallow_untyped_defs = true show_error_codes = true no_implicit_optional = true warn_return_any = true -warn_unused_ignores = true +warn_unused_ignores = false exclude = ["docs", "tests", "examples", "tools", "build"] [tool.poetry.dependencies] python = "^3.9,<4.0" orjson = "^3.9.10,<3.11" -pydantic = "^2.5.2,<3" +pydantic = "^1.10,<3" httpx = "^0.25,<1" diff --git a/src/mistralai/client_base.py b/src/mistralai/client_base.py index 9fb107b..7160bcd 100644 --- a/src/mistralai/client_base.py +++ b/src/mistralai/client_base.py @@ -58,7 +58,7 @@ def _parse_tool_choice(self, tool_choice: Union[str, ToolChoice]) -> str: return tool_choice.value return tool_choice - def _parse_response_format(self, response_format: Union[Dict[str, Any], ResponseFormat]) -> Dict[str, Any]: + def _parse_response_format(self, response_format: Union[Dict[str, Any], ResponseFormat]) -> Any: if isinstance(response_format, ResponseFormat): return response_format.model_dump(exclude_none=True) return response_format diff --git a/src/mistralai/jobs.py b/src/mistralai/jobs.py index 115b232..717cdff 100644 --- a/src/mistralai/jobs.py +++ b/src/mistralai/jobs.py @@ -37,7 +37,7 @@ def create( "model": model, "training_files": training_files, "validation_files": validation_files, - "hyperparameters": hyperparameters.dict(), + "hyperparameters": hyperparameters.model_dump(), "suffix": suffix, "integrations": integrations, }, @@ -120,7 +120,7 @@ async def create( "model": model, "training_files": training_files, "validation_files": validation_files, - "hyperparameters": hyperparameters.dict(), + "hyperparameters": hyperparameters.model_dump(), "suffix": suffix, "integrations": integrations, }, diff --git a/src/mistralai/models/base_model.py b/src/mistralai/models/base_model.py new file mode 100644 index 0000000..59deaaa --- /dev/null +++ b/src/mistralai/models/base_model.py @@ -0,0 +1,25 @@ +from typing import Any, TypeVar + +import pydantic +from pydantic import BaseModel + +Model = TypeVar("Model", bound="BaseModel") +IS_V1 = pydantic.VERSION.startswith("1.") + + +class BackwardCompatibleBaseModel(BaseModel): + def model_dump(self, *args: Any, **kwargs: Any) -> Any: + if IS_V1: + return self.dict(*args, **kwargs) + return super().model_dump(*args, **kwargs) # type: ignore + + @classmethod + def model_validate_json(cls: type[Model], *args: Any, **kwargs: Any) -> Model: + if IS_V1: + return cls.parse_raw(*args, **kwargs) + return super().model_validate_json(*args, **kwargs) # type: ignore + + def model_dump_json(self, *args: Any, **kwargs: Any) -> str: + if IS_V1: + return self.json(*args, **kwargs) + return super().model_dump_json(*args, **kwargs) # type: ignore diff --git a/src/mistralai/models/chat_completion.py b/src/mistralai/models/chat_completion.py index c5eda5a..1dcc180 100644 --- a/src/mistralai/models/chat_completion.py +++ b/src/mistralai/models/chat_completion.py @@ -1,12 +1,11 @@ from enum import Enum from typing import List, Optional -from pydantic import BaseModel - +from mistralai.models.base_model import BackwardCompatibleBaseModel from mistralai.models.common import UsageInfo -class Function(BaseModel): +class Function(BackwardCompatibleBaseModel): name: str description: str parameters: dict @@ -16,12 +15,12 @@ class ToolType(str, Enum): function = "function" -class FunctionCall(BaseModel): +class FunctionCall(BackwardCompatibleBaseModel): name: str arguments: str -class ToolCall(BaseModel): +class ToolCall(BackwardCompatibleBaseModel): id: str = "null" type: ToolType = ToolType.function function: FunctionCall @@ -38,11 +37,11 @@ class ToolChoice(str, Enum): none: str = "none" -class ResponseFormat(BaseModel): +class ResponseFormat(BackwardCompatibleBaseModel): type: ResponseFormats = ResponseFormats.text -class ChatMessage(BaseModel): +class ChatMessage(BackwardCompatibleBaseModel): role: str content: str name: Optional[str] = None @@ -50,7 +49,7 @@ class ChatMessage(BaseModel): tool_call_id: Optional[str] = None -class DeltaMessage(BaseModel): +class DeltaMessage(BackwardCompatibleBaseModel): role: Optional[str] = None content: Optional[str] = None tool_calls: Optional[List[ToolCall]] = None @@ -63,13 +62,13 @@ class FinishReason(str, Enum): tool_calls = "tool_calls" -class ChatCompletionResponseStreamChoice(BaseModel): +class ChatCompletionResponseStreamChoice(BackwardCompatibleBaseModel): index: int delta: DeltaMessage finish_reason: Optional[FinishReason] -class ChatCompletionStreamResponse(BaseModel): +class ChatCompletionStreamResponse(BackwardCompatibleBaseModel): id: str model: str choices: List[ChatCompletionResponseStreamChoice] @@ -78,13 +77,13 @@ class ChatCompletionStreamResponse(BaseModel): usage: Optional[UsageInfo] = None -class ChatCompletionResponseChoice(BaseModel): +class ChatCompletionResponseChoice(BackwardCompatibleBaseModel): index: int message: ChatMessage finish_reason: Optional[FinishReason] -class ChatCompletionResponse(BaseModel): +class ChatCompletionResponse(BackwardCompatibleBaseModel): id: str object: str created: int diff --git a/src/mistralai/models/common.py b/src/mistralai/models/common.py index 11b71e5..30652d0 100644 --- a/src/mistralai/models/common.py +++ b/src/mistralai/models/common.py @@ -1,9 +1,9 @@ from typing import Optional -from pydantic import BaseModel +from mistralai.models.base_model import BackwardCompatibleBaseModel -class UsageInfo(BaseModel): +class UsageInfo(BackwardCompatibleBaseModel): prompt_tokens: int total_tokens: int completion_tokens: Optional[int] diff --git a/src/mistralai/models/embeddings.py b/src/mistralai/models/embeddings.py index a3200f7..b4ee740 100644 --- a/src/mistralai/models/embeddings.py +++ b/src/mistralai/models/embeddings.py @@ -1,17 +1,16 @@ from typing import List -from pydantic import BaseModel - +from mistralai.models.base_model import BackwardCompatibleBaseModel from mistralai.models.common import UsageInfo -class EmbeddingObject(BaseModel): +class EmbeddingObject(BackwardCompatibleBaseModel): object: str embedding: List[float] index: int -class EmbeddingResponse(BaseModel): +class EmbeddingResponse(BackwardCompatibleBaseModel): id: str object: str data: List[EmbeddingObject] diff --git a/src/mistralai/models/files.py b/src/mistralai/models/files.py index f0aeff3..9191584 100644 --- a/src/mistralai/models/files.py +++ b/src/mistralai/models/files.py @@ -1,9 +1,9 @@ from typing import Literal, Optional -from pydantic import BaseModel +from mistralai.models.base_model import BackwardCompatibleBaseModel -class FileObject(BaseModel): +class FileObject(BackwardCompatibleBaseModel): id: str object: str bytes: int @@ -12,12 +12,12 @@ class FileObject(BaseModel): purpose: Optional[Literal["fine-tune"]] = "fine-tune" -class FileDeleted(BaseModel): +class FileDeleted(BackwardCompatibleBaseModel): id: str object: str deleted: bool -class Files(BaseModel): +class Files(BackwardCompatibleBaseModel): data: list[FileObject] object: Literal["list"] diff --git a/src/mistralai/models/jobs.py b/src/mistralai/models/jobs.py index 8006533..26e73f2 100644 --- a/src/mistralai/models/jobs.py +++ b/src/mistralai/models/jobs.py @@ -1,15 +1,17 @@ from datetime import datetime -from typing import Annotated, List, Literal, Optional, Union +from typing import List, Literal, Optional, Union -from pydantic import BaseModel, Field +from pydantic import Field +from mistralai.models.base_model import BackwardCompatibleBaseModel -class TrainingParameters(BaseModel): + +class TrainingParameters(BackwardCompatibleBaseModel): training_steps: int = Field(1800, le=10000, ge=1) learning_rate: float = Field(1.0e-4, le=1, ge=1.0e-8) -class WandbIntegration(BaseModel): +class WandbIntegration(BackwardCompatibleBaseModel): type: Literal["wandb"] = "wandb" project: str name: Union[str, None] = None @@ -20,11 +22,11 @@ class WandbIntegrationIn(WandbIntegration): api_key: str -Integration = Annotated[Union[WandbIntegration], Field(discriminator="type")] -IntegrationIn = Annotated[Union[WandbIntegrationIn], Field(discriminator="type")] +Integration = Union[WandbIntegration] +IntegrationIn = Union[WandbIntegrationIn] -class JobMetadata(BaseModel): +class JobMetadata(BackwardCompatibleBaseModel): object: Literal["job.metadata"] = "job.metadata" training_steps: int train_tokens_per_step: int @@ -34,7 +36,7 @@ class JobMetadata(BaseModel): expected_duration_seconds: Optional[int] -class Job(BaseModel): +class Job(BackwardCompatibleBaseModel): id: str hyperparameters: TrainingParameters fine_tuned_model: Union[str, None] @@ -57,25 +59,25 @@ class Job(BaseModel): integrations: List[Integration] = [] -class Event(BaseModel): +class Event(BackwardCompatibleBaseModel): name: str data: Union[dict, None] = None created_at: int -class Metric(BaseModel): +class Metric(BackwardCompatibleBaseModel): train_loss: Union[float, None] = None valid_loss: Union[float, None] = None valid_mean_token_accuracy: Union[float, None] = None -class Checkpoint(BaseModel): +class Checkpoint(BackwardCompatibleBaseModel): metrics: Metric step_number: int created_at: int -class JobQueryFilter(BaseModel): +class JobQueryFilter(BackwardCompatibleBaseModel): page: int = 0 page_size: int = 100 model: Optional[str] = None @@ -93,6 +95,6 @@ class DetailedJob(Job): estimated_start_time: Optional[int] = None -class Jobs(BaseModel): +class Jobs(BackwardCompatibleBaseModel): data: list[Job] = [] object: Literal["list"] diff --git a/src/mistralai/models/models.py b/src/mistralai/models/models.py index 8ed152d..7d7262a 100644 --- a/src/mistralai/models/models.py +++ b/src/mistralai/models/models.py @@ -1,9 +1,9 @@ from typing import List, Optional -from pydantic import BaseModel +from mistralai.models.base_model import BackwardCompatibleBaseModel -class ModelPermission(BaseModel): +class ModelPermission(BackwardCompatibleBaseModel): id: str object: str created: int @@ -18,7 +18,7 @@ class ModelPermission(BaseModel): is_blocking: Optional[bool] = False -class ModelCard(BaseModel): +class ModelCard(BackwardCompatibleBaseModel): id: str object: str created: int @@ -28,6 +28,6 @@ class ModelCard(BaseModel): permission: List[ModelPermission] = [] -class ModelList(BaseModel): +class ModelList(BackwardCompatibleBaseModel): object: str data: List[ModelCard] diff --git a/tests/test_files.py b/tests/test_files.py index e4ef9e4..f399a08 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -13,7 +13,7 @@ def test_create_file(self, client): expected_response_file = FileObject.model_validate_json(mock_file_response_payload()) client._client.request.return_value = mock_response( 200, - expected_response_file.json(), + expected_response_file.model_dump_json(), ) response_file = client.files.create(b"file_content") @@ -36,7 +36,7 @@ def test_retrieve(self, client): expected_response_file = FileObject.model_validate_json(mock_file_response_payload()) client._client.request.return_value = mock_response( 200, - expected_response_file.json(), + expected_response_file.model_dump_json(), ) response_file = client.files.retrieve("file_id") @@ -86,7 +86,7 @@ def test_list_files(self, client): def test_delete_file(self, client): expected_response_file = FileDeleted.model_validate_json(mock_file_deleted_response_payload()) - client._client.request.return_value = mock_response(200, expected_response_file.json()) + client._client.request.return_value = mock_response(200, expected_response_file.model_dump_json()) response_file = client.files.delete("file_id") diff --git a/tests/test_files_async.py b/tests/test_files_async.py index 7248f40..00fb82f 100644 --- a/tests/test_files_async.py +++ b/tests/test_files_async.py @@ -15,7 +15,7 @@ async def test_create_file(self, async_client): expected_response_file = FileObject.model_validate_json(mock_file_response_payload()) async_client._client.request.return_value = mock_response( 200, - expected_response_file.json(), + expected_response_file.model_dump_json(), ) response_file = await async_client.files.create(b"file_content") @@ -39,7 +39,7 @@ async def test_retrieve(self, async_client): expected_response_file = FileObject.model_validate_json(mock_file_response_payload()) async_client._client.request.return_value = mock_response( 200, - expected_response_file.json(), + expected_response_file.model_dump_json(), ) response_file = await async_client.files.retrieve("file_id") @@ -91,7 +91,7 @@ async def test_list_files(self, async_client): @pytest.mark.asyncio async def test_delete_file(self, async_client): expected_response_file = FileDeleted.model_validate_json(mock_file_deleted_response_payload()) - async_client._client.request.return_value = mock_response(200, expected_response_file.json()) + async_client._client.request.return_value = mock_response(200, expected_response_file.model_dump_json()) response_file = await async_client.files.delete("file_id") diff --git a/tests/test_jobs.py b/tests/test_jobs.py index efb19b7..1a65efe 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -13,7 +13,7 @@ def test_create(self, client): expected_response_job = Job.model_validate_json(mock_job_response_payload()) client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = client.jobs.create( @@ -55,7 +55,7 @@ def test_retrieve(self, client): expected_response_job = DetailedJob.model_validate_json(mock_detailed_job_response_payload()) client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = client.jobs.retrieve("job_id") @@ -108,7 +108,7 @@ def test_cancel(self, client): expected_response_job = DetailedJob.model_validate_json(mock_detailed_job_response_payload()) client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = client.jobs.cancel("job_id") diff --git a/tests/test_jobs_async.py b/tests/test_jobs_async.py index 2d0d488..30b3d71 100644 --- a/tests/test_jobs_async.py +++ b/tests/test_jobs_async.py @@ -15,7 +15,7 @@ async def test_create(self, async_client): expected_response_job = Job.model_validate_json(mock_job_response_payload()) async_client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = await async_client.jobs.create( @@ -58,7 +58,7 @@ async def test_retrieve(self, async_client): expected_response_job = DetailedJob.model_validate_json(mock_detailed_job_response_payload()) async_client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = await async_client.jobs.retrieve("job_id") @@ -113,7 +113,7 @@ async def test_cancel(self, async_client): expected_response_job = DetailedJob.model_validate_json(mock_detailed_job_response_payload()) async_client._client.request.return_value = mock_response( 200, - expected_response_job.json(), + expected_response_job.model_dump_json(), ) response_job = await async_client.jobs.cancel("job_id")