1515 JudgeConfiguration , LDMessage , ModelConfig ,
1616 ProviderConfig )
1717from ldai .providers .ai_provider_factory import AIProviderFactory
18+ from ldai .sdk_info import AI_SDK_LANGUAGE , AI_SDK_NAME , AI_SDK_VERSION
1819from ldai .tracker import LDAIConfigTracker
1920
21+ _TRACK_SDK_INFO = '$ld:ai:sdk-info'
22+ _TRACK_USAGE_COMPLETION_CONFIG = '$ld:ai:usage:completion-config'
23+ _TRACK_USAGE_CREATE_CHAT = '$ld:ai:usage:create-chat'
24+ _TRACK_USAGE_JUDGE_CONFIG = '$ld:ai:usage:judge-config'
25+ _TRACK_USAGE_CREATE_JUDGE = '$ld:ai:usage:create-judge'
26+ _TRACK_USAGE_AGENT_CONFIG = '$ld:ai:usage:agent-config'
27+ _TRACK_USAGE_AGENT_CONFIGS = '$ld:ai:usage:agent-configs'
28+
29+ _INIT_TRACK_CONTEXT = Context .builder ('ld-internal-tracking' ).anonymous (True ).build ()
30+
2031
2132class LDAIClient :
2233 """The LaunchDarkly AI SDK client object."""
2334
2435 def __init__ (self , client : LDClient ):
2536 self ._client = client
37+ self ._client .track (
38+ _TRACK_SDK_INFO ,
39+ _INIT_TRACK_CONTEXT ,
40+ {
41+ 'aiSdkName' : AI_SDK_NAME ,
42+ 'aiSdkVersion' : AI_SDK_VERSION ,
43+ 'aiSdkLanguage' : AI_SDK_LANGUAGE ,
44+ },
45+ 1 ,
46+ )
2647
2748 def completion_config (
2849 self ,
@@ -40,7 +61,7 @@ def completion_config(
4061 :param variables: Additional variables for the completion configuration.
4162 :return: The completion configuration with a tracker used for gathering metrics.
4263 """
43- self ._client .track ('$ld:ai:config:function:single' , context , key , 1 )
64+ self ._client .track (_TRACK_USAGE_COMPLETION_CONFIG , context , key , 1 )
4465
4566 model , provider , messages , instructions , tracker , enabled , judge_configuration , _ = self .__evaluate (
4667 key , context , default_value .to_dict (), variables
@@ -94,7 +115,7 @@ def judge_config(
94115 :param variables: Additional variables for the judge configuration.
95116 :return: The judge configuration with a tracker used for gathering metrics.
96117 """
97- self ._client .track ('$ld:ai:judge:function:single' , context , key , 1 )
118+ self ._client .track (_TRACK_USAGE_JUDGE_CONFIG , context , key , 1 )
98119
99120 model , provider , messages , instructions , tracker , enabled , judge_configuration , variation = self .__evaluate (
100121 key , context , default_value .to_dict (), variables
@@ -170,7 +191,7 @@ async def create_judge(
170191 if relevance_eval:
171192 print('Relevance score:', relevance_eval.score)
172193 """
173- self ._client .track ('$ld:ai:judge:function:createJudge' , context , key , 1 )
194+ self ._client .track (_TRACK_USAGE_CREATE_JUDGE , context , key , 1 )
174195
175196 try :
176197 if variables :
@@ -281,7 +302,7 @@ async def create_chat(
281302 messages = chat.get_messages()
282303 print(f"Conversation has {len(messages)} messages")
283304 """
284- self ._client .track ('$ld:ai:config:function:createChat' , context , key , 1 )
305+ self ._client .track (_TRACK_USAGE_CREATE_CHAT , context , key , 1 )
285306 log .debug (f"Creating chat for key: { key } " )
286307 config = self .completion_config (key , context , default_value , variables )
287308
@@ -340,7 +361,7 @@ def agent_config(
340361 :return: Configured AIAgentConfig instance.
341362 """
342363 self ._client .track (
343- "$ld:ai:agent:function:single" ,
364+ _TRACK_USAGE_AGENT_CONFIG ,
344365 context ,
345366 key ,
346367 1
@@ -406,7 +427,7 @@ def agent_configs(
406427 """
407428 agent_count = len (agent_configs )
408429 self ._client .track (
409- "$ld:ai:agent:function:multiple" ,
430+ _TRACK_USAGE_AGENT_CONFIGS ,
410431 context ,
411432 agent_count ,
412433 agent_count
0 commit comments