langfuse_client_base/models/
observations_view.rs

1/*
2 * langfuse
3 *
4 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
15pub struct ObservationsView {
16    /// The unique identifier of the observation
17    #[serde(rename = "id")]
18    pub id: String,
19    /// The trace ID associated with the observation
20    #[serde(
21        rename = "traceId",
22        default,
23        with = "::serde_with::rust::double_option",
24        skip_serializing_if = "Option::is_none"
25    )]
26    pub trace_id: Option<Option<String>>,
27    /// The type of the observation
28    #[serde(rename = "type")]
29    pub r#type: String,
30    /// The name of the observation
31    #[serde(
32        rename = "name",
33        default,
34        with = "::serde_with::rust::double_option",
35        skip_serializing_if = "Option::is_none"
36    )]
37    pub name: Option<Option<String>>,
38    /// The start time of the observation
39    #[serde(rename = "startTime")]
40    pub start_time: String,
41    /// The end time of the observation.
42    #[serde(
43        rename = "endTime",
44        default,
45        with = "::serde_with::rust::double_option",
46        skip_serializing_if = "Option::is_none"
47    )]
48    pub end_time: Option<Option<String>>,
49    /// The completion start time of the observation
50    #[serde(
51        rename = "completionStartTime",
52        default,
53        with = "::serde_with::rust::double_option",
54        skip_serializing_if = "Option::is_none"
55    )]
56    pub completion_start_time: Option<Option<String>>,
57    /// The model used for the observation
58    #[serde(
59        rename = "model",
60        default,
61        with = "::serde_with::rust::double_option",
62        skip_serializing_if = "Option::is_none"
63    )]
64    pub model: Option<Option<String>>,
65    /// The parameters of the model used for the observation
66    #[serde(
67        rename = "modelParameters",
68        default,
69        with = "::serde_with::rust::double_option",
70        skip_serializing_if = "Option::is_none"
71    )]
72    pub model_parameters: Option<Option<std::collections::HashMap<String, models::MapValue>>>,
73    /// The input data of the observation
74    #[serde(
75        rename = "input",
76        default,
77        with = "::serde_with::rust::double_option",
78        skip_serializing_if = "Option::is_none"
79    )]
80    pub input: Option<Option<serde_json::Value>>,
81    /// The version of the observation
82    #[serde(
83        rename = "version",
84        default,
85        with = "::serde_with::rust::double_option",
86        skip_serializing_if = "Option::is_none"
87    )]
88    pub version: Option<Option<String>>,
89    /// Additional metadata of the observation
90    #[serde(
91        rename = "metadata",
92        default,
93        with = "::serde_with::rust::double_option",
94        skip_serializing_if = "Option::is_none"
95    )]
96    pub metadata: Option<Option<serde_json::Value>>,
97    /// The output data of the observation
98    #[serde(
99        rename = "output",
100        default,
101        with = "::serde_with::rust::double_option",
102        skip_serializing_if = "Option::is_none"
103    )]
104    pub output: Option<Option<serde_json::Value>>,
105    #[serde(rename = "usage", skip_serializing_if = "Option::is_none")]
106    pub usage: Option<Box<models::Usage>>,
107    #[serde(rename = "level")]
108    pub level: models::ObservationLevel,
109    /// The status message of the observation
110    #[serde(
111        rename = "statusMessage",
112        default,
113        with = "::serde_with::rust::double_option",
114        skip_serializing_if = "Option::is_none"
115    )]
116    pub status_message: Option<Option<String>>,
117    /// The parent observation ID
118    #[serde(
119        rename = "parentObservationId",
120        default,
121        with = "::serde_with::rust::double_option",
122        skip_serializing_if = "Option::is_none"
123    )]
124    pub parent_observation_id: Option<Option<String>>,
125    /// The prompt ID associated with the observation
126    #[serde(
127        rename = "promptId",
128        default,
129        with = "::serde_with::rust::double_option",
130        skip_serializing_if = "Option::is_none"
131    )]
132    pub prompt_id: Option<Option<String>>,
133    /// The usage details of the observation. Key is the name of the usage metric, value is the number of units consumed. The total key is the sum of all (non-total) usage metrics or the total value ingested.
134    #[serde(
135        rename = "usageDetails",
136        default,
137        with = "::serde_with::rust::double_option",
138        skip_serializing_if = "Option::is_none"
139    )]
140    pub usage_details: Option<Option<std::collections::HashMap<String, i32>>>,
141    /// The cost details of the observation. Key is the name of the cost metric, value is the cost in USD. The total key is the sum of all (non-total) cost metrics or the total value ingested.
142    #[serde(
143        rename = "costDetails",
144        default,
145        with = "::serde_with::rust::double_option",
146        skip_serializing_if = "Option::is_none"
147    )]
148    pub cost_details: Option<Option<std::collections::HashMap<String, f64>>>,
149    /// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
150    #[serde(
151        rename = "environment",
152        default,
153        with = "::serde_with::rust::double_option",
154        skip_serializing_if = "Option::is_none"
155    )]
156    pub environment: Option<Option<String>>,
157    /// The name of the prompt associated with the observation
158    #[serde(
159        rename = "promptName",
160        default,
161        with = "::serde_with::rust::double_option",
162        skip_serializing_if = "Option::is_none"
163    )]
164    pub prompt_name: Option<Option<String>>,
165    /// The version of the prompt associated with the observation
166    #[serde(
167        rename = "promptVersion",
168        default,
169        with = "::serde_with::rust::double_option",
170        skip_serializing_if = "Option::is_none"
171    )]
172    pub prompt_version: Option<Option<i32>>,
173    /// The unique identifier of the model
174    #[serde(
175        rename = "modelId",
176        default,
177        with = "::serde_with::rust::double_option",
178        skip_serializing_if = "Option::is_none"
179    )]
180    pub model_id: Option<Option<String>>,
181    /// The price of the input in USD
182    #[serde(
183        rename = "inputPrice",
184        default,
185        with = "::serde_with::rust::double_option",
186        skip_serializing_if = "Option::is_none"
187    )]
188    pub input_price: Option<Option<f64>>,
189    /// The price of the output in USD.
190    #[serde(
191        rename = "outputPrice",
192        default,
193        with = "::serde_with::rust::double_option",
194        skip_serializing_if = "Option::is_none"
195    )]
196    pub output_price: Option<Option<f64>>,
197    /// The total price in USD.
198    #[serde(
199        rename = "totalPrice",
200        default,
201        with = "::serde_with::rust::double_option",
202        skip_serializing_if = "Option::is_none"
203    )]
204    pub total_price: Option<Option<f64>>,
205    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the input in USD
206    #[serde(
207        rename = "calculatedInputCost",
208        default,
209        with = "::serde_with::rust::double_option",
210        skip_serializing_if = "Option::is_none"
211    )]
212    pub calculated_input_cost: Option<Option<f64>>,
213    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the output in USD
214    #[serde(
215        rename = "calculatedOutputCost",
216        default,
217        with = "::serde_with::rust::double_option",
218        skip_serializing_if = "Option::is_none"
219    )]
220    pub calculated_output_cost: Option<Option<f64>>,
221    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated total cost in USD
222    #[serde(
223        rename = "calculatedTotalCost",
224        default,
225        with = "::serde_with::rust::double_option",
226        skip_serializing_if = "Option::is_none"
227    )]
228    pub calculated_total_cost: Option<Option<f64>>,
229    /// The latency in seconds.
230    #[serde(
231        rename = "latency",
232        default,
233        with = "::serde_with::rust::double_option",
234        skip_serializing_if = "Option::is_none"
235    )]
236    pub latency: Option<Option<f64>>,
237    /// The time to the first token in seconds
238    #[serde(
239        rename = "timeToFirstToken",
240        default,
241        with = "::serde_with::rust::double_option",
242        skip_serializing_if = "Option::is_none"
243    )]
244    pub time_to_first_token: Option<Option<f64>>,
245}
246
247impl ObservationsView {
248    pub fn new(
249        id: String,
250        r#type: String,
251        start_time: String,
252        level: models::ObservationLevel,
253    ) -> ObservationsView {
254        ObservationsView {
255            id,
256            trace_id: None,
257            r#type,
258            name: None,
259            start_time,
260            end_time: None,
261            completion_start_time: None,
262            model: None,
263            model_parameters: None,
264            input: None,
265            version: None,
266            metadata: None,
267            output: None,
268            usage: None,
269            level,
270            status_message: None,
271            parent_observation_id: None,
272            prompt_id: None,
273            usage_details: None,
274            cost_details: None,
275            environment: None,
276            prompt_name: None,
277            prompt_version: None,
278            model_id: None,
279            input_price: None,
280            output_price: None,
281            total_price: None,
282            calculated_input_cost: None,
283            calculated_output_cost: None,
284            calculated_total_cost: None,
285            latency: None,
286            time_to_first_token: None,
287        }
288    }
289}