Skip to content

Commit

Permalink
.Net: Tidying up AzureOpenAIChatCompletionService (#7073)
Browse files Browse the repository at this point in the history
### Motivation, Context and Description
This PR fixes a small issue that would occur if the LLM started calling
tools that are not functions. Additionally, it renames the
`openAIClient` parameter of the `AzureOpenAIChatCompletionService` class
constructor to `azureOpenAIClient` to keep the name consistent with its
type. It also renames the
`AzureOpenAIChatMessageContent.GetOpenAIFunctionToolCalls` method to
`GetFunctionToolCalls` because the old one is not relevant anymore. The
last two changes are breaking changes and it will be decided in the
scope of the #7053
issue whether to keep them or roll them back.
  • Loading branch information
SergeyMenshykh committed Jul 3, 2024
1 parent f266504 commit edb7442
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void GetOpenAIFunctionToolCallsReturnsCorrectList()
var content2 = new AzureOpenAIChatMessageContent(AuthorRole.User, "content", "model-id", []);

// Act
var actualToolCalls1 = content1.GetOpenAIFunctionToolCalls();
var actualToolCalls2 = content2.GetOpenAIFunctionToolCalls();
var actualToolCalls1 = content1.GetFunctionToolCalls();
var actualToolCalls2 = content2.GetFunctionToolCalls();

// Assert
Assert.Equal(2, actualToolCalls1.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ private static ChatMessageContentItemCollection CreateContentItems(IReadOnlyList
/// Retrieve the resulting function from the chat result.
/// </summary>
/// <returns>The <see cref="AzureOpenAIFunctionToolCall"/>, or null if no function was returned by the model.</returns>
public IReadOnlyList<AzureOpenAIFunctionToolCall> GetOpenAIFunctionToolCalls()
public IReadOnlyList<AzureOpenAIFunctionToolCall> GetFunctionToolCalls()
{
List<AzureOpenAIFunctionToolCall>? functionToolCallList = null;

foreach (var toolCall in this.ToolCalls)
{
if (toolCall is ChatToolCall functionToolCall)
if (toolCall.Kind == ChatToolCallKind.Function)
{
(functionToolCallList ??= []).Add(new AzureOpenAIFunctionToolCall(functionToolCall));
(functionToolCallList ??= []).Add(new AzureOpenAIFunctionToolCall(toolCall));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public AzureOpenAIChatCompletionService(
/// Creates a new <see cref="AzureOpenAIChatCompletionService"/> client instance using the specified <see cref="OpenAIClient"/>.
/// </summary>
/// <param name="deploymentName">Azure OpenAI deployment name, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param>
/// <param name="openAIClient">Custom <see cref="OpenAIClient"/>.</param>
/// <param name="azureOpenAIClient">Custom <see cref="AzureOpenAIClient"/>.</param>
/// <param name="modelId">Azure OpenAI model id, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> to use for logging. If null, no logging will be performed.</param>
public AzureOpenAIChatCompletionService(
string deploymentName,
AzureOpenAIClient openAIClient,
AzureOpenAIClient azureOpenAIClient,
string? modelId = null,
ILoggerFactory? loggerFactory = null)
{
this._core = new(deploymentName, openAIClient, loggerFactory?.CreateLogger(typeof(AzureOpenAIChatCompletionService)));
this._core = new(deploymentName, azureOpenAIClient, loggerFactory?.CreateLogger(typeof(AzureOpenAIChatCompletionService)));
this._core.AddAttribute(AIServiceExtensions.ModelIdKey, modelId);
}

Expand Down

0 comments on commit edb7442

Please sign in to comment.