diff --git a/.gitignore b/.gitignore index 965344c..767c3b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.speakeasy/reports README-PYPI.md .venv/ pyrightconfig.json diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 0b07759..d8a77e9 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 2d045ec7-2ebb-4f4d-ad25-40953b132161 management: - docChecksum: 36ad3563d9d2b3af47015100d060570b + docChecksum: 7ad277ed0527b2949ed9d503ce742fab docVersion: 0.0.2 - speakeasyVersion: 1.451.1 - generationVersion: 2.470.1 - releaseVersion: 1.2.5 - configChecksum: 9dbada68b30d84dc9c102c143b926b3d + speakeasyVersion: 1.462.2 + generationVersion: 2.486.1 + releaseVersion: 1.2.6 + configChecksum: 195a36c6a88eb19c3a487f1fe4a39bcc repoURL: https://github.com/mistralai/client-python.git installationURL: https://github.com/mistralai/client-python.git published: true @@ -14,7 +14,7 @@ features: python: additionalDependencies: 1.0.0 constsAndDefaults: 1.0.5 - core: 5.6.8 + core: 5.7.4 defaultEnabledRetries: 0.2.0 downloadStreams: 1.0.1 enumUnions: 0.1.0 @@ -25,10 +25,10 @@ features: globalSecurity: 3.0.2 globalSecurityCallbacks: 1.0.0 globalSecurityFlattening: 1.0.0 - globalServerURLs: 3.0.0 + globalServerURLs: 3.1.0 methodArguments: 1.0.2 multipartFileContentType: 1.0.0 - nameOverrides: 3.0.0 + nameOverrides: 3.0.1 nullables: 1.0.0 openEnums: 1.0.0 responseFormat: 1.0.1 @@ -373,7 +373,12 @@ generatedFiles: - src/mistralai/utils/values.py examples: list_models_v1_models_get: - speakeasy-default-list-models-v1-models-get: {} + speakeasy-default-list-models-v1-models-get: + responses: + "200": + application/json: {} + "422": + application/json: {} retrieve_model_v1_models__model_id__get: "": parameters: @@ -487,11 +492,15 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} stream_chat: speakeasy-default-stream-chat: requestBody: application/json: {"model": "mistral-small-latest", "messages": [{"content": "Who is the best French painter? Answer in one short sentence.", "role": "user"}]} + responses: + "422": + application/json: {} fim_completion_v1_fim_completions_post: speakeasy-default-fim-completion-v1-fim-completions-post: requestBody: @@ -499,11 +508,15 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "codestral-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} stream_fim: speakeasy-default-stream-fim: requestBody: application/json: {"model": "codestral-2405", "prompt": "def", "suffix": "return a+b"} + responses: + "422": + application/json: {} agents_completion_v1_agents_completions_post: speakeasy-default-agents-completion-v1-agents-completions-post: requestBody: @@ -511,11 +524,15 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} stream_agents: speakeasy-default-stream-agents: requestBody: application/json: {"messages": [{"content": "Who is the best French painter? Answer in one short sentence.", "role": "user"}], "agent_id": ""} + responses: + "422": + application/json: {} embeddings_v1_embeddings_post: speakeasy-default-embeddings-v1-embeddings-post: requestBody: @@ -523,7 +540,8 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "data": [{"object": "embedding", "embedding": [0.1, 0.2, 0.3], "index": 0}, {"object": "embedding", "embedding": [0.4, 0.5, 0.6], "index": 1}]} - "422": {} + "422": + application/json: {} files_api_routes_download_file: speakeasy-default-files-api-routes-download-file: parameters: @@ -564,7 +582,8 @@ examples: responses: "200": application/json: {"id": "mod-e5cc70bb28c444948073e77776eb30ef"} - "422": {} + "422": + application/json: {} moderations_chat_v1_chat_moderations_post: speakeasy-default-moderations-chat-v1-chat-moderations-post: requestBody: @@ -572,7 +591,8 @@ examples: responses: "200": application/json: {"id": "mod-e5cc70bb28c444948073e77776eb30ef"} - "422": {} + "422": + application/json: {} files_api_routes_get_signed_url: speakeasy-default-files-api-routes-get-signed-url: parameters: diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 5c043c4..8680a0e 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false python: - version: 1.2.5 + version: 1.2.6 additionalDependencies: dev: pytest: ^8.2.2 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 593960c..aa87f0a 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,46 +1,46 @@ -speakeasyVersion: 1.451.1 +speakeasyVersion: 1.462.2 sources: mistral-azure-source: sourceNamespace: mistral-azure-source - sourceRevisionDigest: sha256:9c35eed0174f2d8165807bcd7c8e7b7111fa97c059a77ae7eeaa352ca7e83b4d - sourceBlobDigest: sha256:07283bfde08363f9f69b133888b482472c4bf12d2e5b59cb33c8993c517278e3 + sourceRevisionDigest: sha256:ff181b1e0e3894a4925f7ae87415323058538a13bae9d9d508a8fe3b6ec0e333 + sourceBlobDigest: sha256:a2b4fd69298ebb9adb0d3c8dfb452db52defac512a7532203eebffb6a252df76 tags: - latest mistral-google-cloud-source: sourceNamespace: mistral-google-cloud-source - sourceRevisionDigest: sha256:e0fd58ce2dbba068f375d3a23d758b8678c2a68cf4fc7bc46ea7e1b37abe0647 - sourceBlobDigest: sha256:0707d8d2566a9ef4ef286bb0abe467f8696ccf83ba73091065d7caf627a06611 + sourceRevisionDigest: sha256:36c7de11e35023dc8fa5f3c0fb0e486d2a102275a2df808c08cfe9d43089be04 + sourceBlobDigest: sha256:dd65bfa5d0448ad1851ebb18b57aa675533cd3e166beb86a390b0ab51d16a1c1 tags: - latest mistral-openapi: sourceNamespace: mistral-openapi - sourceRevisionDigest: sha256:f74c08bdc7ae39f5fe2394df8f31ae623ece30a7f65019ab6b7bcea352953f05 - sourceBlobDigest: sha256:5de08a038994ec94c0889341d434b598f541459d114f9935deb9ef3b3af90c5f + sourceRevisionDigest: sha256:84bbc6f6011a31e21c8a674b01104446f986c7b5a6b002357800be8ef939b8da + sourceBlobDigest: sha256:ebc7c1bb20aa87873a255cebea1e451099d8949ea1bbff81ec5fd45a107e3a32 tags: - latest - - speakeasy-sdk-regen-1733325251 + - speakeasy-sdk-regen-1736155788 targets: mistralai-azure-sdk: source: mistral-azure-source sourceNamespace: mistral-azure-source - sourceRevisionDigest: sha256:9c35eed0174f2d8165807bcd7c8e7b7111fa97c059a77ae7eeaa352ca7e83b4d - sourceBlobDigest: sha256:07283bfde08363f9f69b133888b482472c4bf12d2e5b59cb33c8993c517278e3 + sourceRevisionDigest: sha256:ff181b1e0e3894a4925f7ae87415323058538a13bae9d9d508a8fe3b6ec0e333 + sourceBlobDigest: sha256:a2b4fd69298ebb9adb0d3c8dfb452db52defac512a7532203eebffb6a252df76 codeSamplesNamespace: mistral-openapi-azure-code-samples - codeSamplesRevisionDigest: sha256:79a227720579444358a825b1a272c153f3d9dd48cd0913be6c988d7931a44241 + codeSamplesRevisionDigest: sha256:28356dba7ea28436035e20182b8ce4d1951e19503b5accef6a128d860361e5c0 mistralai-gcp-sdk: source: mistral-google-cloud-source sourceNamespace: mistral-google-cloud-source - sourceRevisionDigest: sha256:e0fd58ce2dbba068f375d3a23d758b8678c2a68cf4fc7bc46ea7e1b37abe0647 - sourceBlobDigest: sha256:0707d8d2566a9ef4ef286bb0abe467f8696ccf83ba73091065d7caf627a06611 + sourceRevisionDigest: sha256:36c7de11e35023dc8fa5f3c0fb0e486d2a102275a2df808c08cfe9d43089be04 + sourceBlobDigest: sha256:dd65bfa5d0448ad1851ebb18b57aa675533cd3e166beb86a390b0ab51d16a1c1 codeSamplesNamespace: mistral-openapi-google-cloud-code-samples - codeSamplesRevisionDigest: sha256:0657ec41e473356a5a0eeaca3dff137e9ff16080ec1fb50e72553245aa86ffe5 + codeSamplesRevisionDigest: sha256:7de23f90d6543356f310f46375bef4db7f43eb22b2871ad4dfe1b7d0cc875bb4 mistralai-sdk: source: mistral-openapi sourceNamespace: mistral-openapi - sourceRevisionDigest: sha256:f74c08bdc7ae39f5fe2394df8f31ae623ece30a7f65019ab6b7bcea352953f05 - sourceBlobDigest: sha256:5de08a038994ec94c0889341d434b598f541459d114f9935deb9ef3b3af90c5f + sourceRevisionDigest: sha256:84bbc6f6011a31e21c8a674b01104446f986c7b5a6b002357800be8ef939b8da + sourceBlobDigest: sha256:ebc7c1bb20aa87873a255cebea1e451099d8949ea1bbff81ec5fd45a107e3a32 codeSamplesNamespace: mistral-openapi-code-samples - codeSamplesRevisionDigest: sha256:9a22e0289ff4e72dd43c1b65ddb8c7870814176d36e1eb6352d06e93dec597ba + codeSamplesRevisionDigest: sha256:3d7ebf5043f98a2e9b07c66057c279f90272a813875b29bd9b75595f77caf0c4 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index 7a88608..501e0ba 100644 --- a/README.md +++ b/README.md @@ -85,17 +85,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.chat.complete(model="mistral-small-latest", messages=[ +) as mistral: + + res = mistral.chat.complete(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -110,17 +112,19 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.chat.complete_async(model="mistral-small-latest", messages=[ + ) as mistral: + + res = await mistral.chat.complete_async(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -136,15 +140,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.upload(file={ +) as mistral: + + res = mistral.files.upload(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -159,15 +165,17 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.files.upload_async(file={ + ) as mistral: + + res = await mistral.files.upload_async(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -183,17 +191,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.agents.complete(messages=[ +) as mistral: + + res = mistral.agents.complete(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -208,17 +218,19 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.agents.complete_async(messages=[ + ) as mistral: + + res = await mistral.agents.complete_async(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -234,15 +246,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.embeddings.create(inputs=[ +) as mistral: + + res = mistral.embeddings.create(inputs=[ "Embed this sentence.", "As well as this one.", ], model="Wrangler") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -257,15 +271,17 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.embeddings.create_async(inputs=[ + ) as mistral: + + res = await mistral.embeddings.create_async(inputs=[ "Embed this sentence.", "As well as this one.", ], model="Wrangler") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -457,19 +473,21 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.chat.stream(model="mistral-small-latest", messages=[ +) as mistral: + + res = mistral.chat.stream(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - with res as event_stream: - for event in event_stream: - # handle event - print(event, flush=True) + assert res is not None + + with res as event_stream: + for event in event_stream: + # handle event + print(event, flush=True) ``` @@ -494,15 +512,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.upload(file={ +) as mistral: + + res = mistral.files.upload(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -514,37 +534,41 @@ Some of the endpoints in this SDK support retries. If you use the SDK without an To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call: ```python -from mistral.utils import BackoffStrategy, RetryConfig from mistralai import Mistral +from mistralai.utils import BackoffStrategy, RetryConfig import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list(, +) as mistral: + + res = mistral.models.list(, RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False)) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK: ```python -from mistral.utils import BackoffStrategy, RetryConfig from mistralai import Mistral +from mistralai.utils import BackoffStrategy, RetryConfig import os with Mistral( retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False), api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list() +) as mistral: + + res = mistral.models.list() - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -578,14 +602,16 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: +) as mistral: res = None try: - res = s.models.list() - if res is not None: - # handle response - pass + res = mistral.models.list() + + assert res is not None + + # Handle response + print(res) except models.HTTPValidationError as e: # handle e.data: models.HTTPValidationErrorData @@ -616,12 +642,14 @@ import os with Mistral( server="eu", api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list() +) as mistral: + + res = mistral.models.list() - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -635,12 +663,14 @@ import os with Mistral( server_url="https://api.mistral.ai", api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list() +) as mistral: + + res = mistral.models.list() - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -744,12 +774,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list() +) as mistral: + + res = mistral.models.list() - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` diff --git a/RELEASES.md b/RELEASES.md index a13990d..6544f99 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -108,4 +108,14 @@ Based on: ### Generated - [python v1.2.5] . ### Releases -- [PyPI v1.2.5] https://pypi.org/project/mistralai/1.2.5 - . \ No newline at end of file +- [PyPI v1.2.5] https://pypi.org/project/mistralai/1.2.5 - . + +## 2025-01-06 09:57:47 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.462.2 (2.486.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.2.6] . +### Releases +- [PyPI v1.2.6] https://pypi.org/project/mistralai/1.2.6 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index e523aa9..8876296 100644 --- a/USAGE.md +++ b/USAGE.md @@ -10,17 +10,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.chat.complete(model="mistral-small-latest", messages=[ +) as mistral: + + res = mistral.chat.complete(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -35,17 +37,19 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.chat.complete_async(model="mistral-small-latest", messages=[ + ) as mistral: + + res = await mistral.chat.complete_async(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -61,15 +65,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.upload(file={ +) as mistral: + + res = mistral.files.upload(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -84,15 +90,17 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.files.upload_async(file={ + ) as mistral: + + res = await mistral.files.upload_async(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -108,17 +116,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.agents.complete(messages=[ +) as mistral: + + res = mistral.agents.complete(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -133,17 +143,19 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.agents.complete_async(messages=[ + ) as mistral: + + res = await mistral.agents.complete_async(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` @@ -159,15 +171,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.embeddings.create(inputs=[ +) as mistral: + + res = mistral.embeddings.create(inputs=[ "Embed this sentence.", "As well as this one.", ], model="Wrangler") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ```
@@ -182,15 +196,17 @@ import os async def main(): async with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), - ) as s: - res = await s.embeddings.create_async(inputs=[ + ) as mistral: + + res = await mistral.embeddings.create_async(inputs=[ "Embed this sentence.", "As well as this one.", ], model="Wrangler") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) asyncio.run(main()) ``` diff --git a/docs/sdks/agents/README.md b/docs/sdks/agents/README.md index 792b796..3675fad 100644 --- a/docs/sdks/agents/README.md +++ b/docs/sdks/agents/README.md @@ -22,17 +22,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.agents.complete(messages=[ +) as mistral: + + res = mistral.agents.complete(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -77,19 +79,21 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.agents.stream(messages=[ +) as mistral: + + res = mistral.agents.stream(messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ], agent_id="") - if res is not None: - with res as event_stream: - for event in event_stream: - # handle event - print(event, flush=True) + assert res is not None + + with res as event_stream: + for event in event_stream: + # handle event + print(event, flush=True) ``` diff --git a/docs/sdks/chat/README.md b/docs/sdks/chat/README.md index 6e00d3d..8ab0eb6 100644 --- a/docs/sdks/chat/README.md +++ b/docs/sdks/chat/README.md @@ -22,17 +22,19 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.chat.complete(model="mistral-small-latest", messages=[ +) as mistral: + + res = mistral.chat.complete(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -80,19 +82,21 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.chat.stream(model="mistral-small-latest", messages=[ +) as mistral: + + res = mistral.chat.stream(model="mistral-small-latest", messages=[ { "content": "Who is the best French painter? Answer in one short sentence.", "role": "user", }, ]) - if res is not None: - with res as event_stream: - for event in event_stream: - # handle event - print(event, flush=True) + assert res is not None + + with res as event_stream: + for event in event_stream: + # handle event + print(event, flush=True) ``` diff --git a/docs/sdks/classifiers/README.md b/docs/sdks/classifiers/README.md index da90019..37ee3e1 100644 --- a/docs/sdks/classifiers/README.md +++ b/docs/sdks/classifiers/README.md @@ -22,14 +22,16 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.classifiers.moderate(inputs=[ +) as mistral: + + res = mistral.classifiers.moderate(inputs=[ "", ]) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -64,8 +66,9 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.classifiers.moderate_chat(inputs=[ +) as mistral: + + res = mistral.classifiers.moderate_chat(inputs=[ [ { "content": [ @@ -77,9 +80,10 @@ with Mistral( ], ], model="V90") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` diff --git a/docs/sdks/embeddings/README.md b/docs/sdks/embeddings/README.md index 1f9f195..b3610f7 100644 --- a/docs/sdks/embeddings/README.md +++ b/docs/sdks/embeddings/README.md @@ -21,15 +21,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.embeddings.create(inputs=[ +) as mistral: + + res = mistral.embeddings.create(inputs=[ "Embed this sentence.", "As well as this one.", ], model="Wrangler") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` diff --git a/docs/sdks/files/README.md b/docs/sdks/files/README.md index ad2e0f0..63a0023 100644 --- a/docs/sdks/files/README.md +++ b/docs/sdks/files/README.md @@ -30,15 +30,17 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.upload(file={ +) as mistral: + + res = mistral.files.upload(file={ "file_name": "example.file", "content": open("example.file", "rb"), }) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -72,12 +74,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.list() +) as mistral: + + res = mistral.files.list() - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -115,12 +119,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.retrieve(file_id="") +) as mistral: + + res = mistral.files.retrieve(file_id="") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` @@ -153,12 +159,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.delete(file_id="") +) as mistral: - if res is not None: - # handle response - pass + res = mistral.files.delete(file_id="") + + assert res is not None + + # Handle response + print(res) ``` @@ -191,12 +199,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.download(file_id="") +) as mistral: + + res = mistral.files.download(file_id="") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -229,12 +239,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.files.get_signed_url(file_id="") +) as mistral: + + res = mistral.files.get_signed_url(file_id="") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` diff --git a/docs/sdks/fim/README.md b/docs/sdks/fim/README.md index eed1893..0609997 100644 --- a/docs/sdks/fim/README.md +++ b/docs/sdks/fim/README.md @@ -22,12 +22,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fim.complete(model="codestral-2405", prompt="def", suffix="return a+b") +) as mistral: - if res is not None: - # handle response - pass + res = mistral.fim.complete(model="codestral-2405", prompt="def", suffix="return a+b") + + assert res is not None + + # Handle response + print(res) ``` @@ -70,14 +72,16 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fim.stream(model="codestral-2405", prompt="def", suffix="return a+b") - - if res is not None: - with res as event_stream: - for event in event_stream: - # handle event - print(event, flush=True) +) as mistral: + + res = mistral.fim.stream(model="codestral-2405", prompt="def", suffix="return a+b") + + assert res is not None + + with res as event_stream: + for event in event_stream: + # handle event + print(event, flush=True) ``` diff --git a/docs/sdks/jobs/README.md b/docs/sdks/jobs/README.md index b477958..9240663 100644 --- a/docs/sdks/jobs/README.md +++ b/docs/sdks/jobs/README.md @@ -23,12 +23,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fine_tuning.jobs.list() +) as mistral: - if res is not None: - # handle response - pass + res = mistral.fine_tuning.jobs.list() + + assert res is not None + + # Handle response + print(res) ``` @@ -69,12 +71,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fine_tuning.jobs.create(model="codestral-latest", hyperparameters={}) +) as mistral: + + res = mistral.fine_tuning.jobs.create(model="codestral-latest", hyperparameters={}) - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -114,12 +118,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fine_tuning.jobs.get(job_id="b18d8d81-fd7b-4764-a31e-475cb1f36591") +) as mistral: + + res = mistral.fine_tuning.jobs.get(job_id="b18d8d81-fd7b-4764-a31e-475cb1f36591") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -152,12 +158,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fine_tuning.jobs.cancel(job_id="03fa7112-315a-4072-a9f2-43f3f1ec962e") +) as mistral: + + res = mistral.fine_tuning.jobs.cancel(job_id="03fa7112-315a-4072-a9f2-43f3f1ec962e") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` @@ -190,12 +198,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.fine_tuning.jobs.start(job_id="0eb0f807-fb9f-4e46-9c13-4e257df6e1ba") +) as mistral: + + res = mistral.fine_tuning.jobs.start(job_id="0eb0f807-fb9f-4e46-9c13-4e257df6e1ba") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` diff --git a/docs/sdks/mistraljobs/README.md b/docs/sdks/mistraljobs/README.md index 1880c83..118cfcc 100644 --- a/docs/sdks/mistraljobs/README.md +++ b/docs/sdks/mistraljobs/README.md @@ -22,12 +22,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.batch.jobs.list() +) as mistral: - if res is not None: - # handle response - pass + res = mistral.batch.jobs.list() + + assert res is not None + + # Handle response + print(res) ``` @@ -66,14 +68,16 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.batch.jobs.create(input_files=[ +) as mistral: + + res = mistral.batch.jobs.create(input_files=[ "a621cf02-1cd9-4cf5-8403-315211a509a3", ], endpoint="/v1/fim/completions", model="2") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -110,12 +114,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.batch.jobs.get(job_id="b888f774-3e7c-4135-a18c-6b985523c4bc") +) as mistral: - if res is not None: - # handle response - pass + res = mistral.batch.jobs.get(job_id="b888f774-3e7c-4135-a18c-6b985523c4bc") + + assert res is not None + + # Handle response + print(res) ``` @@ -148,12 +154,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.batch.jobs.cancel(job_id="0f713502-9233-41c6-9ebd-c570b7edb496") +) as mistral: + + res = mistral.batch.jobs.cancel(job_id="0f713502-9233-41c6-9ebd-c570b7edb496") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` diff --git a/docs/sdks/models/README.md b/docs/sdks/models/README.md index 7888494..080b355 100644 --- a/docs/sdks/models/README.md +++ b/docs/sdks/models/README.md @@ -26,12 +26,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.list() +) as mistral: - if res is not None: - # handle response - pass + res = mistral.models.list() + + assert res is not None + + # Handle response + print(res) ``` @@ -64,12 +66,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.retrieve(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") +) as mistral: + + res = mistral.models.retrieve(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -103,12 +107,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.delete(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") +) as mistral: + + res = mistral.models.delete(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` @@ -142,12 +148,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.update(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") +) as mistral: - if res is not None: - # handle response - pass + res = mistral.models.update(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") + + assert res is not None + + # Handle response + print(res) ``` @@ -182,12 +190,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.archive(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") +) as mistral: + + res = mistral.models.archive(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") - if res is not None: - # handle response - pass + assert res is not None + + # Handle response + print(res) ``` @@ -220,12 +230,14 @@ import os with Mistral( api_key=os.getenv("MISTRAL_API_KEY", ""), -) as s: - res = s.models.unarchive(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") +) as mistral: + + res = mistral.models.unarchive(model_id="ft:open-mistral-7b:587a6b29:20240514:7e773925") + + assert res is not None - if res is not None: - # handle response - pass + # Handle response + print(res) ``` diff --git a/packages/mistralai_azure/.gitignore b/packages/mistralai_azure/.gitignore index 7755092..5a82b06 100644 --- a/packages/mistralai_azure/.gitignore +++ b/packages/mistralai_azure/.gitignore @@ -1,3 +1,4 @@ +.speakeasy/reports README-PYPI.md .venv/ venv/ diff --git a/packages/mistralai_azure/.speakeasy/gen.lock b/packages/mistralai_azure/.speakeasy/gen.lock index 15388f4..16a5196 100644 --- a/packages/mistralai_azure/.speakeasy/gen.lock +++ b/packages/mistralai_azure/.speakeasy/gen.lock @@ -1,18 +1,18 @@ lockVersion: 2.0.0 id: dc40fa48-2c4d-46ad-ac8b-270749770f34 management: - docChecksum: 26271aa279a7a7182f7af19df8b67038 + docChecksum: 4da7c33f650ddf206c58fa6c941d347f docVersion: 0.0.2 - speakeasyVersion: 1.451.1 - generationVersion: 2.470.1 - releaseVersion: 1.2.3 - configChecksum: 60295c765204eb0aa26205ec02e574fc + speakeasyVersion: 1.462.2 + generationVersion: 2.486.1 + releaseVersion: 1.2.6 + configChecksum: cc2ac1769a87215774fce0075ff2e77d published: true features: python: additionalDependencies: 1.0.0 constsAndDefaults: 1.0.5 - core: 5.6.8 + core: 5.7.4 defaultEnabledRetries: 0.2.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.3.2 @@ -21,9 +21,9 @@ features: globalSecurity: 3.0.2 globalSecurityCallbacks: 1.0.0 globalSecurityFlattening: 1.0.0 - globalServerURLs: 3.0.0 + globalServerURLs: 3.1.0 methodArguments: 1.0.2 - nameOverrides: 3.0.0 + nameOverrides: 3.0.1 nullables: 1.0.0 openEnums: 1.0.0 responseFormat: 1.0.1 @@ -157,6 +157,9 @@ examples: speakeasy-default-stream-chat: requestBody: application/json: {"model": "azureai", "messages": [{"content": "Who is the best French painter? Answer in one short sentence.", "role": "user"}]} + responses: + "422": + application/json: {} chat_completion_v1_chat_completions_post: speakeasy-default-chat-completion-v1-chat-completions-post: requestBody: @@ -164,5 +167,6 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} generatedTests: {} diff --git a/packages/mistralai_azure/.speakeasy/gen.yaml b/packages/mistralai_azure/.speakeasy/gen.yaml index aae8dd2..17344d9 100644 --- a/packages/mistralai_azure/.speakeasy/gen.yaml +++ b/packages/mistralai_azure/.speakeasy/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false python: - version: 1.2.3 + version: 1.2.6 additionalDependencies: dev: pytest: ^8.2.2 diff --git a/packages/mistralai_azure/pyproject.toml b/packages/mistralai_azure/pyproject.toml index a7a0a37..5c227f6 100644 --- a/packages/mistralai_azure/pyproject.toml +++ b/packages/mistralai_azure/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mistralai_azure" -version = "1.2.3" +version = "1.2.6" description = "Python Client SDK for the Mistral AI API in Azure." authors = ["Mistral",] readme = "README-PYPI.md" @@ -18,9 +18,9 @@ in-project = true [tool.poetry.dependencies] python = "^3.8" eval-type-backport = "^0.2.0" -httpx = "^0.27.0" +httpx = "^0.28.1" jsonpath-python = "^1.0.6" -pydantic = "~2.9.2" +pydantic = "~2.10.3" python-dateutil = "^2.8.2" typing-inspect = "^0.9.0" diff --git a/packages/mistralai_azure/src/mistralai_azure/_version.py b/packages/mistralai_azure/src/mistralai_azure/_version.py index 1e41e4f..c7215b8 100644 --- a/packages/mistralai_azure/src/mistralai_azure/_version.py +++ b/packages/mistralai_azure/src/mistralai_azure/_version.py @@ -3,7 +3,7 @@ import importlib.metadata __title__: str = "mistralai_azure" -__version__: str = "1.2.3" +__version__: str = "1.2.6" try: if __package__ is not None: diff --git a/packages/mistralai_azure/src/mistralai_azure/basesdk.py b/packages/mistralai_azure/src/mistralai_azure/basesdk.py index 772b44c..05c100d 100644 --- a/packages/mistralai_azure/src/mistralai_azure/basesdk.py +++ b/packages/mistralai_azure/src/mistralai_azure/basesdk.py @@ -9,7 +9,8 @@ BeforeRequestContext, ) from mistralai_azure.utils import RetryConfig, SerializedRequestBody, get_body_content -from typing import Callable, List, Optional, Tuple +from typing import Callable, List, Mapping, Optional, Tuple +from urllib.parse import parse_qs, urlparse class BaseSDK: @@ -18,7 +19,7 @@ class BaseSDK: def __init__(self, sdk_config: SDKConfiguration) -> None: self.sdk_configuration = sdk_config - def get_url(self, base_url, url_variables): + def _get_url(self, base_url, url_variables): sdk_url, sdk_variables = self.sdk_configuration.get_server_details() if base_url is None: @@ -29,7 +30,7 @@ def get_url(self, base_url, url_variables): return utils.template_url(base_url, url_variables) - def build_request_async( + def _build_request_async( self, method, path, @@ -48,9 +49,10 @@ def build_request_async( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.async_client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -67,9 +69,10 @@ def build_request_async( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request( + def _build_request( self, method, path, @@ -88,9 +91,10 @@ def build_request( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -107,9 +111,10 @@ def build_request( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request_with_client( + def _build_request_with_client( self, client, method, @@ -129,13 +134,14 @@ def build_request_with_client( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: query_params = {} url = url_override if url is None: url = utils.generate_url( - self.get_url(base_url, url_variables), + self._get_url(base_url, url_variables), path, request if request_has_path_params else None, _globals if request_has_path_params else None, @@ -145,6 +151,12 @@ def build_request_with_client( request if request_has_query_params else None, _globals if request_has_query_params else None, ) + else: + # Pick up the query parameter from the override so they can be + # preserved when building the request later on (necessary as of + # httpx 0.28). + parsed_override = urlparse(str(url_override)) + query_params = parse_qs(parsed_override.query, keep_blank_values=True) headers = utils.get_headers(request, _globals) headers["Accept"] = accept_header_value @@ -159,7 +171,7 @@ def build_request_with_client( headers = {**headers, **security_headers} query_params = {**query_params, **security_query_params} - serialized_request_body = SerializedRequestBody("application/octet-stream") + serialized_request_body = SerializedRequestBody() if get_serialized_body is not None: rb = get_serialized_body() if request_body_required and rb is None: @@ -178,6 +190,10 @@ def build_request_with_client( ): headers["content-type"] = serialized_request_body.media_type + if http_headers is not None: + for header, value in http_headers.items(): + headers[header] = value + timeout = timeout_ms / 1000 if timeout_ms is not None else None return client.build_request( diff --git a/packages/mistralai_azure/src/mistralai_azure/chat.py b/packages/mistralai_azure/src/mistralai_azure/chat.py index afab9ba..0ed464b 100644 --- a/packages/mistralai_azure/src/mistralai_azure/chat.py +++ b/packages/mistralai_azure/src/mistralai_azure/chat.py @@ -5,7 +5,7 @@ from mistralai_azure._hooks import HookContext from mistralai_azure.types import OptionalNullable, UNSET from mistralai_azure.utils import eventstreaming -from typing import Any, List, Optional, Union +from typing import Any, List, Mapping, Optional, Union class Chat(BaseSDK): @@ -17,7 +17,7 @@ def stream( messages: Union[List[models.Messages], List[models.MessagesTypedDict]], model: OptionalNullable[str] = "azureai", temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -37,10 +37,11 @@ def stream( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream chat completion @@ -64,6 +65,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -95,7 +97,7 @@ def stream( safe_prompt=safe_prompt, ) - req = self.build_request( + req = self._build_request( method="POST", path="/chat/completions#stream", base_url=base_url, @@ -106,6 +108,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest @@ -165,7 +168,7 @@ async def stream_async( messages: Union[List[models.Messages], List[models.MessagesTypedDict]], model: OptionalNullable[str] = "azureai", temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -185,10 +188,11 @@ async def stream_async( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream chat completion @@ -212,6 +216,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -243,7 +248,7 @@ async def stream_async( safe_prompt=safe_prompt, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/chat/completions#stream", base_url=base_url, @@ -254,6 +259,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest @@ -316,7 +322,7 @@ def complete( ], model: OptionalNullable[str] = "azureai", temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[ @@ -341,10 +347,11 @@ def complete( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -366,6 +373,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -399,7 +407,7 @@ def complete( safe_prompt=safe_prompt, ) - req = self.build_request( + req = self._build_request( method="POST", path="/chat/completions", base_url=base_url, @@ -410,6 +418,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest @@ -468,7 +477,7 @@ async def complete_async( ], model: OptionalNullable[str] = "azureai", temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[ @@ -493,10 +502,11 @@ async def complete_async( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -518,6 +528,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -551,7 +562,7 @@ async def complete_async( safe_prompt=safe_prompt, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/chat/completions", base_url=base_url, @@ -562,6 +573,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest diff --git a/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionrequest.py b/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionrequest.py index 3e4e9a3..67c91bb 100644 --- a/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionrequest.py +++ b/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionrequest.py @@ -107,7 +107,7 @@ class ChatCompletionRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET @@ -137,7 +137,7 @@ class ChatCompletionRequest(BaseModel): n: OptionalNullable[int] = UNSET r"""Number of completions to return for each request, input tokens are only billed once.""" - safe_prompt: Optional[bool] = False + safe_prompt: Optional[bool] = None r"""Whether to inject a safety prompt before all conversations.""" @model_serializer(mode="wrap") diff --git a/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionstreamrequest.py b/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionstreamrequest.py index 6d1f6bb..465647e 100644 --- a/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionstreamrequest.py +++ b/packages/mistralai_azure/src/mistralai_azure/models/chatcompletionstreamrequest.py @@ -102,7 +102,7 @@ class ChatCompletionStreamRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET @@ -131,7 +131,7 @@ class ChatCompletionStreamRequest(BaseModel): n: OptionalNullable[int] = UNSET r"""Number of completions to return for each request, input tokens are only billed once.""" - safe_prompt: Optional[bool] = False + safe_prompt: Optional[bool] = None r"""Whether to inject a safety prompt before all conversations.""" @model_serializer(mode="wrap") diff --git a/packages/mistralai_azure/src/mistralai_azure/sdkconfiguration.py b/packages/mistralai_azure/src/mistralai_azure/sdkconfiguration.py index 191aa32..73b8d51 100644 --- a/packages/mistralai_azure/src/mistralai_azure/sdkconfiguration.py +++ b/packages/mistralai_azure/src/mistralai_azure/sdkconfiguration.py @@ -28,9 +28,9 @@ class SDKConfiguration: server: Optional[str] = "" language: str = "python" openapi_doc_version: str = "0.0.2" - sdk_version: str = "1.2.3" - gen_version: str = "2.470.1" - user_agent: str = "speakeasy-sdk/python 1.2.3 2.470.1 0.0.2 mistralai_azure" + sdk_version: str = "1.2.6" + gen_version: str = "2.486.1" + user_agent: str = "speakeasy-sdk/python 1.2.6 2.486.1 0.0.2 mistralai_azure" retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET) timeout_ms: Optional[int] = None diff --git a/packages/mistralai_azure/src/mistralai_azure/utils/forms.py b/packages/mistralai_azure/src/mistralai_azure/utils/forms.py index 9f5a731..0472aba 100644 --- a/packages/mistralai_azure/src/mistralai_azure/utils/forms.py +++ b/packages/mistralai_azure/src/mistralai_azure/utils/forms.py @@ -109,13 +109,12 @@ def serialize_multipart_form( if not field_metadata: continue - f_name = field.alias if field.alias is not None else name + f_name = field.alias if field.alias else name if field_metadata.file: file_fields: Dict[str, FieldInfo] = val.__class__.model_fields file_name = "" - field_name = "" content = None content_type = None @@ -131,20 +130,15 @@ def serialize_multipart_form( elif file_field_name == "content_type": content_type = getattr(val, file_field_name, None) else: - field_name = ( - file_field.alias - if file_field.alias is not None - else file_field_name - ) file_name = getattr(val, file_field_name) - if field_name == "" or file_name == "" or content is None: + if file_name == "" or content is None: raise ValueError("invalid multipart/form-data file") if content_type is not None: - files[field_name] = (file_name, content, content_type) + files[f_name] = (file_name, content, content_type) else: - files[field_name] = (file_name, content) + files[f_name] = (file_name, content) elif field_metadata.json: files[f_name] = ( None, diff --git a/packages/mistralai_azure/src/mistralai_azure/utils/requestbodies.py b/packages/mistralai_azure/src/mistralai_azure/utils/requestbodies.py index 4f586ae..d5240dd 100644 --- a/packages/mistralai_azure/src/mistralai_azure/utils/requestbodies.py +++ b/packages/mistralai_azure/src/mistralai_azure/utils/requestbodies.py @@ -23,7 +23,7 @@ @dataclass class SerializedRequestBody: - media_type: str + media_type: Optional[str] = None content: Optional[Any] = None data: Optional[Any] = None files: Optional[Any] = None diff --git a/packages/mistralai_gcp/.gitignore b/packages/mistralai_gcp/.gitignore index 7755092..5a82b06 100644 --- a/packages/mistralai_gcp/.gitignore +++ b/packages/mistralai_gcp/.gitignore @@ -1,3 +1,4 @@ +.speakeasy/reports README-PYPI.md .venv/ venv/ diff --git a/packages/mistralai_gcp/.speakeasy/gen.lock b/packages/mistralai_gcp/.speakeasy/gen.lock index ee99e6b..f74b975 100644 --- a/packages/mistralai_gcp/.speakeasy/gen.lock +++ b/packages/mistralai_gcp/.speakeasy/gen.lock @@ -1,18 +1,18 @@ lockVersion: 2.0.0 id: ec60f2d8-7869-45c1-918e-773d41a8cf74 management: - docChecksum: d50a06ac34844141709fa2e57cc940c5 + docChecksum: 849dde0ef239604ca71711ffc1220b54 docVersion: 0.0.2 - speakeasyVersion: 1.451.1 - generationVersion: 2.470.1 - releaseVersion: 1.2.3 - configChecksum: 3fc99d7ec7ee057a323b593ebf8fdb8c + speakeasyVersion: 1.462.2 + generationVersion: 2.486.1 + releaseVersion: 1.2.6 + configChecksum: ba11718a5b49fb4a979ae9693a68b191 published: true features: python: additionalDependencies: 1.0.0 constsAndDefaults: 1.0.5 - core: 5.6.8 + core: 5.7.4 defaultEnabledRetries: 0.2.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.3.2 @@ -21,9 +21,9 @@ features: globalSecurity: 3.0.2 globalSecurityCallbacks: 1.0.0 globalSecurityFlattening: 1.0.0 - globalServerURLs: 3.0.0 + globalServerURLs: 3.1.0 methodArguments: 1.0.2 - nameOverrides: 3.0.0 + nameOverrides: 3.0.1 nullables: 1.0.0 openEnums: 1.0.0 responseFormat: 1.0.1 @@ -166,6 +166,9 @@ examples: speakeasy-default-stream-chat: requestBody: application/json: {"model": "mistral-small-latest", "messages": [{"content": "Who is the best French painter? Answer in one short sentence.", "role": "user"}]} + responses: + "422": + application/json: {} chat_completion_v1_chat_completions_post: speakeasy-default-chat-completion-v1-chat-completions-post: requestBody: @@ -173,11 +176,15 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} stream_fim: speakeasy-default-stream-fim: requestBody: application/json: {"model": "codestral-2405", "prompt": "def", "suffix": "return a+b"} + responses: + "422": + application/json: {} fim_completion_v1_fim_completions_post: speakeasy-default-fim-completion-v1-fim-completions-post: requestBody: @@ -185,5 +192,6 @@ examples: responses: "200": application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "codestral-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": []} - "422": {} + "422": + application/json: {} generatedTests: {} diff --git a/packages/mistralai_gcp/.speakeasy/gen.yaml b/packages/mistralai_gcp/.speakeasy/gen.yaml index a77e2f5..583aaf5 100644 --- a/packages/mistralai_gcp/.speakeasy/gen.yaml +++ b/packages/mistralai_gcp/.speakeasy/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false python: - version: 1.2.3 + version: 1.2.6 additionalDependencies: dev: pytest: ^8.2.2 diff --git a/packages/mistralai_gcp/pyproject.toml b/packages/mistralai_gcp/pyproject.toml index 670c1e3..6692f1d 100644 --- a/packages/mistralai_gcp/pyproject.toml +++ b/packages/mistralai_gcp/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mistralai-gcp" -version = "1.2.3" +version = "1.2.6" description = "Python Client SDK for the Mistral AI API in GCP." authors = ["Mistral",] readme = "README-PYPI.md" @@ -19,9 +19,9 @@ in-project = true python = "^3.8" eval-type-backport = "^0.2.0" google-auth = "2.27.0" -httpx = "^0.27.0" +httpx = "^0.28.1" jsonpath-python = "^1.0.6" -pydantic = "~2.9.2" +pydantic = "~2.10.3" python-dateutil = "^2.8.2" requests = "^2.32.3" typing-inspect = "^0.9.0" diff --git a/packages/mistralai_gcp/src/mistralai_gcp/_version.py b/packages/mistralai_gcp/src/mistralai_gcp/_version.py index 5b65a1b..30081f3 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/_version.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/_version.py @@ -3,7 +3,7 @@ import importlib.metadata __title__: str = "mistralai-gcp" -__version__: str = "1.2.3" +__version__: str = "1.2.6" try: if __package__ is not None: diff --git a/packages/mistralai_gcp/src/mistralai_gcp/basesdk.py b/packages/mistralai_gcp/src/mistralai_gcp/basesdk.py index c647eba..4062001 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/basesdk.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/basesdk.py @@ -9,7 +9,8 @@ BeforeRequestContext, ) from mistralai_gcp.utils import RetryConfig, SerializedRequestBody, get_body_content -from typing import Callable, List, Optional, Tuple +from typing import Callable, List, Mapping, Optional, Tuple +from urllib.parse import parse_qs, urlparse class BaseSDK: @@ -18,7 +19,7 @@ class BaseSDK: def __init__(self, sdk_config: SDKConfiguration) -> None: self.sdk_configuration = sdk_config - def get_url(self, base_url, url_variables): + def _get_url(self, base_url, url_variables): sdk_url, sdk_variables = self.sdk_configuration.get_server_details() if base_url is None: @@ -29,7 +30,7 @@ def get_url(self, base_url, url_variables): return utils.template_url(base_url, url_variables) - def build_request_async( + def _build_request_async( self, method, path, @@ -48,9 +49,10 @@ def build_request_async( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.async_client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -67,9 +69,10 @@ def build_request_async( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request( + def _build_request( self, method, path, @@ -88,9 +91,10 @@ def build_request( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -107,9 +111,10 @@ def build_request( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request_with_client( + def _build_request_with_client( self, client, method, @@ -129,13 +134,14 @@ def build_request_with_client( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: query_params = {} url = url_override if url is None: url = utils.generate_url( - self.get_url(base_url, url_variables), + self._get_url(base_url, url_variables), path, request if request_has_path_params else None, _globals if request_has_path_params else None, @@ -145,6 +151,12 @@ def build_request_with_client( request if request_has_query_params else None, _globals if request_has_query_params else None, ) + else: + # Pick up the query parameter from the override so they can be + # preserved when building the request later on (necessary as of + # httpx 0.28). + parsed_override = urlparse(str(url_override)) + query_params = parse_qs(parsed_override.query, keep_blank_values=True) headers = utils.get_headers(request, _globals) headers["Accept"] = accept_header_value @@ -159,7 +171,7 @@ def build_request_with_client( headers = {**headers, **security_headers} query_params = {**query_params, **security_query_params} - serialized_request_body = SerializedRequestBody("application/octet-stream") + serialized_request_body = SerializedRequestBody() if get_serialized_body is not None: rb = get_serialized_body() if request_body_required and rb is None: @@ -178,6 +190,10 @@ def build_request_with_client( ): headers["content-type"] = serialized_request_body.media_type + if http_headers is not None: + for header, value in http_headers.items(): + headers[header] = value + timeout = timeout_ms / 1000 if timeout_ms is not None else None return client.build_request( diff --git a/packages/mistralai_gcp/src/mistralai_gcp/chat.py b/packages/mistralai_gcp/src/mistralai_gcp/chat.py index 19c9265..47e5b63 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/chat.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/chat.py @@ -5,7 +5,7 @@ from mistralai_gcp._hooks import HookContext from mistralai_gcp.types import Nullable, OptionalNullable, UNSET from mistralai_gcp.utils import eventstreaming -from typing import Any, List, Optional, Union +from typing import Any, List, Mapping, Optional, Union class Chat(BaseSDK): @@ -17,7 +17,7 @@ def stream( model: Nullable[str], messages: Union[List[models.Messages], List[models.MessagesTypedDict]], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -40,6 +40,7 @@ def stream( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream chat completion @@ -62,6 +63,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -92,7 +94,7 @@ def stream( n=n, ) - req = self.build_request( + req = self._build_request( method="POST", path="/streamRawPredict", base_url=base_url, @@ -103,6 +105,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest @@ -162,7 +165,7 @@ async def stream_async( model: Nullable[str], messages: Union[List[models.Messages], List[models.MessagesTypedDict]], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -185,6 +188,7 @@ async def stream_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream chat completion @@ -207,6 +211,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -237,7 +242,7 @@ async def stream_async( n=n, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/streamRawPredict", base_url=base_url, @@ -248,6 +253,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest @@ -310,7 +316,7 @@ def complete( List[models.ChatCompletionRequestMessagesTypedDict], ], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[ @@ -338,6 +344,7 @@ def complete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -358,6 +365,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -390,7 +398,7 @@ def complete( n=n, ) - req = self.build_request( + req = self._build_request( method="POST", path="/rawPredict", base_url=base_url, @@ -401,6 +409,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest @@ -459,7 +468,7 @@ async def complete_async( List[models.ChatCompletionRequestMessagesTypedDict], ], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[ @@ -487,6 +496,7 @@ async def complete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -507,6 +517,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -539,7 +550,7 @@ async def complete_async( n=n, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/rawPredict", base_url=base_url, @@ -550,6 +561,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest diff --git a/packages/mistralai_gcp/src/mistralai_gcp/fim.py b/packages/mistralai_gcp/src/mistralai_gcp/fim.py index bddc010..89146a4 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/fim.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/fim.py @@ -5,7 +5,7 @@ from mistralai_gcp._hooks import HookContext from mistralai_gcp.types import Nullable, OptionalNullable, UNSET from mistralai_gcp.utils import eventstreaming -from typing import Any, Optional, Union +from typing import Any, Mapping, Optional, Union class Fim(BaseSDK): @@ -32,6 +32,7 @@ def stream( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream fim completion @@ -50,6 +51,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -72,7 +74,7 @@ def stream( min_tokens=min_tokens, ) - req = self.build_request( + req = self._build_request( method="POST", path="/streamRawPredict#fim", base_url=base_url, @@ -83,6 +85,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionStreamRequest @@ -157,6 +160,7 @@ async def stream_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream fim completion @@ -175,6 +179,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -197,7 +202,7 @@ async def stream_async( min_tokens=min_tokens, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/streamRawPredict#fim", base_url=base_url, @@ -208,6 +213,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionStreamRequest @@ -282,6 +288,7 @@ def complete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FIMCompletionResponse]: r"""Fim Completion @@ -300,6 +307,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -322,7 +330,7 @@ def complete( min_tokens=min_tokens, ) - req = self.build_request( + req = self._build_request( method="POST", path="/rawPredict#fim", base_url=base_url, @@ -333,6 +341,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionRequest @@ -403,6 +412,7 @@ async def complete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FIMCompletionResponse]: r"""Fim Completion @@ -421,6 +431,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -443,7 +454,7 @@ async def complete_async( min_tokens=min_tokens, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/rawPredict#fim", base_url=base_url, @@ -454,6 +465,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionRequest diff --git a/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py b/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py index b8ebfc9..ab97e52 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionrequest.py @@ -105,7 +105,7 @@ class ChatCompletionRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET diff --git a/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionstreamrequest.py b/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionstreamrequest.py index b710a27..e6c5429 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionstreamrequest.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/models/chatcompletionstreamrequest.py @@ -100,7 +100,7 @@ class ChatCompletionStreamRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET diff --git a/packages/mistralai_gcp/src/mistralai_gcp/sdkconfiguration.py b/packages/mistralai_gcp/src/mistralai_gcp/sdkconfiguration.py index b580081..3c149cc 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/sdkconfiguration.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/sdkconfiguration.py @@ -28,9 +28,9 @@ class SDKConfiguration: server: Optional[str] = "" language: str = "python" openapi_doc_version: str = "0.0.2" - sdk_version: str = "1.2.3" - gen_version: str = "2.470.1" - user_agent: str = "speakeasy-sdk/python 1.2.3 2.470.1 0.0.2 mistralai-gcp" + sdk_version: str = "1.2.6" + gen_version: str = "2.486.1" + user_agent: str = "speakeasy-sdk/python 1.2.6 2.486.1 0.0.2 mistralai-gcp" retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET) timeout_ms: Optional[int] = None diff --git a/packages/mistralai_gcp/src/mistralai_gcp/utils/forms.py b/packages/mistralai_gcp/src/mistralai_gcp/utils/forms.py index 9f5a731..0472aba 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/utils/forms.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/utils/forms.py @@ -109,13 +109,12 @@ def serialize_multipart_form( if not field_metadata: continue - f_name = field.alias if field.alias is not None else name + f_name = field.alias if field.alias else name if field_metadata.file: file_fields: Dict[str, FieldInfo] = val.__class__.model_fields file_name = "" - field_name = "" content = None content_type = None @@ -131,20 +130,15 @@ def serialize_multipart_form( elif file_field_name == "content_type": content_type = getattr(val, file_field_name, None) else: - field_name = ( - file_field.alias - if file_field.alias is not None - else file_field_name - ) file_name = getattr(val, file_field_name) - if field_name == "" or file_name == "" or content is None: + if file_name == "" or content is None: raise ValueError("invalid multipart/form-data file") if content_type is not None: - files[field_name] = (file_name, content, content_type) + files[f_name] = (file_name, content, content_type) else: - files[field_name] = (file_name, content) + files[f_name] = (file_name, content) elif field_metadata.json: files[f_name] = ( None, diff --git a/packages/mistralai_gcp/src/mistralai_gcp/utils/requestbodies.py b/packages/mistralai_gcp/src/mistralai_gcp/utils/requestbodies.py index 4f586ae..d5240dd 100644 --- a/packages/mistralai_gcp/src/mistralai_gcp/utils/requestbodies.py +++ b/packages/mistralai_gcp/src/mistralai_gcp/utils/requestbodies.py @@ -23,7 +23,7 @@ @dataclass class SerializedRequestBody: - media_type: str + media_type: Optional[str] = None content: Optional[Any] = None data: Optional[Any] = None files: Optional[Any] = None diff --git a/pyproject.toml b/pyproject.toml index d3c6fb5..9f5e9f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mistralai" -version = "1.2.5" +version = "1.2.6" description = "Python Client SDK for the Mistral AI API." authors = ["Mistral"] readme = "README-PYPI.md" diff --git a/src/mistralai/_version.py b/src/mistralai/_version.py index d135096..d4a21d0 100644 --- a/src/mistralai/_version.py +++ b/src/mistralai/_version.py @@ -3,7 +3,7 @@ import importlib.metadata __title__: str = "mistralai" -__version__: str = "1.2.5" +__version__: str = "1.2.6" try: if __package__ is not None: diff --git a/src/mistralai/agents.py b/src/mistralai/agents.py index 246cab4..621224e 100644 --- a/src/mistralai/agents.py +++ b/src/mistralai/agents.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import eventstreaming, get_security_from_env -from typing import Any, List, Optional, Union +from typing import Any, List, Mapping, Optional, Union class Agents(BaseSDK): @@ -46,6 +46,7 @@ def complete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Agents Completion @@ -64,6 +65,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -94,7 +96,7 @@ def complete( agent_id=agent_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/agents/completions", base_url=base_url, @@ -105,6 +107,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.AgentsCompletionRequest @@ -191,6 +194,7 @@ async def complete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Agents Completion @@ -209,6 +213,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -239,7 +244,7 @@ async def complete_async( agent_id=agent_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/agents/completions", base_url=base_url, @@ -250,6 +255,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.AgentsCompletionRequest @@ -336,6 +342,7 @@ def stream( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream Agents completion @@ -356,6 +363,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -386,7 +394,7 @@ def stream( agent_id=agent_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/agents/completions#stream", base_url=base_url, @@ -397,6 +405,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.AgentsCompletionStreamRequest @@ -487,6 +496,7 @@ async def stream_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream Agents completion @@ -507,6 +517,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -537,7 +548,7 @@ async def stream_async( agent_id=agent_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/agents/completions#stream", base_url=base_url, @@ -548,6 +559,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.AgentsCompletionStreamRequest diff --git a/src/mistralai/basesdk.py b/src/mistralai/basesdk.py index 3fc2bdd..cda8add 100644 --- a/src/mistralai/basesdk.py +++ b/src/mistralai/basesdk.py @@ -9,7 +9,8 @@ BeforeRequestContext, ) from mistralai.utils import RetryConfig, SerializedRequestBody, get_body_content -from typing import Callable, List, Optional, Tuple +from typing import Callable, List, Mapping, Optional, Tuple +from urllib.parse import parse_qs, urlparse class BaseSDK: @@ -18,7 +19,7 @@ class BaseSDK: def __init__(self, sdk_config: SDKConfiguration) -> None: self.sdk_configuration = sdk_config - def get_url(self, base_url, url_variables): + def _get_url(self, base_url, url_variables): sdk_url, sdk_variables = self.sdk_configuration.get_server_details() if base_url is None: @@ -29,7 +30,7 @@ def get_url(self, base_url, url_variables): return utils.template_url(base_url, url_variables) - def build_request_async( + def _build_request_async( self, method, path, @@ -48,9 +49,10 @@ def build_request_async( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.async_client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -67,9 +69,10 @@ def build_request_async( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request( + def _build_request( self, method, path, @@ -88,9 +91,10 @@ def build_request( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: client = self.sdk_configuration.client - return self.build_request_with_client( + return self._build_request_with_client( client, method, path, @@ -107,9 +111,10 @@ def build_request( timeout_ms, get_serialized_body, url_override, + http_headers, ) - def build_request_with_client( + def _build_request_with_client( self, client, method, @@ -129,13 +134,14 @@ def build_request_with_client( Callable[[], Optional[SerializedRequestBody]] ] = None, url_override: Optional[str] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> httpx.Request: query_params = {} url = url_override if url is None: url = utils.generate_url( - self.get_url(base_url, url_variables), + self._get_url(base_url, url_variables), path, request if request_has_path_params else None, _globals if request_has_path_params else None, @@ -145,6 +151,12 @@ def build_request_with_client( request if request_has_query_params else None, _globals if request_has_query_params else None, ) + else: + # Pick up the query parameter from the override so they can be + # preserved when building the request later on (necessary as of + # httpx 0.28). + parsed_override = urlparse(str(url_override)) + query_params = parse_qs(parsed_override.query, keep_blank_values=True) headers = utils.get_headers(request, _globals) headers["Accept"] = accept_header_value @@ -159,7 +171,7 @@ def build_request_with_client( headers = {**headers, **security_headers} query_params = {**query_params, **security_query_params} - serialized_request_body = SerializedRequestBody("application/octet-stream") + serialized_request_body = SerializedRequestBody() if get_serialized_body is not None: rb = get_serialized_body() if request_body_required and rb is None: @@ -178,6 +190,10 @@ def build_request_with_client( ): headers["content-type"] = serialized_request_body.media_type + if http_headers is not None: + for header, value in http_headers.items(): + headers[header] = value + timeout = timeout_ms / 1000 if timeout_ms is not None else None return client.build_request( diff --git a/src/mistralai/chat.py b/src/mistralai/chat.py index 4b7aad3..9e07f78 100644 --- a/src/mistralai/chat.py +++ b/src/mistralai/chat.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import Nullable, OptionalNullable, UNSET from mistralai.utils import eventstreaming, get_security_from_env -from typing import Any, List, Optional, Union +from typing import Any, List, Mapping, Optional, Union class Chat(BaseSDK): @@ -17,7 +17,7 @@ def complete( model: Nullable[str], messages: Union[List[models.Messages], List[models.MessagesTypedDict]], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -37,10 +37,11 @@ def complete( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -62,6 +63,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -93,7 +95,7 @@ def complete( safe_prompt=safe_prompt, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/chat/completions", base_url=base_url, @@ -104,6 +106,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest @@ -161,7 +164,7 @@ async def complete_async( model: Nullable[str], messages: Union[List[models.Messages], List[models.MessagesTypedDict]], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = False, stop: Optional[Union[models.Stop, models.StopTypedDict]] = None, @@ -181,10 +184,11 @@ async def complete_async( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ChatCompletionResponse]: r"""Chat Completion @@ -206,6 +210,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -237,7 +242,7 @@ async def complete_async( safe_prompt=safe_prompt, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/chat/completions", base_url=base_url, @@ -248,6 +253,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionRequest @@ -308,7 +314,7 @@ def stream( List[models.ChatCompletionStreamRequestMessagesTypedDict], ], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[ @@ -333,10 +339,11 @@ def stream( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream chat completion @@ -360,6 +367,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -393,7 +401,7 @@ def stream( safe_prompt=safe_prompt, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/chat/completions#stream", base_url=base_url, @@ -404,6 +412,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest @@ -468,7 +477,7 @@ async def stream_async( List[models.ChatCompletionStreamRequestMessagesTypedDict], ], temperature: OptionalNullable[float] = UNSET, - top_p: Optional[float] = 1, + top_p: Optional[float] = None, max_tokens: OptionalNullable[int] = UNSET, stream: Optional[bool] = True, stop: Optional[ @@ -493,10 +502,11 @@ async def stream_async( presence_penalty: Optional[float] = None, frequency_penalty: Optional[float] = None, n: OptionalNullable[int] = UNSET, - safe_prompt: Optional[bool] = False, + safe_prompt: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream chat completion @@ -520,6 +530,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -553,7 +564,7 @@ async def stream_async( safe_prompt=safe_prompt, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/chat/completions#stream", base_url=base_url, @@ -564,6 +575,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatCompletionStreamRequest diff --git a/src/mistralai/classifiers.py b/src/mistralai/classifiers.py index 3a77206..55253a1 100644 --- a/src/mistralai/classifiers.py +++ b/src/mistralai/classifiers.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import Nullable, OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import Any, Optional, Union +from typing import Any, Mapping, Optional, Union class Classifiers(BaseSDK): @@ -22,6 +22,7 @@ def moderate( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ClassificationResponse]: r"""Moderations @@ -30,6 +31,7 @@ def moderate( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -44,7 +46,7 @@ def moderate( model=model, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/moderations", base_url=base_url, @@ -55,6 +57,7 @@ def moderate( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ClassificationRequest @@ -117,6 +120,7 @@ async def moderate_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ClassificationResponse]: r"""Moderations @@ -125,6 +129,7 @@ async def moderate_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -139,7 +144,7 @@ async def moderate_async( model=model, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/moderations", base_url=base_url, @@ -150,6 +155,7 @@ async def moderate_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ClassificationRequest @@ -212,6 +218,7 @@ def moderate_chat( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ClassificationResponse]: r"""Moderations Chat @@ -220,6 +227,7 @@ def moderate_chat( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -236,7 +244,7 @@ def moderate_chat( model=model, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/chat/moderations", base_url=base_url, @@ -247,6 +255,7 @@ def moderate_chat( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatClassificationRequest @@ -309,6 +318,7 @@ async def moderate_chat_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ClassificationResponse]: r"""Moderations Chat @@ -317,6 +327,7 @@ async def moderate_chat_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -333,7 +344,7 @@ async def moderate_chat_async( model=model, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/chat/moderations", base_url=base_url, @@ -344,6 +355,7 @@ async def moderate_chat_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.ChatClassificationRequest diff --git a/src/mistralai/embeddings.py b/src/mistralai/embeddings.py index 2aa115c..bf80861 100644 --- a/src/mistralai/embeddings.py +++ b/src/mistralai/embeddings.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import Any, Optional, Union +from typing import Any, Mapping, Optional, Union class Embeddings(BaseSDK): @@ -20,6 +20,7 @@ def create( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.EmbeddingResponse]: r"""Embeddings @@ -31,6 +32,7 @@ def create( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -46,7 +48,7 @@ def create( encoding_format=encoding_format, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/embeddings", base_url=base_url, @@ -57,6 +59,7 @@ def create( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.EmbeddingRequest @@ -117,6 +120,7 @@ async def create_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.EmbeddingResponse]: r"""Embeddings @@ -128,6 +132,7 @@ async def create_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -143,7 +148,7 @@ async def create_async( encoding_format=encoding_format, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/embeddings", base_url=base_url, @@ -154,6 +159,7 @@ async def create_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.EmbeddingRequest diff --git a/src/mistralai/files.py b/src/mistralai/files.py index e2977be..aefa025 100644 --- a/src/mistralai/files.py +++ b/src/mistralai/files.py @@ -6,7 +6,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import List, Optional, Union +from typing import List, Mapping, Optional, Union class Files(BaseSDK): @@ -20,6 +20,7 @@ def upload( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.UploadFileOut]: r"""Upload File @@ -34,6 +35,7 @@ def upload( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -48,7 +50,7 @@ def upload( purpose=purpose, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/files", base_url=base_url, @@ -59,6 +61,7 @@ def upload( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, @@ -116,6 +119,7 @@ async def upload_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.UploadFileOut]: r"""Upload File @@ -130,6 +134,7 @@ async def upload_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -144,7 +149,7 @@ async def upload_async( purpose=purpose, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/files", base_url=base_url, @@ -155,6 +160,7 @@ async def upload_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, @@ -216,6 +222,7 @@ def list( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ListFilesOut]: r"""List Files @@ -230,6 +237,7 @@ def list( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -248,7 +256,7 @@ def list( purpose=purpose, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/files", base_url=base_url, @@ -259,6 +267,7 @@ def list( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -313,6 +322,7 @@ async def list_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ListFilesOut]: r"""List Files @@ -327,6 +337,7 @@ async def list_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -345,7 +356,7 @@ async def list_async( purpose=purpose, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/files", base_url=base_url, @@ -356,6 +367,7 @@ async def list_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -405,6 +417,7 @@ def retrieve( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.RetrieveFileOut]: r"""Retrieve File @@ -414,6 +427,7 @@ def retrieve( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -427,7 +441,7 @@ def retrieve( file_id=file_id, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/files/{file_id}", base_url=base_url, @@ -438,6 +452,7 @@ def retrieve( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -487,6 +502,7 @@ async def retrieve_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.RetrieveFileOut]: r"""Retrieve File @@ -496,6 +512,7 @@ async def retrieve_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -509,7 +526,7 @@ async def retrieve_async( file_id=file_id, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/files/{file_id}", base_url=base_url, @@ -520,6 +537,7 @@ async def retrieve_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -569,6 +587,7 @@ def delete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DeleteFileOut]: r"""Delete File @@ -578,6 +597,7 @@ def delete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -591,7 +611,7 @@ def delete( file_id=file_id, ) - req = self.build_request( + req = self._build_request( method="DELETE", path="/v1/files/{file_id}", base_url=base_url, @@ -602,6 +622,7 @@ def delete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -651,6 +672,7 @@ async def delete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DeleteFileOut]: r"""Delete File @@ -660,6 +682,7 @@ async def delete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -673,7 +696,7 @@ async def delete_async( file_id=file_id, ) - req = self.build_request_async( + req = self._build_request_async( method="DELETE", path="/v1/files/{file_id}", base_url=base_url, @@ -684,6 +707,7 @@ async def delete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -733,6 +757,7 @@ def download( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[httpx.Response]: r"""Download File @@ -742,6 +767,7 @@ def download( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -755,7 +781,7 @@ def download( file_id=file_id, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/files/{file_id}/content", base_url=base_url, @@ -766,6 +792,7 @@ def download( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/octet-stream", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -816,6 +843,7 @@ async def download_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[httpx.Response]: r"""Download File @@ -825,6 +853,7 @@ async def download_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -838,7 +867,7 @@ async def download_async( file_id=file_id, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/files/{file_id}/content", base_url=base_url, @@ -849,6 +878,7 @@ async def download_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/octet-stream", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -900,6 +930,7 @@ def get_signed_url( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FileSignedURL]: r"""Get Signed Url @@ -908,6 +939,7 @@ def get_signed_url( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -922,7 +954,7 @@ def get_signed_url( expiry=expiry, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/files/{file_id}/url", base_url=base_url, @@ -933,6 +965,7 @@ def get_signed_url( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -983,6 +1016,7 @@ async def get_signed_url_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FileSignedURL]: r"""Get Signed Url @@ -991,6 +1025,7 @@ async def get_signed_url_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -1005,7 +1040,7 @@ async def get_signed_url_async( expiry=expiry, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/files/{file_id}/url", base_url=base_url, @@ -1016,6 +1051,7 @@ async def get_signed_url_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) diff --git a/src/mistralai/fim.py b/src/mistralai/fim.py index 6f03631..60a4fd6 100644 --- a/src/mistralai/fim.py +++ b/src/mistralai/fim.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import Nullable, OptionalNullable, UNSET from mistralai.utils import eventstreaming, get_security_from_env -from typing import Any, Optional, Union +from typing import Any, Mapping, Optional, Union class Fim(BaseSDK): @@ -32,6 +32,7 @@ def complete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FIMCompletionResponse]: r"""Fim Completion @@ -50,6 +51,7 @@ def complete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -72,7 +74,7 @@ def complete( min_tokens=min_tokens, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fim/completions", base_url=base_url, @@ -83,6 +85,7 @@ def complete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionRequest @@ -155,6 +158,7 @@ async def complete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FIMCompletionResponse]: r"""Fim Completion @@ -173,6 +177,7 @@ async def complete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -195,7 +200,7 @@ async def complete_async( min_tokens=min_tokens, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fim/completions", base_url=base_url, @@ -206,6 +211,7 @@ async def complete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionRequest @@ -278,6 +284,7 @@ def stream( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]: r"""Stream fim completion @@ -296,6 +303,7 @@ def stream( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -318,7 +326,7 @@ def stream( min_tokens=min_tokens, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fim/completions#stream", base_url=base_url, @@ -329,6 +337,7 @@ def stream( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionStreamRequest @@ -405,6 +414,7 @@ async def stream_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]: r"""Stream fim completion @@ -423,6 +433,7 @@ async def stream_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -445,7 +456,7 @@ async def stream_async( min_tokens=min_tokens, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fim/completions#stream", base_url=base_url, @@ -456,6 +467,7 @@ async def stream_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="text/event-stream", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.FIMCompletionStreamRequest diff --git a/src/mistralai/jobs.py b/src/mistralai/jobs.py index 17085b9..afa1ff4 100644 --- a/src/mistralai/jobs.py +++ b/src/mistralai/jobs.py @@ -6,7 +6,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import List, Optional, Union +from typing import List, Mapping, Optional, Union class Jobs(BaseSDK): @@ -25,6 +25,7 @@ def list( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.JobsOut]: r"""Get Fine Tuning Jobs @@ -42,6 +43,7 @@ def list( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -63,7 +65,7 @@ def list( suffix=suffix, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/fine_tuning/jobs", base_url=base_url, @@ -74,6 +76,7 @@ def list( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -131,6 +134,7 @@ async def list_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.JobsOut]: r"""Get Fine Tuning Jobs @@ -148,6 +152,7 @@ async def list_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -169,7 +174,7 @@ async def list_async( suffix=suffix, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/fine_tuning/jobs", base_url=base_url, @@ -180,6 +185,7 @@ async def list_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -248,6 +254,7 @@ def create( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse]: r"""Create Fine Tuning Job @@ -264,6 +271,7 @@ def create( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -292,7 +300,7 @@ def create( auto_start=auto_start, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fine_tuning/jobs", base_url=base_url, @@ -303,6 +311,7 @@ def create( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.JobIn @@ -377,6 +386,7 @@ async def create_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse]: r"""Create Fine Tuning Job @@ -393,6 +403,7 @@ async def create_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -421,7 +432,7 @@ async def create_async( auto_start=auto_start, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fine_tuning/jobs", base_url=base_url, @@ -432,6 +443,7 @@ async def create_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.JobIn @@ -487,6 +499,7 @@ def get( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Get Fine Tuning Job @@ -496,6 +509,7 @@ def get( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -509,7 +523,7 @@ def get( job_id=job_id, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/fine_tuning/jobs/{job_id}", base_url=base_url, @@ -520,6 +534,7 @@ def get( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -569,6 +584,7 @@ async def get_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Get Fine Tuning Job @@ -578,6 +594,7 @@ async def get_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -591,7 +608,7 @@ async def get_async( job_id=job_id, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/fine_tuning/jobs/{job_id}", base_url=base_url, @@ -602,6 +619,7 @@ async def get_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -651,6 +669,7 @@ def cancel( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Cancel Fine Tuning Job @@ -660,6 +679,7 @@ def cancel( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -673,7 +693,7 @@ def cancel( job_id=job_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fine_tuning/jobs/{job_id}/cancel", base_url=base_url, @@ -684,6 +704,7 @@ def cancel( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -733,6 +754,7 @@ async def cancel_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Cancel Fine Tuning Job @@ -742,6 +764,7 @@ async def cancel_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -755,7 +778,7 @@ async def cancel_async( job_id=job_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fine_tuning/jobs/{job_id}/cancel", base_url=base_url, @@ -766,6 +789,7 @@ async def cancel_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -815,6 +839,7 @@ def start( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Start Fine Tuning Job @@ -824,6 +849,7 @@ def start( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -837,7 +863,7 @@ def start( job_id=job_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fine_tuning/jobs/{job_id}/start", base_url=base_url, @@ -848,6 +874,7 @@ def start( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -897,6 +924,7 @@ async def start_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DetailedJobOut]: r"""Start Fine Tuning Job @@ -906,6 +934,7 @@ async def start_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -919,7 +948,7 @@ async def start_async( job_id=job_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fine_tuning/jobs/{job_id}/start", base_url=base_url, @@ -930,6 +959,7 @@ async def start_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) diff --git a/src/mistralai/mistral_jobs.py b/src/mistralai/mistral_jobs.py index 59ea13f..8642d9f 100644 --- a/src/mistralai/mistral_jobs.py +++ b/src/mistralai/mistral_jobs.py @@ -6,7 +6,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Mapping, Optional class MistralJobs(BaseSDK): @@ -23,6 +23,7 @@ def list( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobsOut]: r"""Get Batch Jobs @@ -38,6 +39,7 @@ def list( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -57,7 +59,7 @@ def list( status=status, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/batch/jobs", base_url=base_url, @@ -68,6 +70,7 @@ def list( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -123,6 +126,7 @@ async def list_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobsOut]: r"""Get Batch Jobs @@ -138,6 +142,7 @@ async def list_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -157,7 +162,7 @@ async def list_async( status=status, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/batch/jobs", base_url=base_url, @@ -168,6 +173,7 @@ async def list_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -221,6 +227,7 @@ def create( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Create Batch Job @@ -234,6 +241,7 @@ def create( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -251,7 +259,7 @@ def create( timeout_hours=timeout_hours, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/batch/jobs", base_url=base_url, @@ -262,6 +270,7 @@ def create( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.BatchJobIn @@ -318,6 +327,7 @@ async def create_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Create Batch Job @@ -331,6 +341,7 @@ async def create_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -348,7 +359,7 @@ async def create_async( timeout_hours=timeout_hours, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/batch/jobs", base_url=base_url, @@ -359,6 +370,7 @@ async def create_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request, False, False, "json", models.BatchJobIn @@ -411,6 +423,7 @@ def get( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Get Batch Job @@ -420,6 +433,7 @@ def get( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -433,7 +447,7 @@ def get( job_id=job_id, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/batch/jobs/{job_id}", base_url=base_url, @@ -444,6 +458,7 @@ def get( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -493,6 +508,7 @@ async def get_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Get Batch Job @@ -502,6 +518,7 @@ async def get_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -515,7 +532,7 @@ async def get_async( job_id=job_id, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/batch/jobs/{job_id}", base_url=base_url, @@ -526,6 +543,7 @@ async def get_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -575,6 +593,7 @@ def cancel( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Cancel Batch Job @@ -584,6 +603,7 @@ def cancel( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -597,7 +617,7 @@ def cancel( job_id=job_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/batch/jobs/{job_id}/cancel", base_url=base_url, @@ -608,6 +628,7 @@ def cancel( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -657,6 +678,7 @@ async def cancel_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.BatchJobOut]: r"""Cancel Batch Job @@ -666,6 +688,7 @@ async def cancel_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -679,7 +702,7 @@ async def cancel_async( job_id=job_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/batch/jobs/{job_id}/cancel", base_url=base_url, @@ -690,6 +713,7 @@ async def cancel_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) diff --git a/src/mistralai/models/chatcompletionrequest.py b/src/mistralai/models/chatcompletionrequest.py index 195ea59..4658324 100644 --- a/src/mistralai/models/chatcompletionrequest.py +++ b/src/mistralai/models/chatcompletionrequest.py @@ -97,7 +97,7 @@ class ChatCompletionRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET @@ -127,7 +127,7 @@ class ChatCompletionRequest(BaseModel): n: OptionalNullable[int] = UNSET r"""Number of completions to return for each request, input tokens are only billed once.""" - safe_prompt: Optional[bool] = False + safe_prompt: Optional[bool] = None r"""Whether to inject a safety prompt before all conversations.""" @model_serializer(mode="wrap") diff --git a/src/mistralai/models/chatcompletionstreamrequest.py b/src/mistralai/models/chatcompletionstreamrequest.py index fee6509..243f069 100644 --- a/src/mistralai/models/chatcompletionstreamrequest.py +++ b/src/mistralai/models/chatcompletionstreamrequest.py @@ -100,7 +100,7 @@ class ChatCompletionStreamRequest(BaseModel): temperature: OptionalNullable[float] = UNSET r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.""" - top_p: Optional[float] = 1 + top_p: Optional[float] = None r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.""" max_tokens: OptionalNullable[int] = UNSET @@ -129,7 +129,7 @@ class ChatCompletionStreamRequest(BaseModel): n: OptionalNullable[int] = UNSET r"""Number of completions to return for each request, input tokens are only billed once.""" - safe_prompt: Optional[bool] = False + safe_prompt: Optional[bool] = None r"""Whether to inject a safety prompt before all conversations.""" @model_serializer(mode="wrap") diff --git a/src/mistralai/models/files_api_routes_upload_fileop.py b/src/mistralai/models/files_api_routes_upload_fileop.py index 4f2bb0c..e6d8687 100644 --- a/src/mistralai/models/files_api_routes_upload_fileop.py +++ b/src/mistralai/models/files_api_routes_upload_fileop.py @@ -19,7 +19,7 @@ class FileTypedDict(TypedDict): class File(BaseModel): file_name: Annotated[ - str, pydantic.Field(alias="file"), FieldMetadata(multipart=True) + str, pydantic.Field(alias="fileName"), FieldMetadata(multipart=True) ] content: Annotated[ @@ -51,11 +51,7 @@ class FilesAPIRoutesUploadFileMultiPartBodyParamsTypedDict(TypedDict): class FilesAPIRoutesUploadFileMultiPartBodyParams(BaseModel): - file: Annotated[ - File, - pydantic.Field(alias=""), - FieldMetadata(multipart=MultipartFormMetadata(file=True)), - ] + file: Annotated[File, FieldMetadata(multipart=MultipartFormMetadata(file=True))] r"""The File object (not file name) to be uploaded. To upload a file and specify a custom file name you should format your request as such: ```bash diff --git a/src/mistralai/models_.py b/src/mistralai/models_.py index 44e95ce..e01e8c9 100644 --- a/src/mistralai/models_.py +++ b/src/mistralai/models_.py @@ -5,7 +5,7 @@ from mistralai._hooks import HookContext from mistralai.types import OptionalNullable, UNSET from mistralai.utils import get_security_from_env -from typing import Any, Optional +from typing import Any, Mapping, Optional class Models(BaseSDK): @@ -17,6 +17,7 @@ def list( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ModelList]: r"""List Models @@ -25,6 +26,7 @@ def list( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -33,7 +35,7 @@ def list( if server_url is not None: base_url = server_url - req = self.build_request( + req = self._build_request( method="GET", path="/v1/models", base_url=base_url, @@ -44,6 +46,7 @@ def list( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -96,6 +99,7 @@ async def list_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ModelList]: r"""List Models @@ -104,6 +108,7 @@ async def list_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -112,7 +117,7 @@ async def list_async( if server_url is not None: base_url = server_url - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/models", base_url=base_url, @@ -123,6 +128,7 @@ async def list_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -176,6 +182,7 @@ def retrieve( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[ models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet ]: @@ -187,6 +194,7 @@ def retrieve( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -200,7 +208,7 @@ def retrieve( model_id=model_id, ) - req = self.build_request( + req = self._build_request( method="GET", path="/v1/models/{model_id}", base_url=base_url, @@ -211,6 +219,7 @@ def retrieve( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -269,6 +278,7 @@ async def retrieve_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[ models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet ]: @@ -280,6 +290,7 @@ async def retrieve_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -293,7 +304,7 @@ async def retrieve_async( model_id=model_id, ) - req = self.build_request_async( + req = self._build_request_async( method="GET", path="/v1/models/{model_id}", base_url=base_url, @@ -304,6 +315,7 @@ async def retrieve_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -362,6 +374,7 @@ def delete( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DeleteModelOut]: r"""Delete Model @@ -371,6 +384,7 @@ def delete( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -384,7 +398,7 @@ def delete( model_id=model_id, ) - req = self.build_request( + req = self._build_request( method="DELETE", path="/v1/models/{model_id}", base_url=base_url, @@ -395,6 +409,7 @@ def delete( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -448,6 +463,7 @@ async def delete_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.DeleteModelOut]: r"""Delete Model @@ -457,6 +473,7 @@ async def delete_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -470,7 +487,7 @@ async def delete_async( model_id=model_id, ) - req = self.build_request_async( + req = self._build_request_async( method="DELETE", path="/v1/models/{model_id}", base_url=base_url, @@ -481,6 +498,7 @@ async def delete_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -536,6 +554,7 @@ def update( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FTModelOut]: r"""Update Fine Tuned Model @@ -547,6 +566,7 @@ def update( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -564,7 +584,7 @@ def update( ), ) - req = self.build_request( + req = self._build_request( method="PATCH", path="/v1/fine_tuning/models/{model_id}", base_url=base_url, @@ -575,6 +595,7 @@ def update( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.update_ft_model_in, False, False, "json", models.UpdateFTModelIn @@ -629,6 +650,7 @@ async def update_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.FTModelOut]: r"""Update Fine Tuned Model @@ -640,6 +662,7 @@ async def update_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -657,7 +680,7 @@ async def update_async( ), ) - req = self.build_request_async( + req = self._build_request_async( method="PATCH", path="/v1/fine_tuning/models/{model_id}", base_url=base_url, @@ -668,6 +691,7 @@ async def update_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.update_ft_model_in, False, False, "json", models.UpdateFTModelIn @@ -720,6 +744,7 @@ def archive( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ArchiveFTModelOut]: r"""Archive Fine Tuned Model @@ -729,6 +754,7 @@ def archive( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -742,7 +768,7 @@ def archive( model_id=model_id, ) - req = self.build_request( + req = self._build_request( method="POST", path="/v1/fine_tuning/models/{model_id}/archive", base_url=base_url, @@ -753,6 +779,7 @@ def archive( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -804,6 +831,7 @@ async def archive_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.ArchiveFTModelOut]: r"""Archive Fine Tuned Model @@ -813,6 +841,7 @@ async def archive_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -826,7 +855,7 @@ async def archive_async( model_id=model_id, ) - req = self.build_request_async( + req = self._build_request_async( method="POST", path="/v1/fine_tuning/models/{model_id}/archive", base_url=base_url, @@ -837,6 +866,7 @@ async def archive_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -888,6 +918,7 @@ def unarchive( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.UnarchiveFTModelOut]: r"""Unarchive Fine Tuned Model @@ -897,6 +928,7 @@ def unarchive( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -910,7 +942,7 @@ def unarchive( model_id=model_id, ) - req = self.build_request( + req = self._build_request( method="DELETE", path="/v1/fine_tuning/models/{model_id}/archive", base_url=base_url, @@ -921,6 +953,7 @@ def unarchive( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) @@ -972,6 +1005,7 @@ async def unarchive_async( retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, + http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[models.UnarchiveFTModelOut]: r"""Unarchive Fine Tuned Model @@ -981,6 +1015,7 @@ async def unarchive_async( :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds + :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None @@ -994,7 +1029,7 @@ async def unarchive_async( model_id=model_id, ) - req = self.build_request_async( + req = self._build_request_async( method="DELETE", path="/v1/fine_tuning/models/{model_id}/archive", base_url=base_url, @@ -1005,6 +1040,7 @@ async def unarchive_async( request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", + http_headers=http_headers, security=self.sdk_configuration.security, timeout_ms=timeout_ms, ) diff --git a/src/mistralai/sdkconfiguration.py b/src/mistralai/sdkconfiguration.py index bb046ba..e7c0718 100644 --- a/src/mistralai/sdkconfiguration.py +++ b/src/mistralai/sdkconfiguration.py @@ -28,9 +28,9 @@ class SDKConfiguration: server: Optional[str] = "" language: str = "python" openapi_doc_version: str = "0.0.2" - sdk_version: str = "1.2.5" - gen_version: str = "2.470.1" - user_agent: str = "speakeasy-sdk/python 1.2.5 2.470.1 0.0.2 mistralai" + sdk_version: str = "1.2.6" + gen_version: str = "2.486.1" + user_agent: str = "speakeasy-sdk/python 1.2.6 2.486.1 0.0.2 mistralai" retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET) timeout_ms: Optional[int] = None diff --git a/src/mistralai/utils/forms.py b/src/mistralai/utils/forms.py index 9f5a731..0472aba 100644 --- a/src/mistralai/utils/forms.py +++ b/src/mistralai/utils/forms.py @@ -109,13 +109,12 @@ def serialize_multipart_form( if not field_metadata: continue - f_name = field.alias if field.alias is not None else name + f_name = field.alias if field.alias else name if field_metadata.file: file_fields: Dict[str, FieldInfo] = val.__class__.model_fields file_name = "" - field_name = "" content = None content_type = None @@ -131,20 +130,15 @@ def serialize_multipart_form( elif file_field_name == "content_type": content_type = getattr(val, file_field_name, None) else: - field_name = ( - file_field.alias - if file_field.alias is not None - else file_field_name - ) file_name = getattr(val, file_field_name) - if field_name == "" or file_name == "" or content is None: + if file_name == "" or content is None: raise ValueError("invalid multipart/form-data file") if content_type is not None: - files[field_name] = (file_name, content, content_type) + files[f_name] = (file_name, content, content_type) else: - files[field_name] = (file_name, content) + files[f_name] = (file_name, content) elif field_metadata.json: files[f_name] = ( None, diff --git a/src/mistralai/utils/requestbodies.py b/src/mistralai/utils/requestbodies.py index 4f586ae..d5240dd 100644 --- a/src/mistralai/utils/requestbodies.py +++ b/src/mistralai/utils/requestbodies.py @@ -23,7 +23,7 @@ @dataclass class SerializedRequestBody: - media_type: str + media_type: Optional[str] = None content: Optional[Any] = None data: Optional[Any] = None files: Optional[Any] = None