summaryrefslogtreecommitdiffstats
path: root/src/client/common.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/common.rs')
-rw-r--r--src/client/common.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/client/common.rs b/src/client/common.rs
index 3b89d11..ed95291 100644
--- a/src/client/common.rs
+++ b/src/client/common.rs
@@ -403,6 +403,26 @@ pub async fn create_openai_compatible_client_config(
Ok(Some((model, clients)))
}
+async fn eval_tool_calls_with_ctx(
+ input: &Input,
+ client: &dyn Client,
+ tool_calls: Vec<ToolCall>,
+) -> Result<Vec<ToolResult>> {
+ let path = input.query_path();
+ let subquery_ctx = crate::config::SubqueryContext::from_input(input);
+ let mut ctx = crate::function::EvalToolCallsContext {
+ subquery_ctx: Some(subquery_ctx),
+ };
+ if path.is_empty() {
+ eval_tool_calls(client.global_config(), tool_calls, &mut ctx).await
+ } else {
+ crate::utils::with_query_scope(crate::utils::format_query_path(&path), async {
+ eval_tool_calls(client.global_config(), tool_calls, &mut ctx).await
+ })
+ .await
+ }
+}
+
pub async fn call_chat_completions(
input: &Input,
print: bool,
@@ -432,7 +452,10 @@ pub async fn call_chat_completions(
client.global_config().read().print_markdown(&text)?;
}
}
- Ok((text, eval_tool_calls(client.global_config(), tool_calls)?))
+ Ok((
+ text,
+ eval_tool_calls_with_ctx(input, client, tool_calls).await?,
+ ))
}
Err(err) => Err(err),
}
@@ -463,7 +486,10 @@ pub async fn call_chat_completions_streaming(
if !text.is_empty() && !text.ends_with('\n') {
println!();
}
- Ok((text, eval_tool_calls(client.global_config(), tool_calls)?))
+ Ok((
+ text,
+ eval_tool_calls_with_ctx(input, client, tool_calls).await?,
+ ))
}
Err(err) => {
if !text.is_empty() {