Skip to content

Commit

Permalink
Truncate OpenAI tool.description to 1024 (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvinnchau authored Jan 24, 2025
1 parent 589b8de commit 761a1b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/goose/src/providers/formats/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ pub fn format_tools(tools: &[Tool]) -> anyhow::Result<Vec<Value>> {
return Err(anyhow!("Duplicate tool name: {}", tool.name));
}

// OpenAI's tool description max str len is 1024
result.push(json!({
"type": "function",
"function": {
"name": tool.name,
"description": tool.description,
"description": tool.description.clone().truncate(1024),
"parameters": tool.input_schema,
}
}));
Expand Down
5 changes: 3 additions & 2 deletions crates/goose/src/providers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ pub async fn non_ok_response_to_provider_error(
ProviderError::ServerError(format!("Server error occurred. Status: {}", response.status()))
}
_ => {
let status = response.status();
tracing::debug!(
"{}", format!("Provider request failed with status: {}. Payload: {}", response.status(), payload)
"{}", format!("Provider request failed with status: {}. Body: {:?}. Payload: {}", status, response.text().await.unwrap_or_default(), payload)
);
ProviderError::RequestFailed(format!("Request failed with status: {}.", response.status()))
ProviderError::RequestFailed(format!("Request failed with status: {}.", status))
}
}
}
Expand Down

0 comments on commit 761a1b2

Please sign in to comment.