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
|
@ -12,7 +12,6 @@ use serde_json::Value;
|
|||
use std::{
|
||||
convert::TryFrom,
|
||||
future::{self, Future},
|
||||
pin::Pin,
|
||||
};
|
||||
use strum::EnumIter;
|
||||
|
||||
|
@ -620,57 +619,6 @@ pub fn embed<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn extract_tool_args_from_events(
|
||||
tool_name: String,
|
||||
mut events: Pin<Box<dyn Send + Stream<Item = Result<ResponseStreamEvent>>>>,
|
||||
) -> Result<impl Send + Stream<Item = Result<String>>> {
|
||||
let mut tool_use_index = None;
|
||||
let mut first_chunk = None;
|
||||
while let Some(event) = events.next().await {
|
||||
let call = event?.choices.into_iter().find_map(|choice| {
|
||||
choice.delta.tool_calls?.into_iter().find_map(|call| {
|
||||
if call.function.as_ref()?.name.as_deref()? == tool_name {
|
||||
Some(call)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
if let Some(call) = call {
|
||||
tool_use_index = Some(call.index);
|
||||
first_chunk = call.function.and_then(|func| func.arguments);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let Some(tool_use_index) = tool_use_index else {
|
||||
return Err(anyhow!("tool not used"));
|
||||
};
|
||||
|
||||
Ok(events.filter_map(move |event| {
|
||||
let result = match event {
|
||||
Err(error) => Some(Err(error)),
|
||||
Ok(ResponseStreamEvent { choices, .. }) => choices.into_iter().find_map(|choice| {
|
||||
choice.delta.tool_calls?.into_iter().find_map(|call| {
|
||||
if call.index == tool_use_index {
|
||||
let func = call.function?;
|
||||
let mut arguments = func.arguments?;
|
||||
if let Some(mut first_chunk) = first_chunk.take() {
|
||||
first_chunk.push_str(&arguments);
|
||||
arguments = first_chunk
|
||||
}
|
||||
Some(Ok(arguments))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}),
|
||||
};
|
||||
|
||||
async move { result }
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn extract_text_from_events(
|
||||
response: impl Stream<Item = Result<ResponseStreamEvent>>,
|
||||
) -> impl Stream<Item = Result<String>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue