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(
46        rename = "metadata",
47        default,
48        with = "::serde_with::rust::double_option",
49        skip_serializing_if = "Option::is_none"
50    )]
51    pub metadata: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
52    /// 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
53    #[serde(rename = "configId", deserialize_with = "Option::deserialize")]
54    pub config_id: Option<String>,
55    /// The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
56    #[serde(rename = "queueId", deserialize_with = "Option::deserialize")]
57    pub queue_id: Option<String>,
58    /// The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
59    #[serde(rename = "environment")]
60    pub environment: String,
61    /// The numeric value of the score
62    #[serde(rename = "value")]
63    pub value: f64,
64}
65
66impl NumericScoreV1 {
67    pub fn new(
68        id: String,
69        trace_id: String,
70        name: String,
71        source: models::ScoreSource,
72        timestamp: chrono::DateTime<chrono::FixedOffset>,
73        created_at: chrono::DateTime<chrono::FixedOffset>,
74        updated_at: chrono::DateTime<chrono::FixedOffset>,
75        author_user_id: Option<String>,
76        comment: Option<String>,
77        config_id: Option<String>,
78        queue_id: Option<String>,
79        environment: String,
80        value: f64,
81    ) -> NumericScoreV1 {
82        NumericScoreV1 {
83            id,
84            trace_id,
85            name,
86            source,
87            observation_id: None,
88            timestamp,
89            created_at,
90            updated_at,
91            author_user_id,
92            comment,
93            metadata: None,
94            config_id,
95            queue_id,
96            environment,
97            value,
98        }
99    }
100}