langfuse_client/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)]
15#[cfg_attr(feature="bon", derive(bon::Builder))]
16pub struct Observation {
17    /// The unique identifier of the observation
18    #[serde(rename = "id")]
19    pub id: String,
20    /// The trace ID associated with the observation
21    #[serde(rename = "traceId", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
22    pub trace_id: Option<Option<String>>,
23    /// The type of the observation
24    #[serde(rename = "type")]
25    pub r#type: String,
26    /// The name of the observation
27    #[serde(rename = "name", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
28    pub name: Option<Option<String>>,
29    /// The start time of the observation
30    #[serde(rename = "startTime")]
31    pub start_time: String,
32    /// The end time of the observation.
33    #[serde(rename = "endTime", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
34    pub end_time: Option<Option<String>>,
35    /// The completion start time of the observation
36    #[serde(rename = "completionStartTime", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
37    pub completion_start_time: Option<Option<String>>,
38    /// The model used for the observation
39    #[serde(rename = "model", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
40    pub model: Option<Option<String>>,
41    /// The parameters of the model used for the observation
42    #[serde(rename = "modelParameters", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
43    pub model_parameters: Option<Option<std::collections::HashMap<String, models::MapValue>>>,
44    /// The input data of the observation
45    #[serde(rename = "input", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
46    pub input: Option<Option<serde_json::Value>>,
47    /// The version of the observation
48    #[serde(rename = "version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
49    pub version: Option<Option<String>>,
50    /// Additional metadata of the observation
51    #[serde(rename = "metadata", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
52    pub metadata: Option<Option<serde_json::Value>>,
53    /// The output data of the observation
54    #[serde(rename = "output", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
55    pub output: Option<Option<serde_json::Value>>,
56    #[serde(rename = "usage", skip_serializing_if = "Option::is_none")]
57    pub usage: Option<models::Usage>,
58    #[serde(rename = "level")]
59    pub level: models::ObservationLevel,
60    /// The status message of the observation
61    #[serde(rename = "statusMessage", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
62    pub status_message: Option<Option<String>>,
63    /// The parent observation ID
64    #[serde(rename = "parentObservationId", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
65    pub parent_observation_id: Option<Option<String>>,
66    /// The prompt ID associated with the observation
67    #[serde(rename = "promptId", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
68    pub prompt_id: Option<Option<String>>,
69    /// 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.
70    #[serde(rename = "usageDetails", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
71    pub usage_details: Option<Option<std::collections::HashMap<String, i32>>>,
72    /// 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.
73    #[serde(rename = "costDetails", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
74    pub cost_details: Option<Option<std::collections::HashMap<String, f64>>>,
75    /// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
76    #[serde(rename = "environment", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
77    pub environment: Option<Option<String>>,
78}
79
80impl Observation {
81    pub fn new(id: String, r#type: String, start_time: String, level: models::ObservationLevel) -> Observation {
82        Observation {
83            id,
84            trace_id: None,
85            r#type,
86            name: None,
87            start_time,
88            end_time: None,
89            completion_start_time: None,
90            model: None,
91            model_parameters: None,
92            input: None,
93            version: None,
94            metadata: None,
95            output: None,
96            usage: None,
97            level,
98            status_message: None,
99            parent_observation_id: None,
100            prompt_id: None,
101            usage_details: None,
102            cost_details: None,
103            environment: None,
104        }
105    }
106}
107