Skip to main content

foundry_local_sdk/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Hardware device type for model execution.
4#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
5pub enum DeviceType {
6    Invalid,
7    #[default]
8    CPU,
9    GPU,
10    NPU,
11}
12
13/// Prompt template describing how messages are formatted for the model.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct PromptTemplate {
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub system: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub user: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub assistant: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub prompt: Option<String>,
25}
26
27/// Runtime information for a model (device type and execution provider).
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct Runtime {
31    pub device_type: DeviceType,
32    pub execution_provider: String,
33}
34
35/// A single parameter key-value pair used in model settings.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(rename_all = "camelCase")]
38pub struct Parameter {
39    pub name: String,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub value: Option<String>,
42}
43
44/// Model-level settings containing a list of parameters.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct ModelSettings {
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub parameters: Option<Vec<Parameter>>,
50}
51
52/// Full metadata for a model variant as returned by the catalog.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct ModelInfo {
56    pub id: String,
57    pub name: String,
58    pub version: u64,
59    pub alias: String,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub display_name: Option<String>,
62    pub provider_type: String,
63    pub uri: String,
64    pub model_type: String,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub prompt_template: Option<PromptTemplate>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub publisher: Option<String>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub model_settings: Option<ModelSettings>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub license: Option<String>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub license_description: Option<String>,
75    pub cached: bool,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub task: Option<String>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub runtime: Option<Runtime>,
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub file_size_mb: Option<u64>,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub supports_tool_calling: Option<bool>,
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub max_output_tokens: Option<u64>,
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub min_fl_version: Option<String>,
88    #[serde(default)]
89    pub created_at_unix: u64,
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub context_length: Option<u64>,
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub input_modalities: Option<String>,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub output_modalities: Option<String>,
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub capabilities: Option<String>,
98}
99
100/// Desired response format for chat completions.
101///
102/// Extends the standard OpenAI formats with the Foundry-specific
103/// `LarkGrammar` variant.
104#[derive(Debug, Clone)]
105pub enum ChatResponseFormat {
106    /// Plain text output (default).
107    Text,
108    /// JSON output (unstructured).
109    JsonObject,
110    /// JSON output constrained by a schema string.
111    JsonSchema(String),
112    /// Output constrained by a Lark grammar (Foundry extension).
113    LarkGrammar(String),
114}
115
116/// Tool choice configuration for chat completions.
117#[derive(Debug, Clone)]
118pub enum ChatToolChoice {
119    /// Model will not call any tool.
120    None,
121    /// Model decides whether to call a tool.
122    Auto,
123    /// Model must call at least one tool.
124    Required,
125    /// Model must call the named function.
126    Function(String),
127}
128
129/// Information about an available execution provider.
130#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(rename_all = "PascalCase")]
132pub struct EpInfo {
133    /// The name of the execution provider.
134    pub name: String,
135    /// Whether this EP is currently registered and ready for use.
136    pub is_registered: bool,
137}
138
139/// Result of a download-and-register execution-provider operation.
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[serde(rename_all = "PascalCase")]
142pub struct EpDownloadResult {
143    /// Whether all requested EPs were successfully registered.
144    pub success: bool,
145    /// Human-readable status message.
146    pub status: String,
147    /// Names of EPs that were successfully registered.
148    pub registered_eps: Vec<String>,
149    /// Names of EPs that failed to register.
150    pub failed_eps: Vec<String>,
151}