langfuse-client-base 0.12.0

Auto-generated Langfuse API client from OpenAPI specification
Documentation
/*
 * langfuse
 *
 * ## 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
 *
 * The version of the OpenAPI document:
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct Observation {
    /// The unique identifier of the observation
    #[serde(rename = "id")]
    pub id: String,
    /// The trace ID associated with the observation
    #[serde(
        rename = "traceId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub trace_id: Option<Option<String>>,
    /// The type of the observation
    #[serde(rename = "type")]
    pub r#type: String,
    /// The name of the observation
    #[serde(
        rename = "name",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub name: Option<Option<String>>,
    /// The start time of the observation
    #[serde(rename = "startTime")]
    pub start_time: String,
    /// The end time of the observation.
    #[serde(
        rename = "endTime",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub end_time: Option<Option<String>>,
    /// The completion start time of the observation
    #[serde(
        rename = "completionStartTime",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub completion_start_time: Option<Option<String>>,
    /// The model used for the observation
    #[serde(
        rename = "model",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub model: Option<Option<String>>,
    /// The parameters of the model used for the observation
    #[serde(rename = "modelParameters", deserialize_with = "Option::deserialize")]
    pub model_parameters: Option<serde_json::Value>,
    /// The input data of the observation
    #[serde(rename = "input", deserialize_with = "Option::deserialize")]
    pub input: Option<serde_json::Value>,
    /// The version of the observation
    #[serde(
        rename = "version",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub version: Option<Option<String>>,
    /// Additional metadata of the observation
    #[serde(rename = "metadata", deserialize_with = "Option::deserialize")]
    pub metadata: Option<serde_json::Value>,
    /// The output data of the observation
    #[serde(rename = "output", deserialize_with = "Option::deserialize")]
    pub output: Option<serde_json::Value>,
    #[serde(rename = "usage")]
    pub usage: Box<models::Usage>,
    #[serde(rename = "level")]
    pub level: models::ObservationLevel,
    /// The status message of the observation
    #[serde(
        rename = "statusMessage",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub status_message: Option<Option<String>>,
    /// The parent observation ID
    #[serde(
        rename = "parentObservationId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub parent_observation_id: Option<Option<String>>,
    /// The prompt ID associated with the observation
    #[serde(
        rename = "promptId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub prompt_id: Option<Option<String>>,
    /// 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.
    #[serde(rename = "usageDetails")]
    pub usage_details: std::collections::HashMap<String, i32>,
    /// 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.
    #[serde(rename = "costDetails")]
    pub cost_details: std::collections::HashMap<String, f64>,
    /// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
    #[serde(rename = "environment")]
    pub environment: String,
}

impl Observation {
    pub fn new(
        id: String,
        r#type: String,
        start_time: String,
        model_parameters: Option<serde_json::Value>,
        input: Option<serde_json::Value>,
        metadata: Option<serde_json::Value>,
        output: Option<serde_json::Value>,
        usage: models::Usage,
        level: models::ObservationLevel,
        usage_details: std::collections::HashMap<String, i32>,
        cost_details: std::collections::HashMap<String, f64>,
        environment: String,
    ) -> Observation {
        Observation {
            id,
            trace_id: None,
            r#type,
            name: None,
            start_time,
            end_time: None,
            completion_start_time: None,
            model: None,
            model_parameters,
            input,
            version: None,
            metadata,
            output,
            usage: Box::new(usage),
            level,
            status_message: None,
            parent_observation_id: None,
            prompt_id: None,
            usage_details,
            cost_details,
            environment,
        }
    }
}