gglib_core/ports/
tool_support.rs

1//! Tool support detection port.
2//!
3//! This port defines the interface for detecting whether models support
4//! tool/function calling capabilities based on their metadata.
5
6/// The source/provider of the model being analyzed.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ModelSource {
9    /// Local GGUF file.
10    LocalGguf,
11    /// `HuggingFace` model.
12    HuggingFace,
13}
14
15/// Input for tool support detection.
16///
17/// Contains metadata from various sources (chat templates, tags, model names)
18/// that can be analyzed to determine tool calling support.
19#[derive(Debug, Clone)]
20pub struct ToolSupportDetectionInput<'a> {
21    /// Model identifier (file path or HF model ID).
22    pub model_id: &'a str,
23    /// Chat template text (e.g., from `tokenizer.chat_template`).
24    pub chat_template: Option<&'a str>,
25    /// Model tags (e.g., from `HuggingFace`).
26    pub tags: &'a [String],
27    /// Source of the model.
28    pub source: ModelSource,
29}
30
31/// Tool calling format detected.
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub enum ToolFormat {
34    /// Hermes-style tool calling.
35    Hermes,
36    /// Llama 3.x style.
37    Llama3,
38    /// Mistral style.
39    Mistral,
40    /// `OpenAI` tools format.
41    OpenAiTools,
42    /// Generic/unknown format.
43    Generic,
44}
45
46impl ToolFormat {
47    /// Convert to string representation.
48    #[must_use]
49    pub const fn as_str(&self) -> &'static str {
50        match self {
51            Self::Hermes => "hermes",
52            Self::Llama3 => "llama3",
53            Self::Mistral => "mistral",
54            Self::OpenAiTools => "openai-tools",
55            Self::Generic => "generic",
56        }
57    }
58}
59
60impl std::fmt::Display for ToolFormat {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        f.write_str(self.as_str())
63    }
64}
65
66/// Result of tool support detection.
67#[derive(Debug, Clone)]
68pub struct ToolSupportDetection {
69    /// Whether the model likely supports tool/function calling.
70    pub supports_tool_calling: bool,
71    /// Confidence level (0.0 = unknown/no support, 1.0 = certain support).
72    pub confidence: f32,
73    /// Detected tool calling format, if identified.
74    pub detected_format: Option<ToolFormat>,
75}
76
77/// Port for detecting tool/function calling support in models.
78///
79/// Implementations analyze model metadata (chat templates, tags, names)
80/// to determine if a model supports tool calling capabilities.
81pub trait ToolSupportDetectorPort: Send + Sync {
82    /// Detect tool support based on model metadata.
83    fn detect(&self, input: ToolSupportDetectionInput<'_>) -> ToolSupportDetection;
84}