Skip to main content

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, bon::Builder)]
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(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}
123
124impl Observation {
125    pub fn new(
126        id: String,
127        r#type: String,
128        start_time: String,
129        model_parameters: Option<serde_json::Value>,
130        input: Option<serde_json::Value>,
131        metadata: Option<serde_json::Value>,
132        output: Option<serde_json::Value>,
133        usage: models::Usage,
134        level: models::ObservationLevel,
135        usage_details: std::collections::HashMap<String, i32>,
136        cost_details: std::collections::HashMap<String, f64>,
137        environment: String,
138    ) -> Observation {
139        Observation {
140            id,
141            trace_id: None,
142            r#type,
143            name: None,
144            start_time,
145            end_time: None,
146            completion_start_time: None,
147            model: None,
148            model_parameters,
149            input,
150            version: None,
151            metadata,
152            output,
153            usage: Box::new(usage),
154            level,
155            status_message: None,
156            parent_observation_id: None,
157            prompt_id: None,
158            usage_details,
159            cost_details,
160            environment,
161        }
162    }
163}