Skip to content

Commit 14f4778

Browse files
authored
feat(integrations): Parallel tool calling in OpenAI is now configurable (#611)
Adds support reasoning models in agents and for chat completions.
1 parent fa5112c commit 14f4778

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

swiftide-integrations/src/openai/chat_completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<C: async_openai::config::Config + std::default::Default + Sync + Send + std
5252
.collect::<Result<Vec<_>>>()?,
5353
)
5454
.tool_choice("auto")
55-
.parallel_tool_calls(true);
55+
.parallel_tool_calls(self.default_options.parallel_tool_calls);
5656
}
5757

5858
let request = openai_request

swiftide-integrations/src/openai/mod.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct OpenAI<C: async_openai::config::Config + Default = async_openai::conf
5353

5454
/// The `Options` struct holds configuration options for the `OpenAI` client.
5555
/// It includes optional fields for specifying the embedding and prompt models.
56-
#[derive(Debug, Default, Clone, Builder)]
56+
#[derive(Debug, Clone, Builder)]
5757
#[builder(setter(into, strip_option))]
5858
pub struct Options {
5959
/// The default embedding model to use, if specified.
@@ -62,6 +62,22 @@ pub struct Options {
6262
/// The default prompt model to use, if specified.
6363
#[builder(default)]
6464
pub prompt_model: Option<String>,
65+
66+
#[builder(default = true)]
67+
/// Option to enable or disable parallel tool calls for completions.
68+
///
69+
/// At this moment, o1 and o3-mini do not support it.
70+
pub parallel_tool_calls: bool,
71+
}
72+
73+
impl Default for Options {
74+
fn default() -> Self {
75+
Self {
76+
embed_model: None,
77+
prompt_model: None,
78+
parallel_tool_calls: true,
79+
}
80+
}
6581
}
6682

6783
impl Options {
@@ -110,6 +126,23 @@ impl<C: async_openai::config::Config + Default + Sync + Send + std::fmt::Debug>
110126
self
111127
}
112128

129+
/// Enable or disable parallel tool calls for completions.
130+
///
131+
/// Note that currently reasoning models do not support parallel tool calls
132+
///
133+
/// Defaults to `true`
134+
pub fn parallel_tool_calls(&mut self, parallel_tool_calls: bool) -> &mut Self {
135+
if let Some(options) = self.default_options.as_mut() {
136+
options.parallel_tool_calls = parallel_tool_calls;
137+
} else {
138+
self.default_options = Some(Options {
139+
parallel_tool_calls,
140+
..Default::default()
141+
});
142+
}
143+
self
144+
}
145+
113146
/// Sets the default prompt model for the `OpenAI` instance.
114147
///
115148
/// # Parameters

0 commit comments

Comments
 (0)