forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net Updating OpenAI/AzureOpenAI ModelResults to be per Choice (micro…
…soft#2214) ### Motivation and Context Prior to this change, when using the ModelResult in a multiple results scenario the choices were being repeated for each ModelResult object, not being clear which Choice was related to the Result. Resolves microsoft#1658 Closes microsoft#1658 ### Description Added two new representations for both `ChatResult` and `TextResult` that has one to one reference to the `choice` details coming from the LLM. Updated GetModelResult example with the expected behavior and an easier example to track the changes and different prompts. ### Contribution Checklist - [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
1 parent
450b253
commit 6629c82
Showing
6 changed files
with
104 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dotnet/src/Connectors/Connectors.AI.OpenAI/AzureSdk/ChatModelResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Azure.AI.OpenAI; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.AI.OpenAI.AzureSdk; | ||
|
||
/// <summary> Represents a singular result of a chat completion.</summary> | ||
public class ChatModelResult | ||
{ | ||
/// <summary> A unique identifier associated with this chat completion response. </summary> | ||
public string Id { get; } | ||
|
||
/// <summary> | ||
/// The first timestamp associated with generation activity for this completions response, | ||
/// represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970. | ||
/// </summary> | ||
public DateTimeOffset Created { get; } | ||
|
||
/// <summary> | ||
/// Content filtering results for zero or more prompts in the request. | ||
/// </summary> | ||
public IReadOnlyList<PromptFilterResult> PromptFilterResults { get; } | ||
|
||
/// <summary> | ||
/// The completion choice associated with this completion result. | ||
/// </summary> | ||
public ChatChoice Choice { get; } | ||
|
||
/// <summary> Usage information for tokens processed and generated as part of this completions operation. </summary> | ||
public CompletionsUsage Usage { get; } | ||
|
||
/// <summary> Initializes a new instance of TextModelResult. </summary> | ||
/// <param name="completionsData"> A completions response object to populate the fields relative the the response.</param> | ||
/// <param name="choiceData"> A choice object to populate the fields relative to the resulting choice.</param> | ||
internal ChatModelResult(ChatCompletions completionsData, ChatChoice choiceData) | ||
{ | ||
this.Id = completionsData.Id; | ||
this.Created = completionsData.Created; | ||
this.PromptFilterResults = completionsData.PromptFilterResults; | ||
this.Choice = choiceData; | ||
this.Usage = completionsData.Usage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dotnet/src/Connectors/Connectors.AI.OpenAI/AzureSdk/TextModelResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Azure.AI.OpenAI; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.AI.OpenAI.AzureSdk; | ||
|
||
/// <summary> Represents a singular result of a text completion.</summary> | ||
public sealed class TextModelResult | ||
{ | ||
/// <summary> A unique identifier associated with this text completion response. </summary> | ||
public string Id { get; } | ||
|
||
/// <summary> | ||
/// The first timestamp associated with generation activity for this completions response, | ||
/// represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970. | ||
/// </summary> | ||
public DateTimeOffset Created { get; } | ||
|
||
/// <summary> | ||
/// Content filtering results for zero or more prompts in the request. | ||
/// </summary> | ||
public IReadOnlyList<PromptFilterResult> PromptFilterResults { get; } | ||
|
||
/// <summary> | ||
/// The completion choice associated with this completion result. | ||
/// </summary> | ||
public Choice Choice { get; } | ||
|
||
/// <summary> Usage information for tokens processed and generated as part of this completions operation. </summary> | ||
public CompletionsUsage Usage { get; } | ||
|
||
/// <summary> Initializes a new instance of TextModelResult. </summary> | ||
/// <param name="completionsData"> A completions response object to populate the fields relative the the response.</param> | ||
/// <param name="choiceData"> A choice object to populate the fields relative to the resulting choice.</param> | ||
internal TextModelResult(Completions completionsData, Choice choiceData) | ||
{ | ||
this.Id = completionsData.Id; | ||
this.Created = completionsData.Created; | ||
this.PromptFilterResults = completionsData.PromptFilterResults; | ||
this.Choice = choiceData; | ||
this.Usage = completionsData.Usage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters