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