Skip to content

Commit 6c7143b

Browse files
Remove CreateAdditionalModelRequestFields from BedrockChatClient (#4226)
* Remove CreateAdditionalModelRequestFields from BedrockChatClient Unknown parameters cause models to hard fail, and most of these settings are not supported by most of the models exposed in bedrock. A developer can use RawRepresentationFactory to populate these themselves if they really want them, so for now at least, this just gets rid of the possibly problematic settings. * chore: Add DevConfig file --------- Co-authored-by: Daniel Pinheiro <[email protected]>
1 parent d6781de commit 6c7143b

File tree

2 files changed

+11
-59
lines changed

2 files changed

+11
-59
lines changed

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/BedrockChatClient.cs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public async Task<ChatResponse> GetResponseAsync(
9090
request.System = CreateSystem(request.System, messages, options);
9191
request.ToolConfig = CreateToolConfig(request.ToolConfig, options);
9292
request.InferenceConfig = CreateInferenceConfiguration(request.InferenceConfig, options);
93-
request.AdditionalModelRequestFields = CreateAdditionalModelRequestFields(request.AdditionalModelRequestFields, options);
9493

9594
ConverseResponse response = await _runtime.ConverseAsync(request, cancellationToken).ConfigureAwait(false);
9695

@@ -257,7 +256,6 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
257256
request.System = CreateSystem(request.System, messages, options);
258257
request.ToolConfig = CreateToolConfig(request.ToolConfig, options);
259258
request.InferenceConfig = CreateInferenceConfiguration(request.InferenceConfig, options);
260-
request.AdditionalModelRequestFields = CreateAdditionalModelRequestFields(request.AdditionalModelRequestFields, options);
261259

262260
var result = await _runtime.ConverseStreamAsync(request, cancellationToken).ConfigureAwait(false);
263261

@@ -1100,61 +1098,4 @@ private static InferenceConfiguration CreateInferenceConfiguration(InferenceConf
11001098

11011099
return config;
11021100
}
1103-
1104-
/// <summary>Creates a <see cref="Document"/> from the specified options to use as the additional model request options.</summary>
1105-
private static Document CreateAdditionalModelRequestFields(Document d, ChatOptions? options)
1106-
{
1107-
if (options is not null)
1108-
{
1109-
if (options.TopK is int topK)
1110-
{
1111-
d.Add("k", topK);
1112-
}
1113-
1114-
if (options.FrequencyPenalty is float frequencyPenalty)
1115-
{
1116-
d.Add("frequency_penalty", frequencyPenalty);
1117-
}
1118-
1119-
if (options.PresencePenalty is float presencePenalty)
1120-
{
1121-
d.Add("presence_penalty", presencePenalty);
1122-
}
1123-
1124-
if (options.Seed is long seed)
1125-
{
1126-
d.Add("seed", seed);
1127-
}
1128-
1129-
if (options.AdditionalProperties is { } props)
1130-
{
1131-
foreach (KeyValuePair<string, object?> prop in props)
1132-
{
1133-
switch (prop.Value)
1134-
{
1135-
case bool propBool: d.Add(prop.Key, propBool); break;
1136-
case int propInt32: d.Add(prop.Key, propInt32); break;
1137-
case long propInt64: d.Add(prop.Key, propInt64); break;
1138-
case float propSingle: d.Add(prop.Key, propSingle); break;
1139-
case double propDouble: d.Add(prop.Key, propDouble); break;
1140-
case string propString: d.Add(prop.Key, propString); break;
1141-
case null: d.Add(prop.Key, default); break;
1142-
case JsonElement json: d.Add(prop.Key, ToDocument(json)); break;
1143-
default:
1144-
try
1145-
{
1146-
d.Add(prop.Key, ToDocument(JsonSerializer.SerializeToElement(prop.Value, BedrockJsonContext.DefaultOptions.GetTypeInfo(prop.Value.GetType()))));
1147-
}
1148-
catch (Exception e)
1149-
{
1150-
DefaultLogger.Debug(e, "Unable to serialize ChatOptions.AdditionalProperties[\"{0}\"] of type {1}", prop.Key, prop.Value?.GetType());
1151-
}
1152-
break;
1153-
}
1154-
}
1155-
}
1156-
}
1157-
1158-
return d;
1159-
}
11601101
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extensions": [
3+
{
4+
"extensionName": "Extensions.Bedrock.MEAI",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Remove `CreateAdditionalModelRequestFields` from `BedrockChatClient`"
8+
]
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)