@@ -32,6 +32,7 @@ class Traceloop:
3232 AUTO_CREATED_URL = str (Path .home () / ".cache" / "traceloop" / "auto_created_url" )
3333
3434 __tracer_wrapper : TracerWrapper
35+ __fetcher : Fetcher
3536
3637 @staticmethod
3738 def init (
@@ -57,7 +58,8 @@ def init(
5758 and not exporter
5859 and not processor
5960 ):
60- Fetcher (base_url = api_endpoint , api_key = api_key ).run ()
61+ Traceloop .__fetcher = Fetcher (base_url = api_endpoint , api_key = api_key )
62+ Traceloop .__fetcher .run ()
6163 print (
6264 Fore .GREEN + "Traceloop syncing configuration and prompts" + Fore .RESET
6365 )
@@ -158,3 +160,27 @@ def set_correlation_id(correlation_id: str) -> None:
158160
159161 def set_association_properties (properties : dict ) -> None :
160162 set_association_properties (properties )
163+
164+ def report_score (
165+ association_property_name : str ,
166+ association_property_id : str ,
167+ score : float ,
168+ ):
169+ if not Traceloop .__fetcher :
170+ print (
171+ Fore .RED
172+ + "Error: Cannot report score. Missing Traceloop API key,"
173+ + " go to https://https://app.traceloop.com/settings/api-keys to create one"
174+ )
175+ print ("Set the TRACELOOP_API_KEY environment variable to the key" )
176+ print (Fore .RESET )
177+ return
178+
179+ Traceloop .__fetcher .post (
180+ "score" ,
181+ {
182+ "entity_name" : f"traceloop.association.properties.{ association_property_name } " ,
183+ "entity_id" : association_property_id ,
184+ "score" : score ,
185+ },
186+ )
0 commit comments