Skip to content

Commit

Permalink
update LlmProcessor for AOT
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakerMohd committed Jan 15, 2025
1 parent e49ddaf commit 012a012
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class AWSLlmModelProcessor
"Specify StringComparison for clarity",
"CA1307",
Justification = "Adding StringComparison only works for NET Core but not the framework.")]
internal static void ProcessGenAiAttributes<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]T>(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions)
internal static void ProcessGenAiAttributes<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions)
#else
internal static void ProcessGenAiAttributes<T>(Activity activity, T message, string modelName, bool isRequest, AWSSemanticConventions awsSemanticConventions)
#endif
Expand All @@ -31,12 +31,6 @@ internal static void ProcessGenAiAttributes<T>(Activity activity, T message, str
// the response body. For the Claude, Command, and Mistral models, the input and output tokens are not provided
// in the response body, so we approximate their values by dividing the input and output lengths by 6, based on
// the Bedrock documentation here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html

if (message is null)
{
return;
}

var messageBodyProperty = typeof(T).GetProperty("Body");
if (messageBodyProperty != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using Amazon.BedrockRuntime.Model;
using Amazon.Runtime;
using Amazon.Runtime.Internal;
using Amazon.Runtime.Telemetry;
Expand Down Expand Up @@ -138,7 +139,7 @@ private void AddResponseSpecificInformation(Activity activity, IExecutionContext
var modelString = model.ToString();
if (modelString != null)
{
AWSLlmModelProcessor.ProcessGenAiAttributes(activity, responseContext.Response, modelString, false, this.awsSemanticConventions);
AWSLlmModelProcessor.ProcessGenAiAttributes(activity, (InvokeModelResponse)responseContext.Response, modelString, false, this.awsSemanticConventions);
}
}
}
Expand Down Expand Up @@ -183,7 +184,7 @@ private void AddRequestSpecificInformation(Activity activity, IRequestContext re
var modelString = model.ToString();
if (modelString != null)
{
AWSLlmModelProcessor.ProcessGenAiAttributes(activity, request, modelString, true, this.awsSemanticConventions);
AWSLlmModelProcessor.ProcessGenAiAttributes(activity, (InvokeModelRequest)request, modelString, true, this.awsSemanticConventions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ItemGroup>
<PackageReference Include="AWSSDK.Core" Version="3.7.400" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.400" />
<PackageReference Include="AWSSDK.BedrockRuntime" Version="3.7.400" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.400" />
</ItemGroup>

Expand Down

0 comments on commit 012a012

Please sign in to comment.