Skip to main content

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(rename = "modelParameters", deserialize_with = "Option::deserialize")]
67    pub model_parameters: Option<serde_json::Value>,
68    /// The input data of the observation
69    #[serde(rename = "input", deserialize_with = "Option::deserialize")]
70    pub input: Option<serde_json::Value>,
71    /// The version of the observation
72    #[serde(
73        rename = "version",
74        default,
75        with = "::serde_with::rust::double_option",
76        skip_serializing_if = "Option::is_none"
77    )]
78    pub version: Option<Option<String>>,
79    /// Additional metadata of the observation
80    #[serde(rename = "metadata", deserialize_with = "Option::deserialize")]
81    pub metadata: Option<serde_json::Value>,
82    /// The output data of the observation
83    #[serde(rename = "output", deserialize_with = "Option::deserialize")]
84    pub output: Option<serde_json::Value>,
85    #[serde(rename = "usage")]
86    pub usage: Box<models::Usage>,
87    #[serde(rename = "level")]
88    pub level: models::ObservationLevel,
89    /// The status message of the observation
90    #[serde(
91        rename = "statusMessage",
92        default,
93        with = "::serde_with::rust::double_option",
94        skip_serializing_if = "Option::is_none"
95    )]
96    pub status_message: Option<Option<String>>,
97    /// The parent observation ID
98    #[serde(
99        rename = "parentObservationId",
100        default,
101        with = "::serde_with::rust::double_option",
102        skip_serializing_if = "Option::is_none"
103    )]
104    pub parent_observation_id: Option<Option<String>>,
105    /// The prompt ID associated with the observation
106    #[serde(
107        rename = "promptId",
108        default,
109        with = "::serde_with::rust::double_option",
110        skip_serializing_if = "Option::is_none"
111    )]
112    pub prompt_id: Option<Option<String>>,
113    /// 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.
114    #[serde(rename = "usageDetails")]
115    pub usage_details: std::collections::HashMap<String, i32>,
116    /// 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.
117    #[serde(rename = "costDetails")]
118    pub cost_details: std::collections::HashMap<String, f64>,
119    /// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
120    #[serde(rename = "environment")]
121    pub environment: String,
122    /// The name of the prompt associated with the observation
123    #[serde(
124        rename = "promptName",
125        default,
126        with = "::serde_with::rust::double_option",
127        skip_serializing_if = "Option::is_none"
128    )]
129    pub prompt_name: Option<Option<String>>,
130    /// The version of the prompt associated with the observation
131    #[serde(
132        rename = "promptVersion",
133        default,
134        with = "::serde_with::rust::double_option",
135        skip_serializing_if = "Option::is_none"
136    )]
137    pub prompt_version: Option<Option<i32>>,
138    /// The unique identifier of the model
139    #[serde(
140        rename = "modelId",
141        default,
142        with = "::serde_with::rust::double_option",
143        skip_serializing_if = "Option::is_none"
144    )]
145    pub model_id: Option<Option<String>>,
146    /// The price of the input in USD
147    #[serde(
148        rename = "inputPrice",
149        default,
150        with = "::serde_with::rust::double_option",
151        skip_serializing_if = "Option::is_none"
152    )]
153    pub input_price: Option<Option<f64>>,
154    /// The price of the output in USD.
155    #[serde(
156        rename = "outputPrice",
157        default,
158        with = "::serde_with::rust::double_option",
159        skip_serializing_if = "Option::is_none"
160    )]
161    pub output_price: Option<Option<f64>>,
162    /// The total price in USD.
163    #[serde(
164        rename = "totalPrice",
165        default,
166        with = "::serde_with::rust::double_option",
167        skip_serializing_if = "Option::is_none"
168    )]
169    pub total_price: Option<Option<f64>>,
170    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the input in USD
171    #[serde(
172        rename = "calculatedInputCost",
173        default,
174        with = "::serde_with::rust::double_option",
175        skip_serializing_if = "Option::is_none"
176    )]
177    pub calculated_input_cost: Option<Option<f64>>,
178    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the output in USD
179    #[serde(
180        rename = "calculatedOutputCost",
181        default,
182        with = "::serde_with::rust::double_option",
183        skip_serializing_if = "Option::is_none"
184    )]
185    pub calculated_output_cost: Option<Option<f64>>,
186    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated total cost in USD
187    #[serde(
188        rename = "calculatedTotalCost",
189        default,
190        with = "::serde_with::rust::double_option",
191        skip_serializing_if = "Option::is_none"
192    )]
193    pub calculated_total_cost: Option<Option<f64>>,
194    /// The latency in seconds.
195    #[serde(
196        rename = "latency",
197        default,
198        with = "::serde_with::rust::double_option",
199        skip_serializing_if = "Option::is_none"
200    )]
201    pub latency: Option<Option<f64>>,
202    /// The time to the first token in seconds
203    #[serde(
204        rename = "timeToFirstToken",
205        default,
206        with = "::serde_with::rust::double_option",
207        skip_serializing_if = "Option::is_none"
208    )]
209    pub time_to_first_token: Option<Option<f64>>,
210}
211
212impl ObservationsView {
213    pub fn new(
214        id: String,
215        r#type: String,
216        start_time: String,
217        model_parameters: Option<serde_json::Value>,
218        input: Option<serde_json::Value>,
219        metadata: Option<serde_json::Value>,
220        output: Option<serde_json::Value>,
221        usage: models::Usage,
222        level: models::ObservationLevel,
223        usage_details: std::collections::HashMap<String, i32>,
224        cost_details: std::collections::HashMap<String, f64>,
225        environment: String,
226    ) -> ObservationsView {
227        ObservationsView {
228            id,
229            trace_id: None,
230            r#type,
231            name: None,
232            start_time,
233            end_time: None,
234            completion_start_time: None,
235            model: None,
236            model_parameters,
237            input,
238            version: None,
239            metadata,
240            output,
241            usage: Box::new(usage),
242            level,
243            status_message: None,
244            parent_observation_id: None,
245            prompt_id: None,
246            usage_details,
247            cost_details,
248            environment,
249            prompt_name: None,
250            prompt_version: None,
251            model_id: None,
252            input_price: None,
253            output_price: None,
254            total_price: None,
255            calculated_input_cost: None,
256            calculated_output_cost: None,
257            calculated_total_cost: None,
258            latency: None,
259            time_to_first_token: None,
260        }
261    }
262}