Skip to main content

codei_llm/
tool_format.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum ToolFormat {
6    /// OpenAI `tools` + `tool_choice` + `tool_calls` (supported by vLLM and OpenAI).
7    #[default]
8    Tools,
9    /// OpenAI `functions` + `function_call` (legacy; many vLLM builds ignore this).
10    Functions,
11}
12
13impl ToolFormat {
14    pub fn parse(raw: Option<&str>) -> Self {
15        match raw.map(str::trim).map(str::to_ascii_lowercase).as_deref() {
16            Some("tools") => Self::Tools,
17            Some("functions") | Some("function") | Some("function_calling") => Self::Functions,
18            _ => Self::default(),
19        }
20    }
21}