Skip to content

Commit

Permalink
Dependencies upgrade (#868)
Browse files Browse the repository at this point in the history
* SK 1.25.0
* Azure.Identity 1.13.1
* LLamaSharp 0.18
* OllamaSharp 4.0.2
  • Loading branch information
dluc authored Oct 30, 2024
1 parent 6422472 commit e5adeeb
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 137 deletions.
49 changes: 24 additions & 25 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.2.1" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.405" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.405.6" />
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageVersion Include="Azure.AI.FormRecognizer" Version="4.1.0" />
<PackageVersion Include="Azure.Identity" Version="1.13.0" />
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
<PackageVersion Include="Azure.Search.Documents" Version="11.6.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.22.2" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.20.1" />
<PackageVersion Include="ClosedXML" Version="0.104.1" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.12.1" />
<PackageVersion Include="Discord.Net" Version="3.16.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.1.1" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.67" />
<PackageVersion Include="LLamaSharp" Version="0.16.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="LLamaSharp.Backend.Cpu" Version="0.16.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="LLamaSharp.Backend.Cuda11" Version="0.12.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="LLamaSharp.Backend.Cuda12" Version="0.12.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="LLamaSharp.Backend.OpenCL" Version="0.12.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="HtmlAgilityPack" Version="1.11.70" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand All @@ -33,34 +25,41 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.4.0" />
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24378.1" /> <!-- prerelease dependency (NU5104) -->
<PackageVersion Include="MongoDB.Driver.GridFS" Version="2.30.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OllamaSharp" Version="3.0.14" />
<PackageVersion Include="OllamaSharp" Version="4.0.2" />
<PackageVersion Include="PdfPig" Version="0.1.9" />
<PackageVersion Include="Pgvector" Version="0.3.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="Polly.Core" Version="8.4.2" />
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
<PackageVersion Include="NRedisStack" Version="0.13.0" /> <!-- missing strong name (CS8002) -->
<PackageVersion Include="ReadLine" Version="2.0.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Memory.Data" Version="8.0.1" />
<PackageVersion Include="System.Numerics.Tensors" Version="8.0.0" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.1" /> <!-- version with security fixes -->
</ItemGroup>
<!-- KM examples -->
<!-- Security upgrades -->
<ItemGroup>
<PackageVersion Include="Microsoft.KernelMemory.Core" Version="0.80.241017.2" />
<PackageVersion Include="Microsoft.KernelMemory.Service.AspNetCore" Version="0.80.241017.2" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.1" />
</ItemGroup>
<!-- Pre-release dependencies -->
<ItemGroup>
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24378.1" />
</ItemGroup>
<!-- Missing Strong Name (CS8002) -->
<ItemGroup>
<PackageVersion Include="ClosedXML" Version="0.104.1" />
<PackageVersion Include="LLamaSharp" Version="0.18.0" />
<PackageVersion Include="LLamaSharp.Backend.Cpu" Version="0.18.0" />
<PackageVersion Include="Pgvector" Version="0.3.0" />
<PackageVersion Include="NRedisStack" Version="0.13.0" />
</ItemGroup>
<!-- Semantic Kernel -->
<ItemGroup>
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.24.1" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.24.1" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.24.1" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureOpenAI" Version="1.24.1" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureOpenAI" Version="1.25.0" />
</ItemGroup>
<!-- Documentation -->
<ItemGroup>
Expand All @@ -81,11 +80,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.8">
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.8">
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
7 changes: 0 additions & 7 deletions KernelMemory.sln
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch", "extensions
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.FunctionalTests", "extensions\Elasticsearch\Elasticsearch.FunctionalTests\Elasticsearch.FunctionalTests.csproj", "{C5E6B28C-F54D-423D-954D-A9EAEFB89732}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord", "extensions\Discord\Discord\Discord.csproj", "{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "301-discord-test-application", "examples\301-discord-test-application\301-discord-test-application.csproj", "{FAE4C6B8-38B2-43E7-8881-99693C9CEDC6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "applications", "applications", "{DBEA0A6B-474A-4E8C-BCC8-D5D43C063A54}"
Expand Down Expand Up @@ -555,10 +553,6 @@ Global
{C5E6B28C-F54D-423D-954D-A9EAEFB89732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5E6B28C-F54D-423D-954D-A9EAEFB89732}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5E6B28C-F54D-423D-954D-A9EAEFB89732}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B}.Release|Any CPU.Build.0 = Release|Any CPU
{FAE4C6B8-38B2-43E7-8881-99693C9CEDC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAE4C6B8-38B2-43E7-8881-99693C9CEDC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAE4C6B8-38B2-43E7-8881-99693C9CEDC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -697,7 +691,6 @@ Global
{B9BE1099-F78F-4A5F-A897-BF2C75E19C57} = {155DA079-E267-49AF-973A-D1D44681970F}
{2E10420F-BF96-411C-8FE0-F6268F2EEB67} = {155DA079-E267-49AF-973A-D1D44681970F}
{C5E6B28C-F54D-423D-954D-A9EAEFB89732} = {3C17F42B-CFC8-4900-8CFB-88936311E919}
{43877864-6AE8-4B03-BEDA-6B6FA8BB1D8B} = {155DA079-E267-49AF-973A-D1D44681970F}
{FAE4C6B8-38B2-43E7-8881-99693C9CEDC6} = {0A43C65C-6007-4BB4-B3FE-8D439FC91841}
{432AC1B4-8275-4284-9A44-44988A6F0C24} = {DBEA0A6B-474A-4E8C-BCC8-D5D43C063A54}
{A0C81A29-715F-463E-A243-7E45DB8AE53F} = {155DA079-E267-49AF-973A-D1D44681970F}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.KernelMemory.Service.AspNetCore" />
<PackageReference Include="Microsoft.KernelMemory.Service.AspNetCore" Version="0.90.241021.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RollForward>LatestMajor</RollForward>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\extensions\Discord\Discord\Discord.csproj" />
<ProjectReference Include="..\..\service\Service.AspNetCore\Service.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.2.2" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="Microsoft.KernelMemory.Service.AspNetCore" Version="0.90.241021.1" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions examples/301-discord-test-application/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.KernelMemory.Diagnostics;

namespace Microsoft.KernelMemory.Sources.DiscordBot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Collections.Generic;

namespace Microsoft.KernelMemory.Sources.DiscordBot;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Text.Json.Serialization;

namespace Microsoft.KernelMemory.Sources.DiscordBot;
Expand Down
28 changes: 0 additions & 28 deletions extensions/Discord/Discord/Discord.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion extensions/LlamaSharp/LlamaSharp/LlamaSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\service\Abstractions\Abstractions.csproj" />
<ProjectReference Include="..\..\OpenAI\OpenAI\OpenAI.csproj" />
<ProjectReference Include="..\..\..\service\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions extensions/LlamaSharp/LlamaSharp/LlamaSharpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class LlamaSharpConfig
/// </summary>
public int? GpuLayerCount { get; set; }

public uint? Seed { get; set; } = 1337;

/// <summary>
/// Verify that the current state is valid.
/// </summary>
Expand Down
81 changes: 27 additions & 54 deletions extensions/LlamaSharp/LlamaSharp/LlamaSharpTextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using LLama;
using LLama.Abstractions;
using LLama.Common;
using LLama.Native;
using LLama.Sampling;
using Microsoft.Extensions.Logging;
using Microsoft.KernelMemory.AI.OpenAI;
using Microsoft.KernelMemory.Diagnostics;

namespace Microsoft.KernelMemory.AI.LlamaSharp;
Expand Down Expand Up @@ -43,36 +43,27 @@ public LlamaSharpTextGenerator(
config.Validate();
this.MaxTokenTotal = (int)config.MaxTokenTotal;

if (textTokenizer == null)
{
this._log.LogWarning(
"Tokenizer not specified, will use {0}. The token count might be incorrect, causing unexpected errors",
nameof(GPT4oTokenizer));
textTokenizer = new GPT4oTokenizer();
}

this._textTokenizer = textTokenizer;

var parameters = new ModelParams(config.ModelPath)
{
ContextSize = config.MaxTokenTotal
ContextSize = config.MaxTokenTotal,
GpuLayerCount = config.GpuLayerCount ?? 20,
};

if (config.GpuLayerCount.HasValue)
{
parameters.GpuLayerCount = config.GpuLayerCount.Value;
}

if (config.Seed.HasValue)
{
parameters.Seed = config.Seed.Value;
}

var modelFilename = config.ModelPath.Split('/').Last().Split('\\').Last();
this._log.LogDebug("Loading LLama model: {1}", modelFilename);
this._model = LLamaWeights.LoadFromFile(parameters);
this._context = this._model.CreateContext(parameters);
this._log.LogDebug("LLama model loaded");

if (textTokenizer == null)
{
this._log.LogWarning(
"Tokenizer not specified, will use {0}. The token count might be incorrect, causing unexpected errors",
nameof(DefaultGPTTokenizer));
textTokenizer = new DefaultGPTTokenizer();
}

this._textTokenizer = textTokenizer;
}

/// <inheritdoc/>
Expand All @@ -81,13 +72,7 @@ public LlamaSharpTextGenerator(
/// <inheritdoc/>
public int CountTokens(string text)
{
int? value = this._textTokenizer?.CountTokens(text);
if (!value.HasValue)
{
value = this._context.Tokenize(text, addBos: false, special: false).Length;
}

return value.Value;
return this._textTokenizer.CountTokens(text);
}

/// <inheritdoc/>
Expand All @@ -104,19 +89,18 @@ public IAsyncEnumerable<string> GenerateTextAsync(
{
var executor = new InteractiveExecutor(this._context);

var samplingPipeline = new DefaultSamplingPipeline();
samplingPipeline.Temperature = (float)options.Temperature;
samplingPipeline.TopP = (float)options.NucleusSampling;
samplingPipeline.AlphaPresence = (float)options.PresencePenalty;
samplingPipeline.AlphaFrequency = (float)options.FrequencyPenalty;
var logitBias = options.TokenSelectionBiases.Count > 0
? options.TokenSelectionBiases.ToDictionary(pair => (LLamaToken)pair.Key, pair => pair.Value)
: new Dictionary<LLamaToken, float>();

if (options.TokenSelectionBiases is { Count: > 0 })
var samplingPipeline = new DefaultSamplingPipeline()
{
foreach (var (token, bias) in options.TokenSelectionBiases)
{
samplingPipeline.LogitBias!.Add(token, bias);
}
}
Temperature = (float)options.Temperature,
TopP = (float)options.NucleusSampling,
AlphaPresence = (float)options.PresencePenalty,
AlphaFrequency = (float)options.FrequencyPenalty,
LogitBias = logitBias,
};

IInferenceParams settings = new InferenceParams
{
Expand All @@ -126,26 +110,15 @@ public IAsyncEnumerable<string> GenerateTextAsync(
SamplingPipeline = samplingPipeline
};

this._log.LogTrace("Generating text, temperature {0}, max tokens {1}",
samplingPipeline.Temperature, settings.MaxTokens);
return executor.InferAsync(prompt, settings, cancellationToken);
}

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!disposing) { return; }

this._context.Dispose();
this._model.Dispose();
}

~LlamaSharpTextGenerator()
{
this.Dispose(false);
this._context.Dispose();
}
}
Loading

0 comments on commit e5adeeb

Please sign in to comment.