From 8ac453c88be4324e14c6f4674295fceb29f4fe8a Mon Sep 17 00:00:00 2001 From: Armin Sander Date: Mon, 30 Jun 2025 15:59:25 +0200 Subject: [PATCH 1/2] openai: Support to update instructions, voice, and temperature --- services/openai-dialog/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/openai-dialog/src/lib.rs b/services/openai-dialog/src/lib.rs index c638360..f7f9397 100644 --- a/services/openai-dialog/src/lib.rs +++ b/services/openai-dialog/src/lib.rs @@ -114,6 +114,12 @@ pub enum ServiceInputEvent { text: String, }, SessionUpdate { + #[serde(skip_serializing_if = "Option::is_none")] + instructions: Option, + #[serde(skip_serializing_if = "Option::is_none")] + voice: Option, + #[serde(skip_serializing_if = "Option::is_none")] + temperature: Option, #[serde(skip_serializing_if = "Option::is_none")] tools: Option>, }, @@ -415,10 +421,18 @@ impl Client { info!("Received prompt"); self.push_prompt(PromptRequest(text)).await?; } - ServiceInputEvent::SessionUpdate { tools } => { + ServiceInputEvent::SessionUpdate { + instructions, + voice, + temperature, + tools, + } => { let event = ClientEvent::SessionUpdate(client_event::SessionUpdate { session: types::Session { tools, + instructions, + voice, + temperature, ..Default::default() }, ..Default::default() From 7d9f5c306ca2ae0ae5ef9e2ed21224c211a43f2d Mon Sep 17 00:00:00 2001 From: Armin Sander Date: Mon, 30 Jun 2025 16:05:02 +0200 Subject: [PATCH 2/2] openai: Support toolChoice --- services/openai-dialog/src/lib.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/services/openai-dialog/src/lib.rs b/services/openai-dialog/src/lib.rs index f7f9397..27042a9 100644 --- a/services/openai-dialog/src/lib.rs +++ b/services/openai-dialog/src/lib.rs @@ -15,7 +15,10 @@ use openai_api_rs::realtime::{ api::RealtimeClient, client_event::{self, ClientEvent}, server_event::{self, ServerEvent}, - types::{self, ItemContentType, ItemRole, ItemStatus, ItemType, RealtimeVoice, ResponseStatus}, + types::{ + self, ItemContentType, ItemRole, ItemStatus, ItemType, RealtimeVoice, ResponseStatus, + ToolChoice, + }, }; use serde::{Deserialize, Serialize}; use tokio::{net::TcpStream, select}; @@ -42,6 +45,7 @@ pub struct Params { pub temperature: Option, #[serde(default)] pub tools: Vec, + tool_choice: Option, } impl Params { @@ -54,6 +58,7 @@ impl Params { voice: None, temperature: None, tools: vec![], + tool_choice: None, } } } @@ -113,6 +118,7 @@ pub enum ServiceInputEvent { Prompt { text: String, }, + #[serde(rename_all = "camelCase")] SessionUpdate { #[serde(skip_serializing_if = "Option::is_none")] instructions: Option, @@ -122,6 +128,8 @@ pub enum ServiceInputEvent { temperature: Option, #[serde(skip_serializing_if = "Option::is_none")] tools: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + tool_choice: Option, }, } @@ -257,11 +265,6 @@ impl Client { send_update = true; }; - if !params.tools.is_empty() { - session.tools = Some(params.tools); - send_update = true; - } - if let Some(voice) = params.voice { session.voice = Some(voice); send_update = true; @@ -272,6 +275,16 @@ impl Client { send_update = true; } + if !params.tools.is_empty() { + session.tools = Some(params.tools); + send_update = true; + } + + if let Some(tool_choice) = params.tool_choice { + session.tool_choice = Some(tool_choice); + send_update = true; + } + if send_update { self.send_client_event(ClientEvent::SessionUpdate(client_event::SessionUpdate { event_id: None, @@ -426,13 +439,15 @@ impl Client { voice, temperature, tools, + tool_choice, } => { let event = ClientEvent::SessionUpdate(client_event::SessionUpdate { session: types::Session { - tools, instructions, voice, temperature, + tools, + tool_choice, ..Default::default() }, ..Default::default()