providers: map native tool support from capabilities

This commit is contained in:
Chummy 2026-02-17 18:50:31 +08:00
parent b5869d424e
commit e9e45acd6d

View file

@ -278,7 +278,7 @@ pub trait Provider: Send + Sync {
/// Whether provider supports native tool calls over API. /// Whether provider supports native tool calls over API.
fn supports_native_tools(&self) -> bool { fn supports_native_tools(&self) -> bool {
false self.capabilities().native_tool_calling
} }
/// Warm up the HTTP connection pool (TLS handshake, DNS, HTTP/2 setup). /// Warm up the HTTP connection pool (TLS handshake, DNS, HTTP/2 setup).
@ -358,6 +358,27 @@ pub trait Provider: Send + Sync {
mod tests { mod tests {
use super::*; use super::*;
struct CapabilityMockProvider;
#[async_trait]
impl Provider for CapabilityMockProvider {
fn capabilities(&self) -> ProviderCapabilities {
ProviderCapabilities {
native_tool_calling: true,
}
}
async fn chat_with_system(
&self,
_system_prompt: Option<&str>,
_message: &str,
_model: &str,
_temperature: f64,
) -> anyhow::Result<String> {
Ok("ok".into())
}
}
#[test] #[test]
fn chat_message_constructors() { fn chat_message_constructors() {
let sys = ChatMessage::system("Be helpful"); let sys = ChatMessage::system("Be helpful");
@ -442,4 +463,10 @@ mod tests {
assert_eq!(caps1, caps2); assert_eq!(caps1, caps2);
assert_ne!(caps1, caps3); assert_ne!(caps1, caps3);
} }
#[test]
fn supports_native_tools_reflects_capabilities_default_mapping() {
let provider = CapabilityMockProvider;
assert!(provider.supports_native_tools());
}
} }