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