@@ -118,6 +118,51 @@ def test_invalid_score_data_does_not_raise_exception():
118118 # We can't assert queue size in OTEL implementation, but we can verify it completes without exception
119119
120120
121+ def test_create_session_score ():
122+ langfuse = Langfuse ()
123+ api_wrapper = LangfuseAPI ()
124+
125+ session_id = 'my-session'
126+
127+ # Create a span and set trace properties
128+ with langfuse .start_as_current_observation (name = "test-span" ) as span :
129+ with propagate_attributes (
130+ trace_name = "this-is-so-great-new" ,
131+ user_id = "test" ,
132+ metadata = {"test" : "test" },
133+ session_id = session_id
134+ ):
135+ # Get trace ID for later use
136+ trace_id = span .trace_id
137+
138+ # Ensure data is sent
139+ langfuse .flush ()
140+ sleep (2 )
141+
142+ # Create a numeric score
143+ score_id = create_uuid ()
144+ print ('score ID' , score_id )
145+ langfuse .create_score (
146+ score_id = score_id ,
147+ session_id = session_id ,
148+ name = "this-is-a-score" ,
149+ value = 1 ,
150+ )
151+
152+
153+ # Ensure data is sent
154+ langfuse .flush ()
155+ sleep (2 )
156+
157+ # Retrieve and verify
158+ score = langfuse .api .scores .get_by_id (score_id )
159+
160+ # find the score by name (server may transform the id format)
161+ assert score is not None
162+ assert score .value == 1
163+ assert score .data_type == "NUMERIC"
164+ assert score .session_id == session_id
165+
121166def test_create_numeric_score ():
122167 langfuse = Langfuse ()
123168 api_wrapper = LangfuseAPI ()
0 commit comments