From 9f749881b31a2cd10fefb240068e6bb1bd46c709 Mon Sep 17 00:00:00 2001 From: Umesh Yadav <23421535+imumesh18@users.noreply.github.com> Date: Wed, 3 Sep 2025 04:52:57 +0530 Subject: [PATCH] language_models: Fix tool_choice null issue for other providers (#34554) Follow up: #34532 Closes #35434 Mostly fixes a issue were when the tool_choice is none it was getting serialised as null. This was fixed for openrouter just wanted to follow up and cleanup for other providers which might have this issue as this is against the spec. Release Notes: - N/A --- crates/lmstudio/src/lmstudio.rs | 3 ++- crates/mistral/src/mistral.rs | 3 ++- crates/open_ai/src/open_ai.rs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/lmstudio/src/lmstudio.rs b/crates/lmstudio/src/lmstudio.rs index 43c78115cdd4f517a51052991121620a0a93c363..ef2f7b6208f62e079609049b8eff83a80034741e 100644 --- a/crates/lmstudio/src/lmstudio.rs +++ b/crates/lmstudio/src/lmstudio.rs @@ -86,11 +86,12 @@ impl Model { } #[derive(Debug, Serialize, Deserialize)] -#[serde(untagged)] +#[serde(rename_all = "lowercase")] pub enum ToolChoice { Auto, Required, None, + #[serde(untagged)] Other(ToolDefinition), } diff --git a/crates/mistral/src/mistral.rs b/crates/mistral/src/mistral.rs index 55986e7e5bfd69ec91f11089753562e9e1984fcc..d6f62cfaa07bc211881817e6178a8673a9a670a6 100644 --- a/crates/mistral/src/mistral.rs +++ b/crates/mistral/src/mistral.rs @@ -286,12 +286,13 @@ pub enum Prediction { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "lowercase")] pub enum ToolChoice { Auto, Required, None, Any, + #[serde(untagged)] Function(ToolDefinition), } diff --git a/crates/open_ai/src/open_ai.rs b/crates/open_ai/src/open_ai.rs index f9a983b433b9d918424f9696269dd0bbd72adefd..279245c0b7d5a545a5d5c7725347f0b5153a4deb 100644 --- a/crates/open_ai/src/open_ai.rs +++ b/crates/open_ai/src/open_ai.rs @@ -269,11 +269,12 @@ pub struct Request { } #[derive(Debug, Serialize, Deserialize)] -#[serde(untagged)] +#[serde(rename_all = "lowercase")] pub enum ToolChoice { Auto, Required, None, + #[serde(untagged)] Other(ToolDefinition), }