Skip to content

Commit

Permalink
fix(provider/amazon-bedrock): Shape the reasoning details types corre…
Browse files Browse the repository at this point in the history
…ctly on doGenerate
  • Loading branch information
Und3rf10w committed Feb 28, 2025
1 parent 22c5486 commit 6f23643
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions packages/amazon-bedrock/src/bedrock-chat-language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,34 +246,35 @@ export class BedrockChatLanguageModel implements LanguageModelV1 {
rawCall: { rawPrompt, rawSettings },
rawResponse: { headers: responseHeaders },
warnings,
reasoning: response.output?.message?.content
?.filter(
part =>
part.reasoningContent &&
(('reasoningText' in part.reasoningContent &&
part.reasoningContent.reasoningText.text != null) ||
('redactedReasoning' in part.reasoningContent &&
part.reasoningContent.redactedReasoning.data != null)),
)
?.map(part => {
const reasoningContent = part.reasoningContent!;

if ('reasoningText' in reasoningContent) {
return {
type: 'text' as const,
text: reasoningContent.reasoningText.text,
...(reasoningContent.reasoningText.signature && {
signature: reasoningContent.reasoningText.signature,
}),
};
} else {
// Must be redactedReasoning
return {
type: 'redacted' as const,
data: reasoningContent.redactedReasoning.data,
};
}
}),
reasoning:
response.output?.message?.content
?.filter(
part =>
part.reasoningContent &&
(('reasoningText' in part.reasoningContent &&
part.reasoningContent.reasoningText.text != null) ||
('redactedReasoning' in part.reasoningContent &&
part.reasoningContent.redactedReasoning.data != null)),
)
?.map(part => {
const reasoningContent = part.reasoningContent!;

if ('reasoningText' in reasoningContent) {
return {
type: 'text' as const,
text: reasoningContent.reasoningText.text,
...(reasoningContent.reasoningText.signature && {
signature: reasoningContent.reasoningText.signature,
}),
};
} else {
// Must be redactedReasoning
return {
type: 'redacted' as const,
data: reasoningContent.redactedReasoning.data,
};
}
}) || undefined,
...(providerMetadata && { providerMetadata }),
};
}
Expand Down

0 comments on commit 6f23643

Please sign in to comment.