Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function for removing scores #658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions langfuse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,25 @@ def score(
self.client, new_id, StateType.TRACE, new_id, self.task_manager
)

def delete_score(self, *, score_id: str) -> None:
"""Delete a score via the Langfuse API by its id.

Args:
id: The id of the score to delete.

Returns:
None

Raises:
Exception: If the score with the given id could not be found within the authenticated project or if an error occurred during the request.
"""
try:
self.log.debug(f"Deleting score {id}")
self.client.score.delete(score_id=score_id)
except Exception as e:
self.log.exception(e)
raise e

def span(
self,
*,
Expand Down
38 changes: 38 additions & 0 deletions tests/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,44 @@ def test_create_score():
assert trace["scores"][0]["id"] == score_id


def test_delete_score():
langfuse = Langfuse(debug=False)
api_wrapper = LangfuseAPI()

trace = langfuse.trace(
name="this-is-so-great-new",
user_id="test",
metadata="test",
)

langfuse.flush()
assert langfuse.task_manager._queue.qsize() == 0

score_id = create_uuid()

langfuse.score(
id=score_id,
trace_id=trace.id,
name="this-is-a-score",
value=1,
)

langfuse.flush()
assert langfuse.task_manager._queue.qsize() == 0

trace = api_wrapper.get_trace(trace.id)
assert trace["scores"][0]["id"] == score_id

langfuse.delete_score(score_id)

langfuse.flush()
assert langfuse.task_manager._queue.qsize() == 0

trace = api_wrapper.get_trace(trace.id)

assert len(trace["scores"]) == 0


def test_create_trace():
langfuse = Langfuse(
debug=False,
Expand Down