Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion langfuse/_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ def create_score(
try:
new_body = ScoreBody(
id=score_id,
session_id=session_id,
sessionId=session_id,
datasetRunId=dataset_run_id,
traceId=trace_id,
observationId=observation_id,
Expand Down
3 changes: 1 addition & 2 deletions langfuse/_utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def generate_headers(self) -> dict:

def batch_post(self, **kwargs: Any) -> httpx.Response:
"""Post the `kwargs` to the batch API endpoint for events"""
logger.debug("uploading data: %s", kwargs)

res = self.post(**kwargs)

return self._process_response(
res, success_message="data uploaded successfully", return_json=False
)
Expand Down
6 changes: 3 additions & 3 deletions langfuse/langchain/CallbackHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,10 @@ def _convert_message_to_dict(self, message: BaseMessage) -> Dict[str, Any]:
and len(message.tool_calls) > 0
):
message_dict["tool_calls"] = message.tool_calls

if (
hasattr(message, "invalid_tool_calls")
and message.invalid_tool_calls is not None
hasattr(message, "invalid_tool_calls")
and message.invalid_tool_calls is not None
and len(message.invalid_tool_calls) > 0
):
message_dict["invalid_tool_calls"] = message.invalid_tool_calls
Expand Down
43 changes: 43 additions & 0 deletions tests/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,49 @@ def test_invalid_score_data_does_not_raise_exception():
# We can't assert queue size in OTEL implementation, but we can verify it completes without exception


def test_create_session_score():
langfuse = Langfuse()

session_id = "my-session"

# Create a span and set trace properties
with langfuse.start_as_current_observation(name="test-span"):
with propagate_attributes(
trace_name="this-is-so-great-new",
user_id="test",
metadata={"test": "test"},
session_id=session_id,
):
pass

# Ensure data is sent
langfuse.flush()
sleep(2)

# Create a numeric score
score_id = create_uuid()

langfuse.create_score(
score_id=score_id,
Comment thread
hassiebp marked this conversation as resolved.
session_id=session_id,
name="this-is-a-score",
value=1,
)

# Ensure data is sent
langfuse.flush()
sleep(2)

# Retrieve and verify
score = langfuse.api.scores.get_by_id(score_id)

# find the score by name (server may transform the id format)
assert score is not None
assert score.value == 1
assert score.data_type == "NUMERIC"
assert score.session_id == session_id


def test_create_numeric_score():
langfuse = Langfuse()
api_wrapper = LangfuseAPI()
Expand Down
Loading