Skip to content

Commit

Permalink
update attribute semantic conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Oct 31, 2024
1 parent cf5a0d3 commit 0cb6272
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ private static void ProcessTitanModelResponseAttributes(Activity activity, Dicti
{
if (jsonBody.TryGetValue("inputTextTokenCount", out var promptTokens))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiPromptTokens, promptTokens.GetInt32());
activity.SetTag(AWSSemanticConventions.AttributeGenAiInputTokens, promptTokens.GetInt32());
}

if (jsonBody.TryGetValue("results", out var resultsArray))
{
var results = resultsArray[0];
if (results.TryGetProperty("tokenCount", out var completionTokens))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiCompletionTokens, completionTokens.GetInt32());
activity.SetTag(AWSSemanticConventions.AttributeGenAiOutputTokens, completionTokens.GetInt32());
}

if (results.TryGetProperty("completionReason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ private static void ProcessClaudeModelResponseAttributes(Activity activity, Dict
{
if (jsonBody.TryGetValue("stop_reason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}

// prompt_tokens and completion_tokens not provided in Claude response body.
Expand Down Expand Up @@ -240,17 +240,17 @@ private static void ProcessLlamaModelResponseAttributes(Activity activity, Dicti
{
if (jsonBody.TryGetValue("prompt_token_count", out var promptTokens))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiPromptTokens, promptTokens.GetInt32());
activity.SetTag(AWSSemanticConventions.AttributeGenAiInputTokens, promptTokens.GetInt32());
}

if (jsonBody.TryGetValue("generation_token_count", out var completionTokens))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiCompletionTokens, completionTokens.GetInt32());
activity.SetTag(AWSSemanticConventions.AttributeGenAiOutputTokens, completionTokens.GetInt32());
}

if (jsonBody.TryGetValue("stop_reason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}
}
catch (Exception ex)
Expand Down Expand Up @@ -294,7 +294,7 @@ private static void ProcessCommandModelResponseAttributes(Activity activity, Dic
var generations = generationsArray[0];
if (generations.TryGetProperty("finish_reason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ private static void ProcessMistralModelResponseAttributes(Activity activity, Dic
var output = outputsArray[0];
if (output.TryGetProperty("stop_reason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}
}

Expand All @@ -361,7 +361,7 @@ private static void ProcessStabilityModelResponseAttributes(Activity activity, D
var artifacts = artifactsArray[0];
if (artifacts.TryGetProperty("finishReason", out var finishReasons))
{
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, finishReasons.GetString());
activity.SetTag(AWSSemanticConventions.AttributeGenAiFinishReasons, new string[] { finishReasons.GetString() });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ internal static class AWSSemanticConventions
public const string AttributeGenAiTopP = "gen_ai.request.top_p";
public const string AttributeGenAiTemperature = "gen_ai.request.temperature";
public const string AttributeGenAiMaxTokens = "gen_ai.request.max_tokens";
public const string AttributeGenAiPromptTokens = "gen_ai.usage.prompt_tokens";
public const string AttributeGenAiCompletionTokens = "gen_ai.usage.completion_tokens";
public const string AttributeGenAiInputTokens = "gen_ai.usage.input_tokens";
public const string AttributeGenAiOutputTokens = "gen_ai.usage.output_tokens";
public const string AttributeGenAiFinishReasons = "gen_ai.response.finish_reasons";

public const string AttributeHttpStatusCode = "http.status_code";
Expand Down

0 comments on commit 0cb6272

Please sign in to comment.