Skip to content

Commit edc70b2

Browse files
committed
fix(scores): parse session ID correctly
1 parent c5dc24d commit edc70b2

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

langfuse/_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ def create_score(
18181818
try:
18191819
new_body = ScoreBody(
18201820
id=score_id,
1821-
session_id=session_id,
1821+
sessionId=session_id,
18221822
datasetRunId=dataset_run_id,
18231823
traceId=trace_id,
18241824
observationId=observation_id,

langfuse/_utils/request.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def generate_headers(self) -> dict:
4848

4949
def batch_post(self, **kwargs: Any) -> httpx.Response:
5050
"""Post the `kwargs` to the batch API endpoint for events"""
51-
logger.debug("uploading data: %s", kwargs)
52-
5351
res = self.post(**kwargs)
52+
5453
return self._process_response(
5554
res, success_message="data uploaded successfully", return_json=False
5655
)

tests/test_core_sdk.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
121166
def test_create_numeric_score():
122167
langfuse = Langfuse()
123168
api_wrapper = LangfuseAPI()

0 commit comments

Comments
 (0)