Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net Fix Add Missing OpenAI Connector Choice properties to Metadata #5655

Conversation

RogerBarreto
Copy link
Member

@RogerBarreto RogerBarreto commented Mar 26, 2024

Description

Resolves #5289
Resolves #5240

This pull request includes changes to both the dotnet/samples/KernelSyntaxExamples/Example43_GetModelResult.cs and dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs files. The changes mainly focus on improving the handling of metadata and simplifying the codebase.

Changes in Example43_GetModelResult.cs:

  • The method GetTokenUsageMetadataAsync() was modified to use implicit type (var) instead of explicit type (Kernel) when creating a kernel. This change simplifies the code and makes it more readable.
  • A new method GetFullModelMetadataAsync() was added. This method creates a kernel, defines a function, invokes the function through the kernel, and displays the results. This addition expands the functionality of the class.

Changes in ClientCore.cs:

  • The method ClientCore() was modified to use GetTextChoiceMetadata() instead of GetChoiceMetadata(). This change improves the handling of metadata.
  • The method GetStreamingTextContentsAsync() was also modified to use GetTextChoiceMetadata() instead of GetChoiceMetadata(). This change improves the handling of metadata.
  • The methods GetTextChoiceMetadata(), GetChatChoiceMetadata(), and GetResponseMetadata() were modified to include additional metadata fields. This change improves the amount of information available in the metadata.
  • The method AddResponseMessage() was modified to handle null values for finishReason. This change improves the robustness of the code.

Changes in AzureOpenAIChatCompletionServiceTests.cs:

  • The method GetStreamingChatMessageContentsWorksCorrectlyAsync() was modified to use an enumerator instead of a foreach loop. This change simplifies the code and makes it more readable.

Changes in chat_completion_streaming_test_response.txt:

  • The test response was modified to include additional data. This change improves the accuracy of the tests.

@RogerBarreto RogerBarreto self-assigned this Mar 26, 2024
@RogerBarreto RogerBarreto requested a review from a team as a code owner March 26, 2024 10:53
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Mar 26, 2024
@RogerBarreto RogerBarreto added this pull request to the merge queue Mar 26, 2024
@Krzysztof318
Copy link
Contributor

Krzysztof318 commented Mar 26, 2024

@RogerBarreto do you think about introduce same pattern for metadata like is in Gemini and HuggingFace? It would be nice have inteliisense support.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 26, 2024
@RogerBarreto
Copy link
Member Author

@Krzysztof318 That's a good suggestion, not in the plans on changing the current OpenAI connector as some other updates will come from Azure on that regard.

We will eventually splitting Azure from OpenAI specific connectors.

@RogerBarreto RogerBarreto added this pull request to the merge queue Mar 26, 2024
Merged via the queue into microsoft:main with commit b997dcb Mar 26, 2024
18 checks passed
@RogerBarreto RogerBarreto deleted the issues/5289-openai-finish-reason-metadata branch March 26, 2024 20:40
LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this pull request Aug 25, 2024
…icrosoft#5655)

## Description

Resolves microsoft#5289 

This pull request includes changes to both the
`dotnet/samples/KernelSyntaxExamples/Example43_GetModelResult.cs` and
`dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs` files.
The changes mainly focus on improving the handling of metadata and
simplifying the codebase.

Changes in `Example43_GetModelResult.cs`:

* The method `GetTokenUsageMetadataAsync()` was modified to use implicit
type (`var`) instead of explicit type (`Kernel`) when creating a kernel.
This change simplifies the code and makes it more readable.
* A new method `GetFullModelMetadataAsync()` was added. This method
creates a kernel, defines a function, invokes the function through the
kernel, and displays the results. This addition expands the
functionality of the class.

Changes in `ClientCore.cs`:

* The method `ClientCore()` was modified to use
`GetTextChoiceMetadata()` instead of `GetChoiceMetadata()`. This change
improves the handling of metadata.
* The method `GetStreamingTextContentsAsync()` was also modified to use
`GetTextChoiceMetadata()` instead of `GetChoiceMetadata()`. This change
improves the handling of metadata.
* The methods `GetTextChoiceMetadata()`, `GetChatChoiceMetadata()`, and
`GetResponseMetadata()` were modified to include additional metadata
fields. This change improves the amount of information available in the
metadata.
* The method `AddResponseMessage()` was modified to handle `null` values
for `finishReason`. This change improves the robustness of the code.

Changes in `AzureOpenAIChatCompletionServiceTests.cs`:

* The method `GetStreamingChatMessageContentsWorksCorrectlyAsync()` was
modified to use an enumerator instead of a foreach loop. This change
simplifies the code and makes it more readable.

Changes in `chat_completion_streaming_test_response.txt`:

* The test response was modified to include additional data. This change
improves the accuracy of the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
4 participants