Skip to content

Commit 4e76ca7

Browse files
committed
refactor(ai-amazon-bedrock): replace nested ternaries with if/else in makeRequest
1 parent 763ad9b commit 4e76ca7

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

packages/ai/amazon-bedrock/src/AmazonBedrockLanguageModel.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,23 +208,26 @@ export const make = Effect.fnUntraced(function*(options: {
208208
const responseFormat = providerOptions.responseFormat
209209

210210
// Anthropic rejects requests that combine extended thinking with forced tool use.
211-
// generateObject always forces toolChoice, so strip "thinking" in the json path.
212-
// Return an explicit object (even if empty) when fields are present so the spread
213-
// overrides the thinking config already placed in the request by ...config above.
214-
const requestAdditionalFields: Record<string, unknown> | undefined = responseFormat.type === "json"
215-
? (Predicate.isNotUndefined(config.additionalModelRequestFields) ||
216-
Predicate.isNotUndefined(additionalTools))
217-
? (() => {
218-
const { thinking: _thinking, ...rest } = {
219-
...config.additionalModelRequestFields,
220-
...additionalTools
221-
}
222-
return rest
223-
})()
224-
: undefined
225-
: Predicate.isNotUndefined(additionalTools)
226-
? { ...config.additionalModelRequestFields, ...additionalTools }
227-
: undefined
211+
// generateObject always forces toolChoice, so strip "thinking" from the merged
212+
// fields on the json path to prevent a 400 from the Bedrock Converse API.
213+
let requestAdditionalFields: Record<string, unknown> | undefined
214+
if (responseFormat.type === "json") {
215+
if (
216+
Predicate.isNotUndefined(config.additionalModelRequestFields) ||
217+
Predicate.isNotUndefined(additionalTools)
218+
) {
219+
const { thinking: _thinking, ...rest } = {
220+
...config.additionalModelRequestFields,
221+
...additionalTools
222+
}
223+
requestAdditionalFields = rest
224+
}
225+
} else if (Predicate.isNotUndefined(additionalTools)) {
226+
requestAdditionalFields = {
227+
...config.additionalModelRequestFields,
228+
...additionalTools
229+
}
230+
}
228231

229232
const request: typeof ConverseRequest.Encoded = {
230233
...config,

0 commit comments

Comments
 (0)