bedrock: Preserve thinking blocks for Bedrock (#29602)
Fixes a regression from #29055, resolves #29290 Release Notes: - agent: Fixed a regression that rendered Claude 3.7 Thinking unusable on Bedrock.
This commit is contained in:
parent
83b8530e1f
commit
fa40353fc5
2 changed files with 25 additions and 4 deletions
|
@ -11,12 +11,14 @@ pub use aws_sdk_bedrockruntime::types::{
|
||||||
Tool as BedrockTool, ToolChoice as BedrockToolChoice, ToolConfiguration as BedrockToolConfig,
|
Tool as BedrockTool, ToolChoice as BedrockToolChoice, ToolConfiguration as BedrockToolConfig,
|
||||||
ToolInputSchema as BedrockToolInputSchema, ToolSpecification as BedrockToolSpec,
|
ToolInputSchema as BedrockToolInputSchema, ToolSpecification as BedrockToolSpec,
|
||||||
};
|
};
|
||||||
|
pub use aws_smithy_types::Blob as BedrockBlob;
|
||||||
use aws_smithy_types::{Document, Number as AwsNumber};
|
use aws_smithy_types::{Document, Number as AwsNumber};
|
||||||
pub use bedrock::operation::converse_stream::ConverseStreamInput as BedrockStreamingRequest;
|
pub use bedrock::operation::converse_stream::ConverseStreamInput as BedrockStreamingRequest;
|
||||||
pub use bedrock::types::{
|
pub use bedrock::types::{
|
||||||
ContentBlock as BedrockRequestContent, ConversationRole as BedrockRole,
|
ContentBlock as BedrockRequestContent, ConversationRole as BedrockRole,
|
||||||
ConverseOutput as BedrockResponse, ConverseStreamOutput as BedrockStreamingResponse,
|
ConverseOutput as BedrockResponse, ConverseStreamOutput as BedrockStreamingResponse,
|
||||||
ImageBlock as BedrockImageBlock, Message as BedrockMessage,
|
ImageBlock as BedrockImageBlock, Message as BedrockMessage,
|
||||||
|
ReasoningContentBlock as BedrockThinkingBlock, ReasoningTextBlock as BedrockThinkingTextBlock,
|
||||||
ResponseStream as BedrockResponseStream, ToolResultBlock as BedrockToolResultBlock,
|
ResponseStream as BedrockResponseStream, ToolResultBlock as BedrockToolResultBlock,
|
||||||
ToolResultContentBlock as BedrockToolResultContentBlock,
|
ToolResultContentBlock as BedrockToolResultContentBlock,
|
||||||
ToolResultStatus as BedrockToolResultStatus, ToolUseBlock as BedrockToolUseBlock,
|
ToolResultStatus as BedrockToolResultStatus, ToolUseBlock as BedrockToolUseBlock,
|
||||||
|
|
|
@ -15,10 +15,11 @@ use bedrock::bedrock_client::types::{
|
||||||
StopReason,
|
StopReason,
|
||||||
};
|
};
|
||||||
use bedrock::{
|
use bedrock::{
|
||||||
BedrockAutoToolChoice, BedrockError, BedrockInnerContent, BedrockMessage, BedrockModelMode,
|
BedrockAutoToolChoice, BedrockBlob, BedrockError, BedrockInnerContent, BedrockMessage,
|
||||||
BedrockStreamingResponse, BedrockTool, BedrockToolChoice, BedrockToolConfig,
|
BedrockModelMode, BedrockStreamingResponse, BedrockThinkingBlock, BedrockThinkingTextBlock,
|
||||||
BedrockToolInputSchema, BedrockToolResultBlock, BedrockToolResultContentBlock,
|
BedrockTool, BedrockToolChoice, BedrockToolConfig, BedrockToolInputSchema,
|
||||||
BedrockToolResultStatus, BedrockToolSpec, BedrockToolUseBlock, Model, value_to_aws_document,
|
BedrockToolResultBlock, BedrockToolResultContentBlock, BedrockToolResultStatus,
|
||||||
|
BedrockToolSpec, BedrockToolUseBlock, Model, value_to_aws_document,
|
||||||
};
|
};
|
||||||
use collections::{BTreeMap, HashMap};
|
use collections::{BTreeMap, HashMap};
|
||||||
use credentials_provider::CredentialsProvider;
|
use credentials_provider::CredentialsProvider;
|
||||||
|
@ -626,6 +627,24 @@ pub fn into_bedrock(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MessageContent::Thinking { text, signature } => {
|
||||||
|
let thinking = BedrockThinkingTextBlock::builder()
|
||||||
|
.text(text)
|
||||||
|
.set_signature(signature)
|
||||||
|
.build()
|
||||||
|
.context("failed to build reasoning block")
|
||||||
|
.log_err()?;
|
||||||
|
|
||||||
|
Some(BedrockInnerContent::ReasoningContent(
|
||||||
|
BedrockThinkingBlock::ReasoningText(thinking),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
MessageContent::RedactedThinking(blob) => {
|
||||||
|
let redacted =
|
||||||
|
BedrockThinkingBlock::RedactedContent(BedrockBlob::new(blob));
|
||||||
|
|
||||||
|
Some(BedrockInnerContent::ReasoningContent(redacted))
|
||||||
|
}
|
||||||
MessageContent::ToolUse(tool_use) => BedrockToolUseBlock::builder()
|
MessageContent::ToolUse(tool_use) => BedrockToolUseBlock::builder()
|
||||||
.name(tool_use.name.to_string())
|
.name(tool_use.name.to_string())
|
||||||
.tool_use_id(tool_use.id.to_string())
|
.tool_use_id(tool_use.id.to_string())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue