mistralai 1.4.0__tar.gz → 1.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mistralai-1.4.0 → mistralai-1.5.1}/PKG-INFO +37 -1
- {mistralai-1.4.0 → mistralai-1.5.1}/README-PYPI.md +36 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/pyproject.toml +1 -1
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_version.py +3 -3
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/chat.py +87 -5
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/classifiers.py +27 -25
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/embeddings.py +2 -8
- mistralai-1.5.1/src/mistralai/extra/README.md +56 -0
- mistralai-1.5.1/src/mistralai/extra/__init__.py +5 -0
- mistralai-1.5.1/src/mistralai/extra/struct_chat.py +41 -0
- mistralai-1.5.1/src/mistralai/extra/tests/__init__.py +0 -0
- mistralai-1.5.1/src/mistralai/extra/tests/test_struct_chat.py +103 -0
- mistralai-1.5.1/src/mistralai/extra/tests/test_utils.py +162 -0
- mistralai-1.5.1/src/mistralai/extra/utils/__init__.py +3 -0
- mistralai-1.5.1/src/mistralai/extra/utils/_pydantic_helper.py +20 -0
- mistralai-1.5.1/src/mistralai/extra/utils/response_format.py +24 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/fim.py +5 -5
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/httpclient.py +50 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/__init__.py +41 -16
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/assistantmessage.py +2 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/chatcompletionrequest.py +3 -10
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/chatcompletionstreamrequest.py +3 -10
- mistralai-1.5.1/src/mistralai/models/chatmoderationrequest.py +86 -0
- mistralai-1.5.1/src/mistralai/models/classificationrequest.py +34 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/contentchunk.py +8 -1
- mistralai-1.5.1/src/mistralai/models/documenturlchunk.py +62 -0
- mistralai-1.5.1/src/mistralai/models/embeddingrequest.py +30 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/fimcompletionrequest.py +2 -3
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/fimcompletionstreamrequest.py +2 -3
- mistralai-1.5.1/src/mistralai/models/jsonschema.py +55 -0
- mistralai-1.5.1/src/mistralai/models/ocrimageobject.py +77 -0
- mistralai-1.5.1/src/mistralai/models/ocrpagedimensions.py +25 -0
- mistralai-1.5.1/src/mistralai/models/ocrpageobject.py +64 -0
- mistralai-1.5.1/src/mistralai/models/ocrrequest.py +97 -0
- mistralai-1.5.1/src/mistralai/models/ocrresponse.py +26 -0
- mistralai-1.5.1/src/mistralai/models/ocrusageinfo.py +51 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/prediction.py +4 -5
- mistralai-1.5.1/src/mistralai/models/responseformat.py +52 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/responseformats.py +1 -1
- mistralai-1.5.1/src/mistralai/ocr.py +238 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/sdk.py +15 -2
- mistralai-1.4.0/src/mistralai/models/chatclassificationrequest.py +0 -113
- mistralai-1.4.0/src/mistralai/models/classificationrequest.py +0 -63
- mistralai-1.4.0/src/mistralai/models/embeddingrequest.py +0 -66
- mistralai-1.4.0/src/mistralai/models/responseformat.py +0 -17
- {mistralai-1.4.0 → mistralai-1.5.1}/LICENSE +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_hooks/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_hooks/custom_user_agent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_hooks/registration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_hooks/sdkhooks.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_hooks/types.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/_version.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/basesdk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/chat.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/httpclient.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/assistantmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionstreamrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/completionchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/completionevent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/completionresponsestreamchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/contentchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/deltamessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/function.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/functioncall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/functionname.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/httpvalidationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/referencechunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/responseformat.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/responseformats.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/sdkerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/systemmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/textchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/tool.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/toolcall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/toolchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/toolchoiceenum.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/toolmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/tooltypes.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/usageinfo.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/usermessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/models/validationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/py.typed +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/sdk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/sdkconfiguration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/types/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/types/basemodel.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/annotations.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/enums.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/eventstreaming.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/forms.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/headers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/logger.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/metadata.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/queryparams.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/requestbodies.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/retries.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/serializers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/url.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_azure/src/mistralai_azure/utils/values.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_hooks/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_hooks/custom_user_agent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_hooks/registration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_hooks/sdkhooks.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_hooks/types.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/_version.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/basesdk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/chat.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/fim.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/httpclient.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/assistantmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionstreamrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/completionchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/completionevent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/completionresponsestreamchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/contentchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/deltamessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/fimcompletionrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/fimcompletionresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/fimcompletionstreamrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/function.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/functioncall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/functionname.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/httpvalidationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/referencechunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/responseformat.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/responseformats.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/sdkerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/systemmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/textchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/tool.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/toolcall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/toolchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/toolchoiceenum.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/toolmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/tooltypes.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/usageinfo.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/usermessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/models/validationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/py.typed +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/sdk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/sdkconfiguration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/types/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/types/basemodel.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/annotations.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/enums.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/eventstreaming.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/forms.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/headers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/logger.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/metadata.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/queryparams.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/requestbodies.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/retries.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/serializers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/url.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/packages/mistralai_gcp/src/mistralai_gcp/utils/values.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/py.typed +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/custom_user_agent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/deprecation_warning.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/registration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/sdkhooks.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/_hooks/types.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/agents.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/async_client.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/basesdk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/batch.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/client.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/files.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/fine_tuning.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/jobs.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/mistral_jobs.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/agentscompletionrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/agentscompletionstreamrequest.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/apiendpoint.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/archiveftmodelout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/basemodelcard.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/batcherror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/batchjobin.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/batchjobout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/batchjobsout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/batchjobstatus.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/chatcompletionchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/chatcompletionresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/checkpointout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/classificationobject.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/classificationresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/completionchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/completionevent.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/completionresponsestreamchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/delete_model_v1_models_model_id_deleteop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/deletefileout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/deletemodelout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/deltamessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/detailedjobout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/embeddingresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/embeddingresponsedata.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/eventout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/filepurpose.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_delete_fileop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_download_fileop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_get_signed_urlop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_list_filesop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_retrieve_fileop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/files_api_routes_upload_fileop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/fileschema.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/filesignedurl.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/fimcompletionresponse.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/ftmodelcapabilitiesout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/ftmodelcard.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/ftmodelout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/function.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/functioncall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/functionname.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/githubrepositoryin.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/githubrepositoryout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/httpvalidationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/imageurl.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/imageurlchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobin.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobmetadataout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_batch_cancel_batch_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/jobsout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/legacyjobmetadataout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/listfilesout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/metricout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/modelcapabilities.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/modellist.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/referencechunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/retrieve_model_v1_models_model_id_getop.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/retrievefileout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/sampletype.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/sdkerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/source.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/systemmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/textchunk.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/tool.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/toolcall.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/toolchoice.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/toolchoiceenum.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/toolmessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/tooltypes.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/trainingfile.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/trainingparameters.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/trainingparametersin.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/unarchiveftmodelout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/updateftmodelin.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/uploadfileout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/usageinfo.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/usermessage.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/validationerror.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/wandbintegration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models/wandbintegrationout.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/models_.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/py.typed +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/sdkconfiguration.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/types/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/types/basemodel.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/__init__.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/annotations.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/enums.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/eventstreaming.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/forms.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/headers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/logger.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/metadata.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/queryparams.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/requestbodies.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/retries.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/security.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/serializers.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/url.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/utils/values.py +0 -0
- {mistralai-1.4.0 → mistralai-1.5.1}/src/mistralai/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: mistralai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.1
|
|
4
4
|
Summary: Python Client SDK for the Mistral AI API.
|
|
5
5
|
Author: Mistral
|
|
6
6
|
Requires-Python: >=3.8
|
|
@@ -67,6 +67,7 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
|
|
|
67
67
|
* [Server Selection](https://github.com/mistralai/client-python/blob/master/#server-selection)
|
|
68
68
|
* [Custom HTTP Client](https://github.com/mistralai/client-python/blob/master/#custom-http-client)
|
|
69
69
|
* [Authentication](https://github.com/mistralai/client-python/blob/master/#authentication)
|
|
70
|
+
* [Resource Management](https://github.com/mistralai/client-python/blob/master/#resource-management)
|
|
70
71
|
* [Debugging](https://github.com/mistralai/client-python/blob/master/#debugging)
|
|
71
72
|
* [IDE Support](https://github.com/mistralai/client-python/blob/master/#ide-support)
|
|
72
73
|
* [Development](https://github.com/mistralai/client-python/blob/master/#development)
|
|
@@ -77,6 +78,11 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
|
|
|
77
78
|
<!-- Start SDK Installation [installation] -->
|
|
78
79
|
## SDK Installation
|
|
79
80
|
|
|
81
|
+
> [!NOTE]
|
|
82
|
+
> **Python version upgrade policy**
|
|
83
|
+
>
|
|
84
|
+
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
|
|
85
|
+
|
|
80
86
|
The SDK can be installed with either *pip* or *poetry* package managers.
|
|
81
87
|
|
|
82
88
|
### PIP
|
|
@@ -461,6 +467,10 @@ The documentation for the GCP SDK is available [here](https://github.com/mistral
|
|
|
461
467
|
* [archive](https://github.com/mistralai/client-python/blob/master/docs/sdks/models/README.md#archive) - Archive Fine Tuned Model
|
|
462
468
|
* [unarchive](https://github.com/mistralai/client-python/blob/master/docs/sdks/models/README.md#unarchive) - Unarchive Fine Tuned Model
|
|
463
469
|
|
|
470
|
+
### [ocr](https://github.com/mistralai/client-python/blob/master/docs/sdks/ocr/README.md)
|
|
471
|
+
|
|
472
|
+
* [process](https://github.com/mistralai/client-python/blob/master/docs/sdks/ocr/README.md#process) - OCR
|
|
473
|
+
|
|
464
474
|
</details>
|
|
465
475
|
<!-- End Available Resources and Operations [operations] -->
|
|
466
476
|
|
|
@@ -779,6 +789,32 @@ with Mistral(
|
|
|
779
789
|
```
|
|
780
790
|
<!-- End Authentication [security] -->
|
|
781
791
|
|
|
792
|
+
<!-- Start Resource Management [resource-management] -->
|
|
793
|
+
## Resource Management
|
|
794
|
+
|
|
795
|
+
The `Mistral` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
|
|
796
|
+
|
|
797
|
+
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
|
|
798
|
+
|
|
799
|
+
```python
|
|
800
|
+
from mistralai import Mistral
|
|
801
|
+
import os
|
|
802
|
+
def main():
|
|
803
|
+
with Mistral(
|
|
804
|
+
api_key=os.getenv("MISTRAL_API_KEY", ""),
|
|
805
|
+
) as mistral:
|
|
806
|
+
# Rest of application here...
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
# Or when using async:
|
|
810
|
+
async def amain():
|
|
811
|
+
async with Mistral(
|
|
812
|
+
api_key=os.getenv("MISTRAL_API_KEY", ""),
|
|
813
|
+
) as mistral:
|
|
814
|
+
# Rest of application here...
|
|
815
|
+
```
|
|
816
|
+
<!-- End Resource Management [resource-management] -->
|
|
817
|
+
|
|
782
818
|
<!-- Start Debugging [debug] -->
|
|
783
819
|
## Debugging
|
|
784
820
|
|
|
@@ -42,6 +42,7 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
|
|
|
42
42
|
* [Server Selection](https://github.com/mistralai/client-python/blob/master/#server-selection)
|
|
43
43
|
* [Custom HTTP Client](https://github.com/mistralai/client-python/blob/master/#custom-http-client)
|
|
44
44
|
* [Authentication](https://github.com/mistralai/client-python/blob/master/#authentication)
|
|
45
|
+
* [Resource Management](https://github.com/mistralai/client-python/blob/master/#resource-management)
|
|
45
46
|
* [Debugging](https://github.com/mistralai/client-python/blob/master/#debugging)
|
|
46
47
|
* [IDE Support](https://github.com/mistralai/client-python/blob/master/#ide-support)
|
|
47
48
|
* [Development](https://github.com/mistralai/client-python/blob/master/#development)
|
|
@@ -52,6 +53,11 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
|
|
|
52
53
|
<!-- Start SDK Installation [installation] -->
|
|
53
54
|
## SDK Installation
|
|
54
55
|
|
|
56
|
+
> [!NOTE]
|
|
57
|
+
> **Python version upgrade policy**
|
|
58
|
+
>
|
|
59
|
+
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
|
|
60
|
+
|
|
55
61
|
The SDK can be installed with either *pip* or *poetry* package managers.
|
|
56
62
|
|
|
57
63
|
### PIP
|
|
@@ -436,6 +442,10 @@ The documentation for the GCP SDK is available [here](https://github.com/mistral
|
|
|
436
442
|
* [archive](https://github.com/mistralai/client-python/blob/master/docs/sdks/models/README.md#archive) - Archive Fine Tuned Model
|
|
437
443
|
* [unarchive](https://github.com/mistralai/client-python/blob/master/docs/sdks/models/README.md#unarchive) - Unarchive Fine Tuned Model
|
|
438
444
|
|
|
445
|
+
### [ocr](https://github.com/mistralai/client-python/blob/master/docs/sdks/ocr/README.md)
|
|
446
|
+
|
|
447
|
+
* [process](https://github.com/mistralai/client-python/blob/master/docs/sdks/ocr/README.md#process) - OCR
|
|
448
|
+
|
|
439
449
|
</details>
|
|
440
450
|
<!-- End Available Resources and Operations [operations] -->
|
|
441
451
|
|
|
@@ -754,6 +764,32 @@ with Mistral(
|
|
|
754
764
|
```
|
|
755
765
|
<!-- End Authentication [security] -->
|
|
756
766
|
|
|
767
|
+
<!-- Start Resource Management [resource-management] -->
|
|
768
|
+
## Resource Management
|
|
769
|
+
|
|
770
|
+
The `Mistral` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
|
|
771
|
+
|
|
772
|
+
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
|
|
773
|
+
|
|
774
|
+
```python
|
|
775
|
+
from mistralai import Mistral
|
|
776
|
+
import os
|
|
777
|
+
def main():
|
|
778
|
+
with Mistral(
|
|
779
|
+
api_key=os.getenv("MISTRAL_API_KEY", ""),
|
|
780
|
+
) as mistral:
|
|
781
|
+
# Rest of application here...
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
# Or when using async:
|
|
785
|
+
async def amain():
|
|
786
|
+
async with Mistral(
|
|
787
|
+
api_key=os.getenv("MISTRAL_API_KEY", ""),
|
|
788
|
+
) as mistral:
|
|
789
|
+
# Rest of application here...
|
|
790
|
+
```
|
|
791
|
+
<!-- End Resource Management [resource-management] -->
|
|
792
|
+
|
|
757
793
|
<!-- Start Debugging [debug] -->
|
|
758
794
|
## Debugging
|
|
759
795
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import importlib.metadata
|
|
4
4
|
|
|
5
5
|
__title__: str = "mistralai"
|
|
6
|
-
__version__: str = "1.
|
|
6
|
+
__version__: str = "1.5.1"
|
|
7
7
|
__openapi_doc_version__: str = "0.0.2"
|
|
8
|
-
__gen_version__: str = "2.
|
|
9
|
-
__user_agent__: str = "speakeasy-sdk/python 1.
|
|
8
|
+
__gen_version__: str = "2.497.0"
|
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 1.5.1 2.497.0 0.0.2 mistralai"
|
|
10
10
|
|
|
11
11
|
try:
|
|
12
12
|
if __package__ is not None:
|
|
@@ -3,18 +3,100 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai import models, utils
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
|
-
from mistralai.types import
|
|
6
|
+
from mistralai.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
8
|
from typing import Any, List, Mapping, Optional, Union
|
|
9
9
|
|
|
10
|
+
# region imports
|
|
11
|
+
from typing import Type
|
|
12
|
+
from mistralai.extra import (
|
|
13
|
+
convert_to_parsed_chat_completion_response,
|
|
14
|
+
response_format_from_pydantic_model,
|
|
15
|
+
CustomPydanticModel,
|
|
16
|
+
ParsedChatCompletionResponse,
|
|
17
|
+
)
|
|
18
|
+
# endregion imports
|
|
19
|
+
|
|
10
20
|
|
|
11
21
|
class Chat(BaseSDK):
|
|
12
22
|
r"""Chat Completion API."""
|
|
13
23
|
|
|
24
|
+
# region sdk-class-body
|
|
25
|
+
# Custom .parse methods for the Structure Outputs Feature.
|
|
26
|
+
|
|
27
|
+
def parse(
|
|
28
|
+
self, response_format: Type[CustomPydanticModel], **kwargs: Any
|
|
29
|
+
) -> ParsedChatCompletionResponse[CustomPydanticModel]:
|
|
30
|
+
"""
|
|
31
|
+
Parse the response using the provided response format.
|
|
32
|
+
:param Type[CustomPydanticModel] response_format: The Pydantic model to parse the response into
|
|
33
|
+
:param Any **kwargs Additional keyword arguments to pass to the .complete method
|
|
34
|
+
:return: The parsed response
|
|
35
|
+
"""
|
|
36
|
+
# Convert the input Pydantic Model to a strict JSON ready to be passed to chat.complete
|
|
37
|
+
json_response_format = response_format_from_pydantic_model(response_format)
|
|
38
|
+
# Run the inference
|
|
39
|
+
response = self.complete(**kwargs, response_format=json_response_format)
|
|
40
|
+
# Parse response back to the input pydantic model
|
|
41
|
+
parsed_response = convert_to_parsed_chat_completion_response(
|
|
42
|
+
response, response_format
|
|
43
|
+
)
|
|
44
|
+
return parsed_response
|
|
45
|
+
|
|
46
|
+
async def parse_async(
|
|
47
|
+
self, response_format: Type[CustomPydanticModel], **kwargs
|
|
48
|
+
) -> ParsedChatCompletionResponse[CustomPydanticModel]:
|
|
49
|
+
"""
|
|
50
|
+
Asynchronously parse the response using the provided response format.
|
|
51
|
+
:param Type[CustomPydanticModel] response_format: The Pydantic model to parse the response into
|
|
52
|
+
:param Any **kwargs Additional keyword arguments to pass to the .complete method
|
|
53
|
+
:return: The parsed response
|
|
54
|
+
"""
|
|
55
|
+
json_response_format = response_format_from_pydantic_model(response_format)
|
|
56
|
+
response = await self.complete_async( # pylint: disable=E1125
|
|
57
|
+
**kwargs, response_format=json_response_format
|
|
58
|
+
)
|
|
59
|
+
parsed_response = convert_to_parsed_chat_completion_response(
|
|
60
|
+
response, response_format
|
|
61
|
+
)
|
|
62
|
+
return parsed_response
|
|
63
|
+
|
|
64
|
+
def parse_stream(
|
|
65
|
+
self, response_format: Type[CustomPydanticModel], **kwargs
|
|
66
|
+
) -> eventstreaming.EventStream[models.CompletionEvent]:
|
|
67
|
+
"""
|
|
68
|
+
Parse the response using the provided response format.
|
|
69
|
+
For now the response will be in JSON format not in the input Pydantic model.
|
|
70
|
+
:param Type[CustomPydanticModel] response_format: The Pydantic model to parse the response into
|
|
71
|
+
:param Any **kwargs Additional keyword arguments to pass to the .stream method
|
|
72
|
+
:return: The JSON parsed response
|
|
73
|
+
"""
|
|
74
|
+
json_response_format = response_format_from_pydantic_model(response_format)
|
|
75
|
+
response = self.stream(**kwargs, response_format=json_response_format)
|
|
76
|
+
return response
|
|
77
|
+
|
|
78
|
+
async def parse_stream_async(
|
|
79
|
+
self, response_format: Type[CustomPydanticModel], **kwargs
|
|
80
|
+
) -> eventstreaming.EventStreamAsync[models.CompletionEvent]:
|
|
81
|
+
"""
|
|
82
|
+
Asynchronously parse the response using the provided response format.
|
|
83
|
+
For now the response will be in JSON format not in the input Pydantic model.
|
|
84
|
+
:param Type[CustomPydanticModel] response_format: The Pydantic model to parse the response into
|
|
85
|
+
:param Any **kwargs Additional keyword arguments to pass to the .stream method
|
|
86
|
+
:return: The JSON parsed response
|
|
87
|
+
"""
|
|
88
|
+
json_response_format = response_format_from_pydantic_model(response_format)
|
|
89
|
+
response = await self.stream_async( # pylint: disable=E1125
|
|
90
|
+
**kwargs, response_format=json_response_format
|
|
91
|
+
)
|
|
92
|
+
return response
|
|
93
|
+
|
|
94
|
+
# endregion sdk-class-body
|
|
95
|
+
|
|
14
96
|
def complete(
|
|
15
97
|
self,
|
|
16
98
|
*,
|
|
17
|
-
model:
|
|
99
|
+
model: str,
|
|
18
100
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
19
101
|
temperature: OptionalNullable[float] = UNSET,
|
|
20
102
|
top_p: Optional[float] = None,
|
|
@@ -171,7 +253,7 @@ class Chat(BaseSDK):
|
|
|
171
253
|
async def complete_async(
|
|
172
254
|
self,
|
|
173
255
|
*,
|
|
174
|
-
model:
|
|
256
|
+
model: str,
|
|
175
257
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
176
258
|
temperature: OptionalNullable[float] = UNSET,
|
|
177
259
|
top_p: Optional[float] = None,
|
|
@@ -328,7 +410,7 @@ class Chat(BaseSDK):
|
|
|
328
410
|
def stream(
|
|
329
411
|
self,
|
|
330
412
|
*,
|
|
331
|
-
model:
|
|
413
|
+
model: str,
|
|
332
414
|
messages: Union[
|
|
333
415
|
List[models.ChatCompletionStreamRequestMessages],
|
|
334
416
|
List[models.ChatCompletionStreamRequestMessagesTypedDict],
|
|
@@ -503,7 +585,7 @@ class Chat(BaseSDK):
|
|
|
503
585
|
async def stream_async(
|
|
504
586
|
self,
|
|
505
587
|
*,
|
|
506
|
-
model:
|
|
588
|
+
model: str,
|
|
507
589
|
messages: Union[
|
|
508
590
|
List[models.ChatCompletionStreamRequestMessages],
|
|
509
591
|
List[models.ChatCompletionStreamRequestMessagesTypedDict],
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai import models, utils
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
|
-
from mistralai.types import
|
|
6
|
+
from mistralai.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai.utils import get_security_from_env
|
|
8
8
|
from typing import Any, Mapping, Optional, Union
|
|
9
9
|
|
|
@@ -14,11 +14,11 @@ class Classifiers(BaseSDK):
|
|
|
14
14
|
def moderate(
|
|
15
15
|
self,
|
|
16
16
|
*,
|
|
17
|
+
model: str,
|
|
17
18
|
inputs: Union[
|
|
18
19
|
models.ClassificationRequestInputs,
|
|
19
20
|
models.ClassificationRequestInputsTypedDict,
|
|
20
21
|
],
|
|
21
|
-
model: OptionalNullable[str] = UNSET,
|
|
22
22
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
23
23
|
server_url: Optional[str] = None,
|
|
24
24
|
timeout_ms: Optional[int] = None,
|
|
@@ -26,8 +26,8 @@ class Classifiers(BaseSDK):
|
|
|
26
26
|
) -> models.ClassificationResponse:
|
|
27
27
|
r"""Moderations
|
|
28
28
|
|
|
29
|
+
:param model: ID of the model to use.
|
|
29
30
|
:param inputs: Text to classify.
|
|
30
|
-
:param model:
|
|
31
31
|
:param retries: Override the default retry configuration for this method
|
|
32
32
|
:param server_url: Override the default server URL for this method
|
|
33
33
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -42,8 +42,8 @@ class Classifiers(BaseSDK):
|
|
|
42
42
|
base_url = server_url
|
|
43
43
|
|
|
44
44
|
request = models.ClassificationRequest(
|
|
45
|
-
inputs=inputs,
|
|
46
45
|
model=model,
|
|
46
|
+
inputs=inputs,
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
req = self._build_request(
|
|
@@ -115,11 +115,11 @@ class Classifiers(BaseSDK):
|
|
|
115
115
|
async def moderate_async(
|
|
116
116
|
self,
|
|
117
117
|
*,
|
|
118
|
+
model: str,
|
|
118
119
|
inputs: Union[
|
|
119
120
|
models.ClassificationRequestInputs,
|
|
120
121
|
models.ClassificationRequestInputsTypedDict,
|
|
121
122
|
],
|
|
122
|
-
model: OptionalNullable[str] = UNSET,
|
|
123
123
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
124
124
|
server_url: Optional[str] = None,
|
|
125
125
|
timeout_ms: Optional[int] = None,
|
|
@@ -127,8 +127,8 @@ class Classifiers(BaseSDK):
|
|
|
127
127
|
) -> models.ClassificationResponse:
|
|
128
128
|
r"""Moderations
|
|
129
129
|
|
|
130
|
+
:param model: ID of the model to use.
|
|
130
131
|
:param inputs: Text to classify.
|
|
131
|
-
:param model:
|
|
132
132
|
:param retries: Override the default retry configuration for this method
|
|
133
133
|
:param server_url: Override the default server URL for this method
|
|
134
134
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -143,8 +143,8 @@ class Classifiers(BaseSDK):
|
|
|
143
143
|
base_url = server_url
|
|
144
144
|
|
|
145
145
|
request = models.ClassificationRequest(
|
|
146
|
-
inputs=inputs,
|
|
147
146
|
model=model,
|
|
147
|
+
inputs=inputs,
|
|
148
148
|
)
|
|
149
149
|
|
|
150
150
|
req = self._build_request_async(
|
|
@@ -216,11 +216,12 @@ class Classifiers(BaseSDK):
|
|
|
216
216
|
def moderate_chat(
|
|
217
217
|
self,
|
|
218
218
|
*,
|
|
219
|
+
model: str,
|
|
219
220
|
inputs: Union[
|
|
220
|
-
models.
|
|
221
|
-
models.
|
|
221
|
+
models.ChatModerationRequestInputs,
|
|
222
|
+
models.ChatModerationRequestInputsTypedDict,
|
|
222
223
|
],
|
|
223
|
-
|
|
224
|
+
truncate_for_context_length: Optional[bool] = False,
|
|
224
225
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
225
226
|
server_url: Optional[str] = None,
|
|
226
227
|
timeout_ms: Optional[int] = None,
|
|
@@ -228,8 +229,9 @@ class Classifiers(BaseSDK):
|
|
|
228
229
|
) -> models.ClassificationResponse:
|
|
229
230
|
r"""Moderations Chat
|
|
230
231
|
|
|
231
|
-
:param inputs: Chat to classify
|
|
232
232
|
:param model:
|
|
233
|
+
:param inputs: Chat to classify
|
|
234
|
+
:param truncate_for_context_length:
|
|
233
235
|
:param retries: Override the default retry configuration for this method
|
|
234
236
|
:param server_url: Override the default server URL for this method
|
|
235
237
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -243,11 +245,10 @@ class Classifiers(BaseSDK):
|
|
|
243
245
|
if server_url is not None:
|
|
244
246
|
base_url = server_url
|
|
245
247
|
|
|
246
|
-
request = models.
|
|
247
|
-
inputs=utils.get_pydantic_model(
|
|
248
|
-
inputs, models.ChatClassificationRequestInputs
|
|
249
|
-
),
|
|
248
|
+
request = models.ChatModerationRequest(
|
|
250
249
|
model=model,
|
|
250
|
+
inputs=utils.get_pydantic_model(inputs, models.ChatModerationRequestInputs),
|
|
251
|
+
truncate_for_context_length=truncate_for_context_length,
|
|
251
252
|
)
|
|
252
253
|
|
|
253
254
|
req = self._build_request(
|
|
@@ -264,7 +265,7 @@ class Classifiers(BaseSDK):
|
|
|
264
265
|
http_headers=http_headers,
|
|
265
266
|
security=self.sdk_configuration.security,
|
|
266
267
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
267
|
-
request, False, False, "json", models.
|
|
268
|
+
request, False, False, "json", models.ChatModerationRequest
|
|
268
269
|
),
|
|
269
270
|
timeout_ms=timeout_ms,
|
|
270
271
|
)
|
|
@@ -319,11 +320,12 @@ class Classifiers(BaseSDK):
|
|
|
319
320
|
async def moderate_chat_async(
|
|
320
321
|
self,
|
|
321
322
|
*,
|
|
323
|
+
model: str,
|
|
322
324
|
inputs: Union[
|
|
323
|
-
models.
|
|
324
|
-
models.
|
|
325
|
+
models.ChatModerationRequestInputs,
|
|
326
|
+
models.ChatModerationRequestInputsTypedDict,
|
|
325
327
|
],
|
|
326
|
-
|
|
328
|
+
truncate_for_context_length: Optional[bool] = False,
|
|
327
329
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
328
330
|
server_url: Optional[str] = None,
|
|
329
331
|
timeout_ms: Optional[int] = None,
|
|
@@ -331,8 +333,9 @@ class Classifiers(BaseSDK):
|
|
|
331
333
|
) -> models.ClassificationResponse:
|
|
332
334
|
r"""Moderations Chat
|
|
333
335
|
|
|
334
|
-
:param inputs: Chat to classify
|
|
335
336
|
:param model:
|
|
337
|
+
:param inputs: Chat to classify
|
|
338
|
+
:param truncate_for_context_length:
|
|
336
339
|
:param retries: Override the default retry configuration for this method
|
|
337
340
|
:param server_url: Override the default server URL for this method
|
|
338
341
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -346,11 +349,10 @@ class Classifiers(BaseSDK):
|
|
|
346
349
|
if server_url is not None:
|
|
347
350
|
base_url = server_url
|
|
348
351
|
|
|
349
|
-
request = models.
|
|
350
|
-
inputs=utils.get_pydantic_model(
|
|
351
|
-
inputs, models.ChatClassificationRequestInputs
|
|
352
|
-
),
|
|
352
|
+
request = models.ChatModerationRequest(
|
|
353
353
|
model=model,
|
|
354
|
+
inputs=utils.get_pydantic_model(inputs, models.ChatModerationRequestInputs),
|
|
355
|
+
truncate_for_context_length=truncate_for_context_length,
|
|
354
356
|
)
|
|
355
357
|
|
|
356
358
|
req = self._build_request_async(
|
|
@@ -367,7 +369,7 @@ class Classifiers(BaseSDK):
|
|
|
367
369
|
http_headers=http_headers,
|
|
368
370
|
security=self.sdk_configuration.security,
|
|
369
371
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
370
|
-
request, False, False, "json", models.
|
|
372
|
+
request, False, False, "json", models.ChatModerationRequest
|
|
371
373
|
),
|
|
372
374
|
timeout_ms=timeout_ms,
|
|
373
375
|
)
|
|
@@ -16,7 +16,6 @@ class Embeddings(BaseSDK):
|
|
|
16
16
|
*,
|
|
17
17
|
inputs: Union[models.Inputs, models.InputsTypedDict],
|
|
18
18
|
model: Optional[str] = "mistral-embed",
|
|
19
|
-
encoding_format: OptionalNullable[str] = UNSET,
|
|
20
19
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
21
20
|
server_url: Optional[str] = None,
|
|
22
21
|
timeout_ms: Optional[int] = None,
|
|
@@ -28,7 +27,6 @@ class Embeddings(BaseSDK):
|
|
|
28
27
|
|
|
29
28
|
:param inputs: Text to embed.
|
|
30
29
|
:param model: ID of the model to use.
|
|
31
|
-
:param encoding_format: The format to return the embeddings in.
|
|
32
30
|
:param retries: Override the default retry configuration for this method
|
|
33
31
|
:param server_url: Override the default server URL for this method
|
|
34
32
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -43,9 +41,8 @@ class Embeddings(BaseSDK):
|
|
|
43
41
|
base_url = server_url
|
|
44
42
|
|
|
45
43
|
request = models.EmbeddingRequest(
|
|
46
|
-
inputs=inputs,
|
|
47
44
|
model=model,
|
|
48
|
-
|
|
45
|
+
inputs=inputs,
|
|
49
46
|
)
|
|
50
47
|
|
|
51
48
|
req = self._build_request(
|
|
@@ -119,7 +116,6 @@ class Embeddings(BaseSDK):
|
|
|
119
116
|
*,
|
|
120
117
|
inputs: Union[models.Inputs, models.InputsTypedDict],
|
|
121
118
|
model: Optional[str] = "mistral-embed",
|
|
122
|
-
encoding_format: OptionalNullable[str] = UNSET,
|
|
123
119
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
124
120
|
server_url: Optional[str] = None,
|
|
125
121
|
timeout_ms: Optional[int] = None,
|
|
@@ -131,7 +127,6 @@ class Embeddings(BaseSDK):
|
|
|
131
127
|
|
|
132
128
|
:param inputs: Text to embed.
|
|
133
129
|
:param model: ID of the model to use.
|
|
134
|
-
:param encoding_format: The format to return the embeddings in.
|
|
135
130
|
:param retries: Override the default retry configuration for this method
|
|
136
131
|
:param server_url: Override the default server URL for this method
|
|
137
132
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -146,9 +141,8 @@ class Embeddings(BaseSDK):
|
|
|
146
141
|
base_url = server_url
|
|
147
142
|
|
|
148
143
|
request = models.EmbeddingRequest(
|
|
149
|
-
inputs=inputs,
|
|
150
144
|
model=model,
|
|
151
|
-
|
|
145
|
+
inputs=inputs,
|
|
152
146
|
)
|
|
153
147
|
|
|
154
148
|
req = self._build_request_async(
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
## Context
|
|
2
|
+
|
|
3
|
+
The extra package contains the custom logic which is too complex to be generated by Speakeasy from the OpenAPI specs. It was introduced to add the Structured Outputs feature.
|
|
4
|
+
|
|
5
|
+
## Development / Contributing
|
|
6
|
+
|
|
7
|
+
To add custom code in the SDK, you need to use [Speakeasy custom code regions](https://www.speakeasy.com/docs/customize/code/code-regions/overview) as below.
|
|
8
|
+
|
|
9
|
+
### Runbook of SDK customization
|
|
10
|
+
|
|
11
|
+
1. Add the code you want to import in the `src/mistralai/extra/` package. To have it importable from the SDK, you need to add it in the `__init__.py` file:
|
|
12
|
+
```python
|
|
13
|
+
from .my_custom_file import my_custom_function
|
|
14
|
+
|
|
15
|
+
__all__ = ["my_custom_function"]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. Add a new custom code region in the SDK files, e.g in `src/mistralai/chat.py`:
|
|
19
|
+
```python
|
|
20
|
+
# region imports
|
|
21
|
+
from typing import Type
|
|
22
|
+
from mistralai.extra import my_custom_function
|
|
23
|
+
# endregion imports
|
|
24
|
+
|
|
25
|
+
class Chat(BaseSDK):
|
|
26
|
+
r"""Chat Completion API."""
|
|
27
|
+
|
|
28
|
+
# region sdk-class-body
|
|
29
|
+
def my_custom_method(self, param: str) -> Type[some_type]:
|
|
30
|
+
output = my_custom_function(param1)
|
|
31
|
+
return output
|
|
32
|
+
# endregion sdk-class-body
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Now build the SDK with the custom code:
|
|
36
|
+
```bash
|
|
37
|
+
rm -rf dist; poetry build; python3 -m pip install ~/client-python/dist/mistralai-1.4.1-py3-none-any.whl --force-reinstall
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. And now you should be able to call the custom method:
|
|
41
|
+
```python
|
|
42
|
+
import os
|
|
43
|
+
from mistralai import Mistral
|
|
44
|
+
|
|
45
|
+
api_key = os.environ["MISTRAL_API_KEY"]
|
|
46
|
+
client = Mistral(api_key=api_key)
|
|
47
|
+
|
|
48
|
+
client.chat.my_custom_method(param="test")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Run the unit tests
|
|
52
|
+
|
|
53
|
+
To run the unit tests for the `extra` package, you can run the following command from the root of the repository:
|
|
54
|
+
```bash
|
|
55
|
+
python3.12 -m unittest discover -s src/mistralai/extra/tests -t src
|
|
56
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from .struct_chat import ParsedChatCompletionResponse, convert_to_parsed_chat_completion_response
|
|
2
|
+
from .utils import response_format_from_pydantic_model
|
|
3
|
+
from .utils.response_format import CustomPydanticModel
|
|
4
|
+
|
|
5
|
+
__all__ = ["convert_to_parsed_chat_completion_response", "response_format_from_pydantic_model", "CustomPydanticModel", "ParsedChatCompletionResponse"]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from ..models import ChatCompletionResponse, ChatCompletionChoice, AssistantMessage
|
|
2
|
+
from .utils.response_format import CustomPydanticModel, pydantic_model_from_json
|
|
3
|
+
from typing import List, Optional, Type, Generic
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
class ParsedAssistantMessage(AssistantMessage, Generic[CustomPydanticModel]):
|
|
8
|
+
parsed: Optional[CustomPydanticModel]
|
|
9
|
+
|
|
10
|
+
class ParsedChatCompletionChoice(ChatCompletionChoice, Generic[CustomPydanticModel]):
|
|
11
|
+
message: Optional[ParsedAssistantMessage[CustomPydanticModel]] # type: ignore
|
|
12
|
+
|
|
13
|
+
class ParsedChatCompletionResponse(ChatCompletionResponse, Generic[CustomPydanticModel]):
|
|
14
|
+
choices: Optional[List[ParsedChatCompletionChoice[CustomPydanticModel]]] # type: ignore
|
|
15
|
+
|
|
16
|
+
def convert_to_parsed_chat_completion_response(response: ChatCompletionResponse, response_format: Type[BaseModel]) -> ParsedChatCompletionResponse:
|
|
17
|
+
parsed_choices = []
|
|
18
|
+
|
|
19
|
+
if response.choices:
|
|
20
|
+
for choice in response.choices:
|
|
21
|
+
if choice.message:
|
|
22
|
+
parsed_message: ParsedAssistantMessage = ParsedAssistantMessage(
|
|
23
|
+
**choice.message.model_dump(),
|
|
24
|
+
parsed=None
|
|
25
|
+
)
|
|
26
|
+
if isinstance(parsed_message.content, str):
|
|
27
|
+
parsed_message.parsed = pydantic_model_from_json(json.loads(parsed_message.content), response_format)
|
|
28
|
+
elif parsed_message.content is None:
|
|
29
|
+
parsed_message.parsed = None
|
|
30
|
+
else:
|
|
31
|
+
raise TypeError(f"Unexpected type for message.content: {type(parsed_message.content)}")
|
|
32
|
+
choice_dict = choice.model_dump()
|
|
33
|
+
choice_dict["message"] = parsed_message
|
|
34
|
+
parsed_choice: ParsedChatCompletionChoice = ParsedChatCompletionChoice(**choice_dict)
|
|
35
|
+
parsed_choices.append(parsed_choice)
|
|
36
|
+
else:
|
|
37
|
+
parsed_choice = ParsedChatCompletionChoice(**choice.model_dump())
|
|
38
|
+
parsed_choices.append(parsed_choice)
|
|
39
|
+
response_dict = response.model_dump()
|
|
40
|
+
response_dict["choices"] = parsed_choices
|
|
41
|
+
return ParsedChatCompletionResponse(**response_dict)
|
|
File without changes
|