Skip to content

Commit 5d24c92

Browse files
authored
Map tool choice 'required' to 'auto' for Together (tensorzero#2952)
Together doesn't mention supporting 'required' in its docs, and attempting to pass it in gives a generic 'Invalid request' error. This fixes a Together tool-calling test when running without the provider-proxy cache
1 parent 3a4bd63 commit 5d24c92

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tensorzero-core/src/providers/together.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{borrow::Cow, sync::OnceLock, time::Duration};
22

33
use crate::inference::types::RequestMessage;
4+
use crate::providers::openai::OpenAIToolChoiceString;
45
use futures::StreamExt;
56
use lazy_static::lazy_static;
67
use reqwest_eventsource::{Event, EventSource};
@@ -365,10 +366,14 @@ impl<'a> TogetherRequest<'a> {
365366
.as_ref()
366367
.map(|config| &config.tool_choice);
367368

368-
let (tools, tool_choice, parallel_tool_calls) = match tool_choice {
369+
let (tools, mut tool_choice, parallel_tool_calls) = match tool_choice {
369370
Some(&ToolChoice::None) => (None, None, None),
370371
_ => prepare_openai_tools(request),
371372
};
373+
// Together AI doesn't seem to support `tool_choice="required"`, so we convert it to `tool_choice="auto"`
374+
if let Some(OpenAIToolChoice::String(OpenAIToolChoiceString::Required)) = tool_choice {
375+
tool_choice = Some(OpenAIToolChoice::String(OpenAIToolChoiceString::Auto));
376+
}
372377

373378
Ok(TogetherRequest {
374379
messages,

0 commit comments

Comments
 (0)