Skip to main content

bitrouter_core/models/language/
prompt.rs

1use crate::models::{
2    language::data_content::LanguageModelDataContent,
3    shared::{
4        provider::ProviderOptions,
5        types::{JsonValue, Record},
6    },
7};
8
9/// The prompt for a language model.
10pub type LanguageModelPrompt = Vec<LanguageModelMessage>;
11
12/// A message in the prompt, which can be from the system, user, assistant, or tool
13#[derive(Debug, Clone)]
14pub enum LanguageModelMessage {
15    /// role: "system"
16    System {
17        /// System instructions content as text
18        content: String,
19        /// Provider-specific metadata
20        provider_options: Option<ProviderOptions>,
21    },
22    /// role: "user"
23    User {
24        /// The user content
25        content: Vec<LanguageModelUserContent>,
26        /// Provider-specific metadata
27        provider_options: Option<ProviderOptions>,
28    },
29    /// role: "assistant"
30    Assistant {
31        /// The assistant content
32        content: Vec<LanguageModelAssistantContent>,
33        /// Provider-specific metadata
34        provider_options: Option<ProviderOptions>,
35    },
36    /// role: "tool"
37    Tool {
38        /// The tool content
39        content: Vec<LanguageModelToolResult>,
40        /// Provider-specific metadata
41        provider_options: Option<ProviderOptions>,
42    },
43}
44
45#[derive(Debug, Clone)]
46pub enum LanguageModelUserContent {
47    /// type: "text"
48    Text {
49        /// The text content
50        text: String,
51        /// Provider-specific metadata
52        provider_options: Option<ProviderOptions>,
53    },
54    /// type: "file"
55    File {
56        /// The file name, if available
57        filename: Option<String>,
58        /// The file data, which can be bytes, a string, or a URL
59        data: LanguageModelDataContent,
60        /// The IANA media type
61        media_type: String,
62        /// Provider-specific metadata
63        provider_options: Option<ProviderOptions>,
64    },
65}
66
67#[derive(Debug, Clone)]
68pub enum LanguageModelAssistantContent {
69    /// type: "text"
70    Text {
71        /// The text content
72        text: String,
73        /// Provider-specific metadata
74        provider_options: Option<ProviderOptions>,
75    },
76    /// type: "reasoning"
77    Reasoning {
78        /// The reasoning content as text
79        text: String,
80        /// Provider-specific metadata
81        provider_options: Option<ProviderOptions>,
82    },
83    /// type: "file"
84    File {
85        /// The file name, if available
86        filename: Option<String>,
87        /// The file data, which can be bytes, a string, or a URL
88        data: LanguageModelDataContent,
89        /// The IANA media type
90        media_type: String,
91        /// Provider-specific metadata
92        provider_options: Option<ProviderOptions>,
93    },
94    /// type: "tool-call"
95    ToolCall {
96        /// The tool call ID
97        tool_call_id: String,
98        /// The tool name
99        tool_name: String,
100        /// The tool input, which can be any JSON value
101        input: JsonValue,
102        /// Whether the tool call was executed by the provider
103        provider_executed: Option<bool>,
104        /// Provider-specific metadata
105        provider_options: Option<ProviderOptions>,
106    },
107    /// type: "tool-result"
108    ToolResult {
109        /// The tool call ID that this result corresponds to
110        tool_call_id: String,
111        tool_name: String,
112        output: JsonValue,
113        /// Provider-specific metadata
114        provider_options: Option<ProviderOptions>,
115    },
116}
117
118#[derive(Debug, Clone)]
119pub enum LanguageModelToolResult {
120    /// type: "tool-result"
121    ToolResult {
122        /// The tool call ID that this result corresponds to
123        tool_call_id: String,
124        /// The tool name
125        tool_name: String,
126        /// The tool output, which can be any JSON value
127        output: LanguageModelToolResultOutput,
128        /// Provider-specific metadata
129        provider_options: Option<ProviderOptions>,
130    },
131    /// type: "tool-approval-response"
132    ToolApprovalResponse {
133        /// The approval ID that this response corresponds to
134        approval_id: String,
135        /// Whether the tool call was approved
136        approved: bool,
137        /// The reason for approval or denial, if provided
138        reason: Option<String>,
139        /// Provider-specific metadata
140        provider_options: Option<ProviderOptions>,
141    },
142}
143
144#[derive(Debug, Clone)]
145pub enum LanguageModelToolResultOutput {
146    /// type: "text"
147    Text {
148        /// The text output
149        value: String,
150        /// Provider-specific metadata
151        provider_options: Option<ProviderOptions>,
152    },
153    /// type: "json"
154    Json {
155        /// The JSON output as a JsonValue
156        value: JsonValue,
157        /// Provider-specific metadata
158        provider_options: Option<ProviderOptions>,
159    },
160    /// type: "execution-denied"
161    ExecutionDenied {
162        /// The reason for the execution denial
163        reason: String,
164        /// Provider-specific metadata
165        provider_options: Option<ProviderOptions>,
166    },
167    /// type: "error-text"
168    ErrorText {
169        /// The error message
170        value: String,
171        /// Provider-specific metadata
172        provider_options: Option<ProviderOptions>,
173    },
174    /// type: "error-json"
175    ErrorJson {
176        /// The error details as a JsonValue
177        value: JsonValue,
178        /// Provider-specific metadata
179        provider_options: Option<ProviderOptions>,
180    },
181    /// type: "content"
182    Content {
183        /// The content output, which can be text, file data, file URL, image data, image URL, or provider-specific content
184        value: Vec<LanguageModelToolResultOutputContent>,
185        /// Provider-specific metadata
186        provider_options: Option<ProviderOptions>,
187    },
188}
189
190#[derive(Debug, Clone)]
191pub enum LanguageModelToolResultOutputContent {
192    /// type: "text"
193    Text {
194        /// The text output
195        text: String,
196        /// Provider-specific metadata
197        provider_options: Option<ProviderOptions>,
198    },
199    /// type: "file-data"
200    FileData {
201        /// The file name, if available
202        filename: Option<String>,
203        /// Base64-encoded file data
204        data: String,
205        /// The IANA media type
206        media_type: String,
207        /// Provider-specific metadata
208        provider_options: Option<ProviderOptions>,
209    },
210    /// type: "file-url"
211    FileUrl {
212        /// The file URL
213        url: String,
214        /// Provider-specific metadata
215        provider_options: Option<ProviderOptions>,
216    },
217    /// type: "file-id"
218    FileId {
219        /// The file ID
220        id: LanguageModelToolResultOutputContentFileId,
221        /// Provider-specific metadata
222        provider_options: Option<ProviderOptions>,
223    },
224    /// type: "image-data"
225    ImageData {
226        /// Base64-encoded image data
227        data: String,
228        /// The IANA media type (e.g. "image/png")
229        media_type: String,
230        /// Provider-specific metadata
231        provider_options: Option<ProviderOptions>,
232    },
233    /// type: "image-url"
234    ImageUrl {
235        /// The image URL
236        url: String,
237        /// Provider-specific metadata
238        provider_options: Option<ProviderOptions>,
239    },
240    /// type: "image-file-id"
241    ImageFileId {
242        /// The image file ID
243        id: LanguageModelToolResultOutputContentFileId,
244        /// Provider-specific metadata
245        provider_options: Option<ProviderOptions>,
246    },
247    /// type: "provider-specific"
248    ProviderSpecific {
249        /// Provider-specific metadata
250        provider_options: Option<ProviderOptions>,
251    },
252}
253
254/// If using multiple providers, you need to specify the provider specific ids using
255/// the Record option. The key is the provider name, e.g. 'openai' or 'anthropic'.
256#[derive(Debug, Clone)]
257pub enum LanguageModelToolResultOutputContentFileId {
258    Record(Record<String, String>),
259    String(String),
260}