datadog-api-client 0.32.0

Rust client for the Datadog API.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// The result of an LLM inference request, including input parameters and the model response.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct LLMObsIntegrationInferenceResponse {
    /// Anthropic-specific metadata for an inference request.
    #[serde(rename = "anthropic_metadata")]
    pub anthropic_metadata: Option<crate::datadogV2::model::LLMObsAnthropicMetadata>,
    /// Azure OpenAI-specific metadata for an integration account or inference request.
    #[serde(rename = "azure_openai_metadata")]
    pub azure_openai_metadata: Option<crate::datadogV2::model::LLMObsAzureOpenAIMetadata>,
    /// Amazon Bedrock-specific metadata for an inference request.
    #[serde(rename = "bedrock_metadata")]
    pub bedrock_metadata: Option<crate::datadogV2::model::LLMObsBedrockMetadata>,
    /// Error details returned when an inference provider returns an error.
    #[serde(rename = "error_response")]
    pub error_response: Option<crate::datadogV2::model::LLMObsInferenceErrorResponse>,
    /// Frequency penalty that was applied.
    #[serde(
        rename = "frequency_penalty",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub frequency_penalty: Option<Option<f64>>,
    /// JSON schema that was applied for structured output.
    #[serde(
        rename = "json_schema",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub json_schema: Option<Option<String>>,
    /// Maximum number of completion tokens that were configured.
    #[serde(
        rename = "max_completion_tokens",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub max_completion_tokens: Option<Option<i64>>,
    /// Maximum number of tokens that were configured.
    #[serde(
        rename = "max_tokens",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub max_tokens: Option<Option<i64>>,
    /// List of messages in an inference conversation.
    #[serde(rename = "messages")]
    pub messages: Vec<crate::datadogV2::model::LLMObsInferenceMessage>,
    /// The model identifier used for inference.
    #[serde(rename = "model_id")]
    pub model_id: String,
    /// OpenAI-specific metadata for an inference request.
    #[serde(rename = "openai_metadata")]
    pub openai_metadata: Option<crate::datadogV2::model::LLMObsOpenAIMetadata>,
    /// Presence penalty that was applied.
    #[serde(
        rename = "presence_penalty",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub presence_penalty: Option<Option<f64>>,
    /// The output of a completed LLM inference call.
    #[serde(rename = "response")]
    pub response: crate::datadogV2::model::LLMObsInferenceRunResult,
    /// Sampling temperature that was used.
    #[serde(
        rename = "temperature",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub temperature: Option<Option<f64>>,
    /// List of tools available to the model.
    #[serde(rename = "tools")]
    pub tools: Option<Vec<crate::datadogV2::model::LLMObsInferenceTool>>,
    /// Top-K sampling parameter that was used.
    #[serde(rename = "top_k", default, with = "::serde_with::rust::double_option")]
    pub top_k: Option<Option<i64>>,
    /// Nucleus sampling parameter that was used.
    #[serde(rename = "top_p", default, with = "::serde_with::rust::double_option")]
    pub top_p: Option<Option<f64>>,
    /// Vertex AI-specific metadata for an integration account or inference request.
    #[serde(rename = "vertex_ai_metadata")]
    pub vertex_ai_metadata: Option<crate::datadogV2::model::LLMObsVertexAIMetadata>,
    #[serde(flatten)]
    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
    #[serde(skip)]
    #[serde(default)]
    pub(crate) _unparsed: bool,
}

impl LLMObsIntegrationInferenceResponse {
    pub fn new(
        messages: Vec<crate::datadogV2::model::LLMObsInferenceMessage>,
        model_id: String,
        response: crate::datadogV2::model::LLMObsInferenceRunResult,
    ) -> LLMObsIntegrationInferenceResponse {
        LLMObsIntegrationInferenceResponse {
            anthropic_metadata: None,
            azure_openai_metadata: None,
            bedrock_metadata: None,
            error_response: None,
            frequency_penalty: None,
            json_schema: None,
            max_completion_tokens: None,
            max_tokens: None,
            messages,
            model_id,
            openai_metadata: None,
            presence_penalty: None,
            response,
            temperature: None,
            tools: None,
            top_k: None,
            top_p: None,
            vertex_ai_metadata: None,
            additional_properties: std::collections::BTreeMap::new(),
            _unparsed: false,
        }
    }

    pub fn anthropic_metadata(
        mut self,
        value: crate::datadogV2::model::LLMObsAnthropicMetadata,
    ) -> Self {
        self.anthropic_metadata = Some(value);
        self
    }

    pub fn azure_openai_metadata(
        mut self,
        value: crate::datadogV2::model::LLMObsAzureOpenAIMetadata,
    ) -> Self {
        self.azure_openai_metadata = Some(value);
        self
    }

    pub fn bedrock_metadata(
        mut self,
        value: crate::datadogV2::model::LLMObsBedrockMetadata,
    ) -> Self {
        self.bedrock_metadata = Some(value);
        self
    }

    pub fn error_response(
        mut self,
        value: crate::datadogV2::model::LLMObsInferenceErrorResponse,
    ) -> Self {
        self.error_response = Some(value);
        self
    }

    pub fn frequency_penalty(mut self, value: Option<f64>) -> Self {
        self.frequency_penalty = Some(value);
        self
    }

    pub fn json_schema(mut self, value: Option<String>) -> Self {
        self.json_schema = Some(value);
        self
    }

    pub fn max_completion_tokens(mut self, value: Option<i64>) -> Self {
        self.max_completion_tokens = Some(value);
        self
    }

    pub fn max_tokens(mut self, value: Option<i64>) -> Self {
        self.max_tokens = Some(value);
        self
    }

    pub fn openai_metadata(mut self, value: crate::datadogV2::model::LLMObsOpenAIMetadata) -> Self {
        self.openai_metadata = Some(value);
        self
    }

    pub fn presence_penalty(mut self, value: Option<f64>) -> Self {
        self.presence_penalty = Some(value);
        self
    }

    pub fn temperature(mut self, value: Option<f64>) -> Self {
        self.temperature = Some(value);
        self
    }

    pub fn tools(mut self, value: Vec<crate::datadogV2::model::LLMObsInferenceTool>) -> Self {
        self.tools = Some(value);
        self
    }

    pub fn top_k(mut self, value: Option<i64>) -> Self {
        self.top_k = Some(value);
        self
    }

    pub fn top_p(mut self, value: Option<f64>) -> Self {
        self.top_p = Some(value);
        self
    }

    pub fn vertex_ai_metadata(
        mut self,
        value: crate::datadogV2::model::LLMObsVertexAIMetadata,
    ) -> Self {
        self.vertex_ai_metadata = Some(value);
        self
    }

    pub fn additional_properties(
        mut self,
        value: std::collections::BTreeMap<String, serde_json::Value>,
    ) -> Self {
        self.additional_properties = value;
        self
    }
}

impl<'de> Deserialize<'de> for LLMObsIntegrationInferenceResponse {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        struct LLMObsIntegrationInferenceResponseVisitor;
        impl<'a> Visitor<'a> for LLMObsIntegrationInferenceResponseVisitor {
            type Value = LLMObsIntegrationInferenceResponse;

            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
                f.write_str("a mapping")
            }

            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
            where
                M: MapAccess<'a>,
            {
                let mut anthropic_metadata: Option<
                    crate::datadogV2::model::LLMObsAnthropicMetadata,
                > = None;
                let mut azure_openai_metadata: Option<
                    crate::datadogV2::model::LLMObsAzureOpenAIMetadata,
                > = None;
                let mut bedrock_metadata: Option<crate::datadogV2::model::LLMObsBedrockMetadata> =
                    None;
                let mut error_response: Option<
                    crate::datadogV2::model::LLMObsInferenceErrorResponse,
                > = None;
                let mut frequency_penalty: Option<Option<f64>> = None;
                let mut json_schema: Option<Option<String>> = None;
                let mut max_completion_tokens: Option<Option<i64>> = None;
                let mut max_tokens: Option<Option<i64>> = None;
                let mut messages: Option<Vec<crate::datadogV2::model::LLMObsInferenceMessage>> =
                    None;
                let mut model_id: Option<String> = None;
                let mut openai_metadata: Option<crate::datadogV2::model::LLMObsOpenAIMetadata> =
                    None;
                let mut presence_penalty: Option<Option<f64>> = None;
                let mut response: Option<crate::datadogV2::model::LLMObsInferenceRunResult> = None;
                let mut temperature: Option<Option<f64>> = None;
                let mut tools: Option<Vec<crate::datadogV2::model::LLMObsInferenceTool>> = None;
                let mut top_k: Option<Option<i64>> = None;
                let mut top_p: Option<Option<f64>> = None;
                let mut vertex_ai_metadata: Option<
                    crate::datadogV2::model::LLMObsVertexAIMetadata,
                > = None;
                let mut additional_properties: std::collections::BTreeMap<
                    String,
                    serde_json::Value,
                > = std::collections::BTreeMap::new();
                let mut _unparsed = false;

                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
                    match k.as_str() {
                        "anthropic_metadata" => {
                            if v.is_null() {
                                continue;
                            }
                            anthropic_metadata =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "azure_openai_metadata" => {
                            if v.is_null() {
                                continue;
                            }
                            azure_openai_metadata =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "bedrock_metadata" => {
                            if v.is_null() {
                                continue;
                            }
                            bedrock_metadata =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "error_response" => {
                            if v.is_null() {
                                continue;
                            }
                            error_response =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "frequency_penalty" => {
                            if v.as_str() == Some("") {
                                continue;
                            }
                            frequency_penalty =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "json_schema" => {
                            json_schema =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "max_completion_tokens" => {
                            max_completion_tokens =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "max_tokens" => {
                            max_tokens = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "messages" => {
                            messages = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "model_id" => {
                            model_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "openai_metadata" => {
                            if v.is_null() {
                                continue;
                            }
                            openai_metadata =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "presence_penalty" => {
                            if v.as_str() == Some("") {
                                continue;
                            }
                            presence_penalty =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "response" => {
                            response = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "temperature" => {
                            if v.as_str() == Some("") {
                                continue;
                            }
                            temperature =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "tools" => {
                            if v.is_null() {
                                continue;
                            }
                            tools = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "top_k" => {
                            top_k = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "top_p" => {
                            if v.as_str() == Some("") {
                                continue;
                            }
                            top_p = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "vertex_ai_metadata" => {
                            if v.is_null() {
                                continue;
                            }
                            vertex_ai_metadata =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        &_ => {
                            if let Ok(value) = serde_json::from_value(v.clone()) {
                                additional_properties.insert(k, value);
                            }
                        }
                    }
                }
                let messages = messages.ok_or_else(|| M::Error::missing_field("messages"))?;
                let model_id = model_id.ok_or_else(|| M::Error::missing_field("model_id"))?;
                let response = response.ok_or_else(|| M::Error::missing_field("response"))?;

                let content = LLMObsIntegrationInferenceResponse {
                    anthropic_metadata,
                    azure_openai_metadata,
                    bedrock_metadata,
                    error_response,
                    frequency_penalty,
                    json_schema,
                    max_completion_tokens,
                    max_tokens,
                    messages,
                    model_id,
                    openai_metadata,
                    presence_penalty,
                    response,
                    temperature,
                    tools,
                    top_k,
                    top_p,
                    vertex_ai_metadata,
                    additional_properties,
                    _unparsed,
                };

                Ok(content)
            }
        }

        deserializer.deserialize_any(LLMObsIntegrationInferenceResponseVisitor)
    }
}