Skip to main content

langfuse_client_base/models/
text_score.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 TextScore {
16    #[serde(rename = "id")]
17    pub id: String,
18    /// The trace ID associated with the score
19    #[serde(
20        rename = "traceId",
21        default,
22        with = "::serde_with::rust::double_option",
23        skip_serializing_if = "Option::is_none"
24    )]
25    pub trace_id: Option<Option<String>>,
26    /// The session ID associated with the score
27    #[serde(
28        rename = "sessionId",
29        default,
30        with = "::serde_with::rust::double_option",
31        skip_serializing_if = "Option::is_none"
32    )]
33    pub session_id: Option<Option<String>>,
34    /// The observation ID associated with the score
35    #[serde(
36        rename = "observationId",
37        default,
38        with = "::serde_with::rust::double_option",
39        skip_serializing_if = "Option::is_none"
40    )]
41    pub observation_id: Option<Option<String>>,
42    /// The dataset run ID associated with the score
43    #[serde(
44        rename = "datasetRunId",
45        default,
46        with = "::serde_with::rust::double_option",
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub dataset_run_id: Option<Option<String>>,
50    #[serde(rename = "name")]
51    pub name: String,
52    #[serde(rename = "source")]
53    pub source: models::ScoreSource,
54    #[serde(rename = "timestamp")]
55    pub timestamp: chrono::DateTime<chrono::FixedOffset>,
56    #[serde(rename = "createdAt")]
57    pub created_at: chrono::DateTime<chrono::FixedOffset>,
58    #[serde(rename = "updatedAt")]
59    pub updated_at: chrono::DateTime<chrono::FixedOffset>,
60    /// The user ID of the author
61    #[serde(rename = "authorUserId", deserialize_with = "Option::deserialize")]
62    pub author_user_id: Option<String>,
63    /// Comment on the score
64    #[serde(rename = "comment", deserialize_with = "Option::deserialize")]
65    pub comment: Option<String>,
66    /// Metadata associated with the score
67    #[serde(rename = "metadata")]
68    pub metadata: std::collections::HashMap<String, serde_json::Value>,
69    /// 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
70    #[serde(rename = "configId", deserialize_with = "Option::deserialize")]
71    pub config_id: Option<String>,
72    /// The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
73    #[serde(rename = "queueId", deserialize_with = "Option::deserialize")]
74    pub queue_id: Option<String>,
75    /// The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
76    #[serde(rename = "environment")]
77    pub environment: String,
78    /// The text content of the score (1-500 characters)
79    #[serde(rename = "stringValue")]
80    pub string_value: String,
81}
82
83impl TextScore {
84    pub fn new(
85        id: String,
86        name: String,
87        source: models::ScoreSource,
88        timestamp: chrono::DateTime<chrono::FixedOffset>,
89        created_at: chrono::DateTime<chrono::FixedOffset>,
90        updated_at: chrono::DateTime<chrono::FixedOffset>,
91        author_user_id: Option<String>,
92        comment: Option<String>,
93        metadata: std::collections::HashMap<String, serde_json::Value>,
94        config_id: Option<String>,
95        queue_id: Option<String>,
96        environment: String,
97        string_value: String,
98    ) -> TextScore {
99        TextScore {
100            id,
101            trace_id: None,
102            session_id: None,
103            observation_id: None,
104            dataset_run_id: None,
105            name,
106            source,
107            timestamp,
108            created_at,
109            updated_at,
110            author_user_id,
111            comment,
112            metadata,
113            config_id,
114            queue_id,
115            environment,
116            string_value,
117        }
118    }
119}