Skip to main content

langfuse_client_base/models/
numeric_score_v1.rs

1/*
2 * server
3 *
4 * ## Real-time data  The only real-time path to get tracing data is to ingest via OpenTelemetry (`POST /api/public/otel/v1/traces`) and retrieve via Observations API v2 (`GET /api/public/v2/observations`) and Metrics API v2 (`GET /api/public/v2/metrics`). Other public API write and read endpoints can delay data by about 10 minutes. Direct OpenTelemetry exporters must send the `x-langfuse-ingestion-version: 4` header; current Python and JS SDKs already do. See the [Public API docs](https://langfuse.com/docs/api-and-data-platform/features/public-api) and [real-time ingestion](https://langfuse.com/integrations/native/opentelemetry.md#real-time-ingestion).  ## 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 - Self-hosted deployments: interactive API reference at `/api/docs` and OpenAPI spec at `/api/openapi.yaml`
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 NumericScoreV1 {
16    #[serde(rename = "id")]
17    pub id: String,
18    #[serde(rename = "traceId")]
19    pub trace_id: String,
20    #[serde(rename = "name")]
21    pub name: String,
22    #[serde(rename = "source")]
23    pub source: models::ScoreSource,
24    /// The observation ID associated with the score
25    #[serde(
26        rename = "observationId",
27        default,
28        with = "::serde_with::rust::double_option",
29        skip_serializing_if = "Option::is_none"
30    )]
31    pub observation_id: Option<Option<String>>,
32    #[serde(rename = "timestamp")]
33    pub timestamp: chrono::DateTime<chrono::FixedOffset>,
34    #[serde(rename = "createdAt")]
35    pub created_at: chrono::DateTime<chrono::FixedOffset>,
36    #[serde(rename = "updatedAt")]
37    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
38    /// The user ID of the author
39    #[serde(rename = "authorUserId", deserialize_with = "Option::deserialize")]
40    pub author_user_id: Option<String>,
41    /// Comment on the score
42    #[serde(rename = "comment", deserialize_with = "Option::deserialize")]
43    pub comment: Option<String>,
44    /// Metadata associated with the score
45    #[serde(rename = "metadata")]
46    pub metadata: std::collections::HashMap<String, serde_json::Value>,
47    /// Reference a score config on a score. When set, config and score name must be equal and value must comply to optionally defined numerical range
48    #[serde(rename = "configId", deserialize_with = "Option::deserialize")]
49    pub config_id: Option<String>,
50    /// The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
51    #[serde(rename = "queueId", deserialize_with = "Option::deserialize")]
52    pub queue_id: Option<String>,
53    /// The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
54    #[serde(rename = "environment")]
55    pub environment: String,
56    /// The numeric value of the score
57    #[serde(rename = "value")]
58    pub value: f64,
59}
60
61impl NumericScoreV1 {
62    pub fn new(
63        id: String,
64        trace_id: String,
65        name: String,
66        source: models::ScoreSource,
67        timestamp: chrono::DateTime<chrono::FixedOffset>,
68        created_at: chrono::DateTime<chrono::FixedOffset>,
69        updated_at: chrono::DateTime<chrono::FixedOffset>,
70        author_user_id: Option<String>,
71        comment: Option<String>,
72        metadata: std::collections::HashMap<String, serde_json::Value>,
73        config_id: Option<String>,
74        queue_id: Option<String>,
75        environment: String,
76        value: f64,
77    ) -> NumericScoreV1 {
78        NumericScoreV1 {
79            id,
80            trace_id,
81            name,
82            source,
83            observation_id: None,
84            timestamp,
85            created_at,
86            updated_at,
87            author_user_id,
88            comment,
89            metadata,
90            config_id,
91            queue_id,
92            environment,
93            value,
94        }
95    }
96}