Skip to content

Commit

Permalink
Merge branch 'main' into agent-name-in-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrostruk authored Jan 28, 2025
2 parents 4de015c + 89cd872 commit 693a95b
Show file tree
Hide file tree
Showing 74 changed files with 2,029 additions and 166 deletions.
5 changes: 4 additions & 1 deletion docs/decisions/0054-processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ In technical terms, a process is something that can be represented as a graph wh

- Customers should be able to leverage their existing investments in all supported languages of Semantic Kernel.
- ```
```

- Customers should be able to leverage their existing investments in infrastructure.
- Customers should be able to collaborate with their business process peers to build up composable processes.
- Customers should be able to use AI to enhance and streamline the steps within their business processes.
Expand Down Expand Up @@ -314,5 +317,5 @@ The following packages will be created for Processes:

In validation of the proposed solution, two runtimes were created, one for the local/server scenario and one for the distributed actor scenario using Orleans. Both of these implementation were based on the [Pregel Algorithm](https://kowshik.github.io/JPregel/pregel_paper.pdf) for large-scale graph processing. This algorithm is well tested and well suited for single machine scenarios as well as distributed systems. More information on how the Pregel algorithm works can be found in the following links.

- [Pregel - The Morning Paper](https://blog.acolyer.org/2015/05/26/pregel-a-system-for-large-scale-graph-processing/)
<!-- [Pregel - The Morning Paper](https://blog.acolyer.org/2015/05/26/pregel-a-system-for-large-scale-graph-processing/) -->
<!-- [Pregel - Distributed Algorithms and Optimization](https://web.stanford.edu/~rezab/classes/cme323/S15/notes/lec8.pdf) -->
14 changes: 7 additions & 7 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.2" />
<PackageVersion Include="Azure.AI.OpenAI" Version="[2.1.0-beta.2]" />
<PackageVersion Include="Azure.AI.Projects" Version="[1.0.0-beta.3]" />
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
<PackageVersion Include="Azure.Search.Documents" Version="11.6.0" />
<PackageVersion Include="Dapr.Actors" Version="1.14.0" />
Expand Down Expand Up @@ -43,7 +43,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.66.2" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.67.2" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime" Version="1.20.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down Expand Up @@ -97,18 +97,18 @@
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
<PackageVersion Include="xretry" Version="1.9.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
<!-- Plugins -->
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.2.0" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="9.0.0" />
<PackageVersion Include="DuckDB.NET.Data.Full" Version="1.1.2.1" />
<PackageVersion Include="DuckDB.NET.Data.Full" Version="1.1.3" />
<PackageVersion Include="DuckDB.NET.Data" Version="1.1.2.1" />
<PackageVersion Include="MongoDB.Driver" Version="2.30.0" />
<PackageVersion Include="Microsoft.Graph" Version="4.51.0" />
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.61.3" />
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.67.2" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.22" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
<PackageVersion Include="Microsoft.OpenApi.ApiManifest" Version="0.5.6-preview" />
Expand All @@ -124,7 +124,7 @@
<PackageVersion Include="Pgvector" Version="0.2.0" />
<PackageVersion Include="NRedisStack" Version="0.12.0" />
<PackageVersion Include="Milvus.Client" Version="2.3.0-preview.1" />
<PackageVersion Include="Testcontainers.Milvus" Version="4.0.0" />
<PackageVersion Include="Testcontainers.Milvus" Version="4.1.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageVersion Include="Qdrant.Client" Version="1.12.0" />
<!-- Symbols -->
Expand All @@ -145,7 +145,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageVersion Include="Moq.Analyzers" Version="0.1.2" />
<PackageVersion Include="Moq.Analyzers" Version="0.3.0" />
<PackageReference Include="Moq.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/nuget/nuget-package.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<!-- Central version prefix - applies to all nuget packages. -->
<VersionPrefix>1.34.0</VersionPrefix>
<VersionPrefix>1.35.0</VersionPrefix>
<PackageVersion Condition="'$(VersionSuffix)' != ''">$(VersionPrefix)-$(VersionSuffix)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)' == ''">$(VersionPrefix)</PackageVersion>

Expand Down
3 changes: 3 additions & 0 deletions dotnet/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dotnet_diagnostic.CA2007.severity = error # Do not directly await a Task
dotnet_diagnostic.VSTHRD111.severity = error # Use .ConfigureAwait(bool)
dotnet_diagnostic.IDE1006.severity = error # Naming rule violations

# Testing
dotnet_diagnostic.Moq1400.severity = none # Explicitly choose a mocking behavior instead of relying on the default (Loose) behavior

# Resharper disabled rules: https://www.jetbrains.com/help/resharper/Reference__Code_Inspections_CSHARP.html#CodeSmell
resharper_not_resolved_in_text_highlighting = none # Disable Resharper's "Not resolved in text" highlighting
resharper_check_namespace_highlighting = none # Disable Resharper's "Check namespace" highlighting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,44 @@ public void AddChatMessageToRequest()
c => Equals(message.Role, c.Role));
}

[Fact]
public void CachedContentFromPromptReturnsAsExpected()
{
// Arrange
var prompt = "prompt-example";
var executionSettings = new GeminiPromptExecutionSettings
{
CachedContent = "xyz/abc"
};

// Act
var request = GeminiRequest.FromPromptAndExecutionSettings(prompt, executionSettings);

// Assert
Assert.NotNull(request.Configuration);
Assert.Equal(executionSettings.CachedContent, request.CachedContent);
}

[Fact]
public void CachedContentFromChatHistoryReturnsAsExpected()
{
// Arrange
ChatHistory chatHistory = [];
chatHistory.AddUserMessage("user-message");
chatHistory.AddAssistantMessage("assist-message");
chatHistory.AddUserMessage("user-message2");
var executionSettings = new GeminiPromptExecutionSettings
{
CachedContent = "xyz/abc"
};

// Act
var request = GeminiRequest.FromChatHistoryAndExecutionSettings(chatHistory, executionSettings);

// Assert
Assert.Equal(executionSettings.CachedContent, request.CachedContent);
}

private sealed class DummyContent(object? innerContent, string? modelId = null, IReadOnlyDictionary<string, object?>? metadata = null) :
KernelContent(innerContent, modelId, metadata);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.Google;
using Microsoft.SemanticKernel.Services;
using Xunit;

namespace SemanticKernel.Connectors.Google.UnitTests.Services;

public sealed class GoogleAIGeminiChatCompletionServiceTests
public sealed class GoogleAIGeminiChatCompletionServiceTests : IDisposable
{
private readonly HttpMessageHandlerStub _messageHandlerStub;
private readonly HttpClient _httpClient;

public GoogleAIGeminiChatCompletionServiceTests()
{
this._messageHandlerStub = new()
{
ResponseToReturn = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent(File.ReadAllText("./TestData/completion_one_response.json"))
}
};
this._httpClient = new HttpClient(this._messageHandlerStub, false);
}

[Fact]
public void AttributesShouldContainModelId()
{
Expand All @@ -18,4 +39,39 @@ public void AttributesShouldContainModelId()
// Assert
Assert.Equal(model, service.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Theory]
[InlineData(null)]
[InlineData("content")]
[InlineData("")]
public async Task RequestCachedContentWorksCorrectlyAsync(string? cachedContent)
{
// Arrange
string model = "fake-model";
var sut = new GoogleAIGeminiChatCompletionService(model, "key", httpClient: this._httpClient);

// Act
var result = await sut.GetChatMessageContentAsync("my prompt", new GeminiPromptExecutionSettings { CachedContent = cachedContent });

// Assert
Assert.NotNull(result);
Assert.NotNull(this._messageHandlerStub.RequestContent);

var requestBody = UTF8Encoding.UTF8.GetString(this._messageHandlerStub.RequestContent);
if (cachedContent is not null)
{
Assert.Contains($"\"cachedContent\":\"{cachedContent}\"", requestBody);
}
else
{
// Then no quality is provided, it should not be included in the request body
Assert.DoesNotContain("cachedContent", requestBody);
}
}

public void Dispose()
{
this._httpClient.Dispose();
this._messageHandlerStub.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.Google;
using Microsoft.SemanticKernel.Services;
using Xunit;

namespace SemanticKernel.Connectors.Google.UnitTests.Services;

public sealed class VertexAIGeminiChatCompletionServiceTests
public sealed class VertexAIGeminiChatCompletionServiceTests : IDisposable
{
private readonly HttpMessageHandlerStub _messageHandlerStub;
private readonly HttpClient _httpClient;

public VertexAIGeminiChatCompletionServiceTests()
{
this._messageHandlerStub = new()
{
ResponseToReturn = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent(File.ReadAllText("./TestData/completion_one_response.json"))
}
};
this._httpClient = new HttpClient(this._messageHandlerStub, false);
}

[Fact]
public void AttributesShouldContainModelIdBearerAsString()
{
Expand All @@ -30,4 +50,39 @@ public void AttributesShouldContainModelIdBearerAsFunc()
// Assert
Assert.Equal(model, service.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Theory]
[InlineData(null)]
[InlineData("content")]
[InlineData("")]
public async Task RequestCachedContentWorksCorrectlyAsync(string? cachedContent)
{
// Arrange
string model = "fake-model";
var sut = new VertexAIGeminiChatCompletionService(model, () => new ValueTask<string>("key"), "location", "project", httpClient: this._httpClient);

// Act
var result = await sut.GetChatMessageContentAsync("my prompt", new GeminiPromptExecutionSettings { CachedContent = cachedContent });

// Assert
Assert.NotNull(result);
Assert.NotNull(this._messageHandlerStub.RequestContent);

var requestBody = UTF8Encoding.UTF8.GetString(this._messageHandlerStub.RequestContent);
if (cachedContent is not null)
{
Assert.Contains($"\"cachedContent\":\"{cachedContent}\"", requestBody);
}
else
{
// Then no quality is provided, it should not be included in the request body
Assert.DoesNotContain("cachedContent", requestBody);
}
}

public void Dispose()
{
this._httpClient.Dispose();
this._messageHandlerStub.Dispose();
}
}
1 change: 1 addition & 0 deletions dotnet/src/Connectors/Connectors.Google/Core/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected static string GetApiVersionSubLink(VertexAIVersion apiVersion)
=> apiVersion switch
{
VertexAIVersion.V1 => "v1",
VertexAIVersion.V1_Beta => "v1beta1",
_ => throw new NotSupportedException($"Vertex API version {apiVersion} is not supported.")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ internal sealed class GeminiRequest
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public GeminiContent? SystemInstruction { get; set; }

[JsonPropertyName("cachedContent")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? CachedContent { get; set; }

public void AddFunction(GeminiFunction function)
{
// NOTE: Currently Gemini only supports one tool i.e. function calling.
Expand All @@ -67,6 +71,7 @@ public static GeminiRequest FromPromptAndExecutionSettings(
GeminiRequest obj = CreateGeminiRequest(prompt);
AddSafetySettings(executionSettings, obj);
AddConfiguration(executionSettings, obj);
AddAdditionalBodyFields(executionSettings, obj);
return obj;
}

Expand All @@ -83,6 +88,7 @@ public static GeminiRequest FromChatHistoryAndExecutionSettings(
GeminiRequest obj = CreateGeminiRequest(chatHistory);
AddSafetySettings(executionSettings, obj);
AddConfiguration(executionSettings, obj);
AddAdditionalBodyFields(executionSettings, obj);
return obj;
}

Expand Down Expand Up @@ -318,6 +324,11 @@ private static void AddSafetySettings(GeminiPromptExecutionSettings executionSet
=> new GeminiSafetySetting(s.Category, s.Threshold)).ToList();
}

private static void AddAdditionalBodyFields(GeminiPromptExecutionSettings executionSettings, GeminiRequest request)
{
request.CachedContent = executionSettings.CachedContent;
}

internal sealed class ConfigurationElement
{
[JsonPropertyName("temperature")]
Expand Down
Loading

0 comments on commit 693a95b

Please sign in to comment.