Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Cleanlab

Cleanlab’s trustworthiness score is a number from 0 to 1 for a prompt and a response. This page sends that number to cetra as a score on the trace. It is setup only: it was not run, because it needs a Cleanlab key.

Terminal window
pip install cetra-sdk cleanlab-tlm

Set your Cleanlab key in the environment for the cleanlab-tlm client. The variable name is not given on this page; use the one the cleanlab-tlm documentation names.

Score the answer inside a span, so that the score has a trace to attach to:

import cetra
from cleanlab_tlm import TLM
cetra.init()
tlm = TLM()
prompt = "What is the capital of France?"
response = "Paris."
with cetra.span("answer", input=prompt) as s:
s.set_output(response)
trustworthiness = tlm.get_trustworthiness_score(prompt, response)
cetra.score(
trace_id=cetra.current_trace_id(),
name="trustworthiness",
value=trustworthiness,
)
cetra.flush()

Set CETRA_API_KEY to your sk-cetra-… key first.

  • One score named trustworthiness on the trace, with a value from 0 to 1, shown with the other scores of the trace.
  • The span answer, with the prompt and the response as its input and output.
  • Not run: no Cleanlab key was used, so the return value is taken from the package’s reading, not observed. A batch of inputs returns a list.
  • The score is written only when the span is inside a trace. Outside one, cetra does not queue it.
  • Cleanlab calls its own service, so this page does not say that those calls appear as spans in the trace.
  • Scores: the score API and how scores are read.
  • Traces: read the trace as a tree and a timeline.