Skip to content

Commit

Permalink
.Net: [HB Planner] Content type fix (#5133)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves #5127: If the Content-Type header of a REST API JSON response
includes a charset (e.g. Content-Type: application/json; charset=utf-8),
the Handlebars prompt template handles the response as a string instead
of as deserialized JSON.

This PR changes the check from strict equality to a check that determine
if the content type simply contains `application/json`

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
teresaqhoang committed Feb 23, 2024
1 parent 5b8deb6 commit d38b45d
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private static void ProcessPositionalArguments(KernelFunctionMetadata functionMe
if (resultAsObject is RestApiOperationResponse restApiOperationResponse)
{
// Deserialize any JSON content or return the content as a string
if (string.Equals(restApiOperationResponse.ContentType, "application/json", StringComparison.OrdinalIgnoreCase))
if (restApiOperationResponse.ContentType?.IndexOf("application/json", StringComparison.OrdinalIgnoreCase) >= 0)
{
var parsedJson = JsonValue.Parse(restApiOperationResponse.Content.ToString());
return KernelHelpersUtils.DeserializeJsonNode(parsedJson);
Expand Down

0 comments on commit d38b45d

Please sign in to comment.