Skip to content

Commit

Permalink
[C#] fix: Calls to OpenAI trace logs format is malformed. (#1141)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1140 

## Details
This is how the OpenAI call trace logs are currently formatted:



![Image](https://github.com/microsoft/teams-ai/assets/115390646/69b0750f-dbfe-4367-af2f-385b012c79ff)

This is how it should be:




![Image](https://github.com/microsoft/teams-ai/assets/115390646/895d2cc2-33e9-4504-bc16-2fc610e8cf19)



## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (we use
[TypeDoc](https://typedoc.org/) to document our code)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

### Additional information

> Feel free to add other relevant information below
  • Loading branch information
singhk97 authored Jan 9, 2024
1 parent 8160253 commit 5373c2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class OpenAIModel : IPromptCompletionModel

private readonly OpenAIClient _openAIClient;
private string _deploymentName;
private static JsonSerializerOptions _serializerOptions = new()
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};

private static readonly string _userAgent = "AlphaWave";

Expand Down Expand Up @@ -190,12 +195,12 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
_logger.LogTrace($"duration {(DateTime.UtcNow - startTime).TotalMilliseconds} ms");
if (promptResponse.Status == PromptResponseStatus.Success)
{
_logger.LogTrace(JsonSerializer.Serialize(completionsResponse!.Value));
_logger.LogTrace(JsonSerializer.Serialize(completionsResponse!.Value, _serializerOptions));
}
if (promptResponse.Status == PromptResponseStatus.RateLimited)
{
_logger.LogTrace("HEADERS:");
_logger.LogTrace(JsonSerializer.Serialize(rawResponse.Headers));
_logger.LogTrace(JsonSerializer.Serialize(rawResponse.Headers, _serializerOptions));
}
}

Expand All @@ -221,7 +226,7 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
{
// TODO: Colorize
_logger.LogTrace("CHAT PROMPT:");
_logger.LogTrace(JsonSerializer.Serialize(prompt.Output));
_logger.LogTrace(JsonSerializer.Serialize(prompt.Output, _serializerOptions));
}

// Call chat completion API
Expand Down Expand Up @@ -269,12 +274,12 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
_logger.LogTrace($"duration {(DateTime.UtcNow - startTime).TotalMilliseconds} ms");
if (promptResponse.Status == PromptResponseStatus.Success)
{
_logger.LogTrace(JsonSerializer.Serialize(chatCompletionsResponse!.Value));
_logger.LogTrace(JsonSerializer.Serialize(chatCompletionsResponse!.Value, _serializerOptions));
}
if (promptResponse.Status == PromptResponseStatus.RateLimited)
{
_logger.LogTrace("HEADERS:");
_logger.LogTrace(JsonSerializer.Serialize(rawResponse.Headers));
_logger.LogTrace(JsonSerializer.Serialize(rawResponse.Headers, _serializerOptions));
}
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/.workflows/build-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dotnet nuget locals global-packages -c

# If var is empty, conditions is true
if [ -z $SAMPLE_FOLDER ]; then
for p in $(find . -name "*.csproj"); do dotnet build $p; done
for p in $(find . -name "*.csproj"); do dotnet build -c Debug $p; done
else
dotnet build $SAMPLE_FOLDER;
fi

0 comments on commit 5373c2c

Please sign in to comment.