@@ -359,242 +359,4 @@ private static void ProcessMistralModelAttributes(Activity activity, Dictionary<
359359 Console . WriteLine ( "Exception: " + ex . Message ) ;
360360 }
361361 }
362-
363- private static void ProcessClaudeModelAttributes ( Activity activity , Dictionary < string , JsonElement > jsonBody , bool isRequest )
364- {
365- try
366- {
367- if ( isRequest )
368- {
369- if ( jsonBody . TryGetValue ( "top_p" , out var topP ) )
370- {
371- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTopP , topP . GetDouble ( ) ) ;
372- }
373-
374- if ( jsonBody . TryGetValue ( "temperature" , out var temperature ) )
375- {
376- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTemperature , temperature . GetDouble ( ) ) ;
377- }
378-
379- if ( jsonBody . TryGetValue ( "max_tokens" , out var maxTokens ) )
380- {
381- activity . SetTag ( AWSSemanticConventions . AttributeGenAiMaxTokens , maxTokens . GetInt32 ( ) ) ;
382- }
383- }
384- else
385- {
386- if ( jsonBody . TryGetValue ( "usage" , out var usage ) )
387- {
388- if ( usage . TryGetProperty ( "input_tokens" , out var inputTokens ) )
389- {
390- activity . SetTag ( AWSSemanticConventions . AttributeGenAiInputTokens , inputTokens . GetInt32 ( ) ) ;
391- }
392- if ( usage . TryGetProperty ( "output_tokens" , out var outputTokens ) )
393- {
394- activity . SetTag ( AWSSemanticConventions . AttributeGenAiOutputTokens , outputTokens . GetInt32 ( ) ) ;
395- }
396- }
397- if ( jsonBody . TryGetValue ( "stop_reason" , out var finishReasons ) )
398- {
399- activity . SetTag ( AWSSemanticConventions . AttributeGenAiFinishReasons , new string [ ] { finishReasons . GetString ( ) } ) ;
400- }
401- }
402- }
403- catch ( Exception ex )
404- {
405- Console . WriteLine ( "Exception: " + ex . Message ) ;
406- }
407- }
408-
409- private static void ProcessLlamaModelAttributes ( Activity activity , Dictionary < string , JsonElement > jsonBody , bool isRequest )
410- {
411- try
412- {
413- if ( isRequest )
414- {
415- if ( jsonBody . TryGetValue ( "top_p" , out var topP ) )
416- {
417- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTopP , topP . GetDouble ( ) ) ;
418- }
419-
420- if ( jsonBody . TryGetValue ( "temperature" , out var temperature ) )
421- {
422- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTemperature , temperature . GetDouble ( ) ) ;
423- }
424-
425- if ( jsonBody . TryGetValue ( "max_gen_len" , out var maxTokens ) )
426- {
427- activity . SetTag ( AWSSemanticConventions . AttributeGenAiMaxTokens , maxTokens . GetInt32 ( ) ) ;
428- }
429- }
430- else
431- {
432- if ( jsonBody . TryGetValue ( "prompt_token_count" , out var inputTokens ) )
433- {
434- activity . SetTag ( AWSSemanticConventions . AttributeGenAiInputTokens , inputTokens . GetInt32 ( ) ) ;
435- }
436-
437- if ( jsonBody . TryGetValue ( "generation_token_count" , out var outputTokens ) )
438- {
439- activity . SetTag ( AWSSemanticConventions . AttributeGenAiOutputTokens , outputTokens . GetInt32 ( ) ) ;
440- }
441-
442- if ( jsonBody . TryGetValue ( "stop_reason" , out var finishReasons ) )
443- {
444- activity . SetTag ( AWSSemanticConventions . AttributeGenAiFinishReasons , new string [ ] { finishReasons . GetString ( ) } ) ;
445- }
446- }
447- }
448- catch ( Exception ex )
449- {
450- Console . WriteLine ( "Exception: " + ex . Message ) ;
451- }
452- }
453-
454- private static void ProcessCommandModelAttributes ( Activity activity , Dictionary < string , JsonElement > jsonBody , bool isRequest )
455- {
456- try
457- {
458- if ( isRequest )
459- {
460- if ( jsonBody . TryGetValue ( "p" , out var topP ) )
461- {
462- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTopP , topP . GetDouble ( ) ) ;
463- }
464-
465- if ( jsonBody . TryGetValue ( "temperature" , out var temperature ) )
466- {
467- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTemperature , temperature . GetDouble ( ) ) ;
468- }
469-
470- if ( jsonBody . TryGetValue ( "max_tokens" , out var maxTokens ) )
471- {
472- activity . SetTag ( AWSSemanticConventions . AttributeGenAiMaxTokens , maxTokens . GetInt32 ( ) ) ;
473- }
474-
475- // input tokens not provided in Command response body, so we estimate the value based on input length
476- if ( jsonBody . TryGetValue ( "message" , out var input ) )
477- {
478- activity . SetTag ( AWSSemanticConventions . AttributeGenAiInputTokens , Convert . ToInt32 ( Math . Ceiling ( ( double ) input . GetString ( ) . Length / 6 ) ) ) ;
479- }
480- }
481- else
482- {
483- if ( jsonBody . TryGetValue ( "finish_reason" , out var finishReasons ) )
484- {
485- activity . SetTag ( AWSSemanticConventions . AttributeGenAiFinishReasons , new string [ ] { finishReasons . GetString ( ) } ) ;
486- }
487-
488- // completion tokens not provided in Command response body, so we estimate the value based on output length
489- if ( jsonBody . TryGetValue ( "text" , out var output ) )
490- {
491- activity . SetTag ( AWSSemanticConventions . AttributeGenAiOutputTokens , Convert . ToInt32 ( Math . Ceiling ( ( double ) output . GetString ( ) . Length / 6 ) ) ) ;
492- }
493- }
494- }
495- catch ( Exception ex )
496- {
497- Console . WriteLine ( "Exception: " + ex . Message ) ;
498- }
499- }
500-
501- private static void ProcessJambaModelAttributes ( Activity activity , Dictionary < string , JsonElement > jsonBody , bool isRequest )
502- {
503- try
504- {
505- if ( isRequest )
506- {
507- if ( jsonBody . TryGetValue ( "top_p" , out var topP ) )
508- {
509- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTopP , topP . GetDouble ( ) ) ;
510- }
511-
512- if ( jsonBody . TryGetValue ( "temperature" , out var temperature ) )
513- {
514- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTemperature , temperature . GetDouble ( ) ) ;
515- }
516-
517- if ( jsonBody . TryGetValue ( "max_tokens" , out var maxTokens ) )
518- {
519- activity . SetTag ( AWSSemanticConventions . AttributeGenAiMaxTokens , maxTokens . GetInt32 ( ) ) ;
520- }
521- }
522- else
523- {
524- if ( jsonBody . TryGetValue ( "usage" , out var usage ) )
525- {
526- if ( usage . TryGetProperty ( "prompt_tokens" , out var inputTokens ) )
527- {
528- activity . SetTag ( AWSSemanticConventions . AttributeGenAiInputTokens , inputTokens . GetInt32 ( ) ) ;
529- }
530- if ( usage . TryGetProperty ( "completion_tokens" , out var outputTokens ) )
531- {
532- activity . SetTag ( AWSSemanticConventions . AttributeGenAiOutputTokens , outputTokens . GetInt32 ( ) ) ;
533- }
534- }
535- if ( jsonBody . TryGetValue ( "choices" , out var choices ) )
536- {
537- if ( choices [ 0 ] . TryGetProperty ( "finish_reason" , out var finishReasons ) )
538- {
539- activity . SetTag ( AWSSemanticConventions . AttributeGenAiFinishReasons , new string [ ] { finishReasons . GetString ( ) } ) ;
540- }
541- }
542- }
543- }
544- catch ( Exception ex )
545- {
546- Console . WriteLine ( "Exception: " + ex . Message ) ;
547- }
548- }
549-
550- private static void ProcessMistralModelAttributes ( Activity activity , Dictionary < string , JsonElement > jsonBody , bool isRequest )
551- {
552- try
553- {
554- if ( isRequest )
555- {
556- if ( jsonBody . TryGetValue ( "top_p" , out var topP ) )
557- {
558- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTopP , topP . GetDouble ( ) ) ;
559- }
560-
561- if ( jsonBody . TryGetValue ( "temperature" , out var temperature ) )
562- {
563- activity . SetTag ( AWSSemanticConventions . AttributeGenAiTemperature , temperature . GetDouble ( ) ) ;
564- }
565-
566- if ( jsonBody . TryGetValue ( "max_tokens" , out var maxTokens ) )
567- {
568- activity . SetTag ( AWSSemanticConventions . AttributeGenAiMaxTokens , maxTokens . GetInt32 ( ) ) ;
569- }
570-
571- // input tokens not provided in Mistral response body, so we estimate the value based on input length
572- if ( jsonBody . TryGetValue ( "prompt" , out var input ) )
573- {
574- activity . SetTag ( AWSSemanticConventions . AttributeGenAiInputTokens , Convert . ToInt32 ( Math . Ceiling ( ( double ) input . GetString ( ) . Length / 6 ) ) ) ;
575- }
576- }
577- else
578- {
579- if ( jsonBody . TryGetValue ( "outputs" , out var outputsArray ) )
580- {
581- var output = outputsArray [ 0 ] ;
582- if ( output . TryGetProperty ( "stop_reason" , out var finishReasons ) )
583- {
584- activity . SetTag ( AWSSemanticConventions . AttributeGenAiFinishReasons , new string [ ] { finishReasons . GetString ( ) } ) ;
585- }
586-
587- // output tokens not provided in Mistral response body, so we estimate the value based on output length
588- if ( output . TryGetProperty ( "text" , out var text ) )
589- {
590- activity . SetTag ( AWSSemanticConventions . AttributeGenAiOutputTokens , Convert . ToInt32 ( Math . Ceiling ( ( double ) text . GetString ( ) . Length / 6 ) ) ) ;
591- }
592- }
593- }
594- }
595- catch ( Exception ex )
596- {
597- Console . WriteLine ( "Exception: " + ex . Message ) ;
598- }
599- }
600362}
0 commit comments