use cancellation token in claude API as well
This commit is contained in:
@@ -358,15 +358,17 @@ impl ClaudeAssistant {
|
|||||||
tools: tools.clone(),
|
tools: tools.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = self
|
let response = tokio::select! {
|
||||||
|
result = self
|
||||||
.client
|
.client
|
||||||
.post(&self.config.claude_api_url)
|
.post(&self.config.claude_api_url)
|
||||||
.header("x-api-key", &self.api_key)
|
.header("x-api-key", &self.api_key)
|
||||||
.header("anthropic-version", ANTHROPIC_API_VERSION)
|
.header("anthropic-version", ANTHROPIC_API_VERSION)
|
||||||
.header("content-type", "application/json")
|
.header("content-type", "application/json")
|
||||||
.json(&request_body)
|
.json(&request_body)
|
||||||
.send()
|
.send() => result?,
|
||||||
.await?;
|
_ = cancel.cancelled() => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
let error: ErrorResponse = response.json().await?;
|
let error: ErrorResponse = response.json().await?;
|
||||||
@@ -394,7 +396,11 @@ impl ClaudeAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Claude tool use: {}({})", name, input);
|
info!("Claude tool use: {}({})", name, input);
|
||||||
let (result_text, is_error) = match executor.execute(name, input).await {
|
let tool_result = tokio::select! {
|
||||||
|
result = executor.execute(name, input) => result,
|
||||||
|
_ = cancel.cancelled() => return Ok(None),
|
||||||
|
};
|
||||||
|
let (result_text, is_error) = match tool_result {
|
||||||
Ok(tool_result) => {
|
Ok(tool_result) => {
|
||||||
info!("Tool result: {}", tool_result.text);
|
info!("Tool result: {}", tool_result.text);
|
||||||
attachments.extend(tool_result.attachments);
|
attachments.extend(tool_result.attachments);
|
||||||
|
|||||||
Reference in New Issue
Block a user