Remove unused extract_tool_args_from_events
functions (#28038)
This PR removes the unused `extract_tool_args_from_events` functions that were defined in some of the LLM provider crates. Release Notes: - N/A
This commit is contained in:
parent
e123c4bced
commit
e5b347b03a
3 changed files with 3 additions and 165 deletions
|
@ -8,9 +8,7 @@ use aws_config::Region;
|
|||
use aws_config::stalled_stream_protection::StalledStreamProtectionConfig;
|
||||
use aws_credential_types::Credentials;
|
||||
use aws_http_client::AwsHttpClient;
|
||||
use bedrock::bedrock_client::types::{
|
||||
ContentBlockDelta, ContentBlockStart, ContentBlockStartEvent, ConverseStreamOutput,
|
||||
};
|
||||
use bedrock::bedrock_client::types::{ContentBlockDelta, ContentBlockStart, ConverseStreamOutput};
|
||||
use bedrock::bedrock_client::{self, Config};
|
||||
use bedrock::{BedrockError, BedrockInnerContent, BedrockMessage, BedrockStreamingResponse, Model};
|
||||
use collections::{BTreeMap, HashMap};
|
||||
|
@ -544,70 +542,6 @@ pub fn get_bedrock_tokens(
|
|||
.boxed()
|
||||
}
|
||||
|
||||
pub async fn extract_tool_args_from_events(
|
||||
name: String,
|
||||
mut events: Pin<Box<dyn Send + Stream<Item = Result<BedrockStreamingResponse, BedrockError>>>>,
|
||||
handle: Handle,
|
||||
) -> Result<impl Send + Stream<Item = Result<String>>> {
|
||||
handle
|
||||
.spawn(async move {
|
||||
let mut tool_use_index = None;
|
||||
while let Some(event) = events.next().await {
|
||||
if let BedrockStreamingResponse::ContentBlockStart(ContentBlockStartEvent {
|
||||
content_block_index,
|
||||
start,
|
||||
..
|
||||
}) = event?
|
||||
{
|
||||
match start {
|
||||
None => {
|
||||
continue;
|
||||
}
|
||||
Some(start) => match start.as_tool_use() {
|
||||
Ok(tool_use) => {
|
||||
if name == tool_use.name {
|
||||
tool_use_index = Some(content_block_index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(anyhow!("Failed to parse tool use event: {:?}", err));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let Some(tool_use_index) = tool_use_index else {
|
||||
return Err(anyhow!("Tool is not used"));
|
||||
};
|
||||
|
||||
Ok(events.filter_map(move |event| {
|
||||
let result = match event {
|
||||
Err(_err) => None,
|
||||
Ok(output) => match output.clone() {
|
||||
BedrockStreamingResponse::ContentBlockDelta(inner) => {
|
||||
match inner.clone().delta {
|
||||
Some(ContentBlockDelta::ToolUse(tool_use)) => {
|
||||
if inner.content_block_index == tool_use_index {
|
||||
Some(Ok(tool_use.input))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
};
|
||||
|
||||
async move { result }
|
||||
}))
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
pub fn map_to_language_model_completion_events(
|
||||
events: Pin<Box<dyn Send + Stream<Item = Result<BedrockStreamingResponse, BedrockError>>>>,
|
||||
handle: Handle,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue