langfuse_client_base/models/
observation.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)]
15pub struct Observation {
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}
158
159impl Observation {
160    pub fn new(
161        id: String,
162        r#type: String,
163        start_time: String,
164        level: models::ObservationLevel,
165    ) -> Observation {
166        Observation {
167            id,
168            trace_id: None,
169            r#type,
170            name: None,
171            start_time,
172            end_time: None,
173            completion_start_time: None,
174            model: None,
175            model_parameters: None,
176            input: None,
177            version: None,
178            metadata: None,
179            output: None,
180            usage: None,
181            level,
182            status_message: None,
183            parent_observation_id: None,
184            prompt_id: None,
185            usage_details: None,
186            cost_details: None,
187            environment: None,
188        }
189    }
190}