diff --git a/LLama.Examples/Examples/SemanticKernelChat.cs b/LLama.Examples/Examples/SemanticKernelChat.cs index a9d5be54..86d7a1d5 100644 --- a/LLama.Examples/Examples/SemanticKernelChat.cs +++ b/LLama.Examples/Examples/SemanticKernelChat.cs @@ -2,6 +2,7 @@ using LLama.Common; using Microsoft.SemanticKernel.AI.ChatCompletion; using LLamaSharp.SemanticKernel.ChatCompletion; +using Microsoft.SemanticKernel.ChatCompletion; namespace LLama.Examples.Examples { @@ -29,8 +30,8 @@ namespace LLama.Examples.Examples await MessageOutputAsync(chatHistory); // First bot assistant message - string reply = await chatGPT.GetChatMessageContentAsync(chatHistory); - chatHistory.AddAssistantMessage(reply); + var reply = await chatGPT.GetChatMessageContentAsync(chatHistory); + chatHistory.AddAssistantMessage(reply.Content); await MessageOutputAsync(chatHistory); // Second user message @@ -39,14 +40,14 @@ namespace LLama.Examples.Examples // Second bot assistant message reply = await chatGPT.GetChatMessageContentAsync(chatHistory); - chatHistory.AddAssistantMessage(reply); + chatHistory.AddAssistantMessage(reply.Content); await MessageOutputAsync(chatHistory); } /// /// Outputs the last message of the chat history /// - private static Task MessageOutputAsync(Microsoft.SemanticKernel.AI.ChatCompletion.ChatHistory chatHistory) + private static Task MessageOutputAsync(Microsoft.SemanticKernel.ChatCompletion.ChatHistory chatHistory) { var message = chatHistory.Last(); diff --git a/LLama.Examples/Examples/SemanticKernelPrompt.cs b/LLama.Examples/Examples/SemanticKernelPrompt.cs index 21cb55de..4c4157a3 100644 --- a/LLama.Examples/Examples/SemanticKernelPrompt.cs +++ b/LLama.Examples/Examples/SemanticKernelPrompt.cs @@ -3,7 +3,7 @@ using LLama.Common; using LLamaSharp.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel; using LLamaSharp.SemanticKernel.TextCompletion; -using Microsoft.SemanticKernel.AI.TextGeneration; +using Microsoft.SemanticKernel.TextGeneration; using Microsoft.Extensions.DependencyInjection; namespace LLama.Examples.Examples @@ -21,7 +21,7 @@ namespace LLama.Examples.Examples using var model = LLamaWeights.LoadFromFile(parameters); var ex = new StatelessExecutor(model, parameters); - var builder = new KernelBuilder(); + var builder = Kernel.CreateBuilder(); builder.Services.AddKeyedSingleton("local-llama", new LLamaSharpTextCompletion(ex)); var kernel = builder.Build(); @@ -43,9 +43,9 @@ One line TLDR with the fewest words."; 2. The acceleration of an object depends on the mass of the object and the amount of force applied. 3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first."; - Console.WriteLine((await kernel.InvokeAsync(summarize,new KernelArguments(text1))).GetValue()); + Console.WriteLine((await kernel.InvokeAsync(summarize, new() { ["input"] = text1 })).GetValue()); - Console.WriteLine((await kernel.InvokeAsync(summarize, new KernelArguments(text2))).GetValue()); + Console.WriteLine((await kernel.InvokeAsync(summarize, new() { ["input"] = text2 })).GetValue()); } } } diff --git a/LLama.Examples/LLama.Examples.csproj b/LLama.Examples/LLama.Examples.csproj index 9e4f17ab..2266bdcf 100644 --- a/LLama.Examples/LLama.Examples.csproj +++ b/LLama.Examples/LLama.Examples.csproj @@ -16,7 +16,7 @@ - + diff --git a/LLama.SemanticKernel/ChatCompletion/ChatRequestSettings.cs b/LLama.SemanticKernel/ChatCompletion/ChatRequestSettings.cs index aab3240f..ac22e1fc 100644 --- a/LLama.SemanticKernel/ChatCompletion/ChatRequestSettings.cs +++ b/LLama.SemanticKernel/ChatCompletion/ChatRequestSettings.cs @@ -1,4 +1,4 @@ -using Microsoft.SemanticKernel.AI; +using Microsoft.SemanticKernel; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/LLama.SemanticKernel/ChatCompletion/ChatRequestSettingsConverter.cs b/LLama.SemanticKernel/ChatCompletion/ChatRequestSettingsConverter.cs index f0d3a430..e320ea3f 100644 --- a/LLama.SemanticKernel/ChatCompletion/ChatRequestSettingsConverter.cs +++ b/LLama.SemanticKernel/ChatCompletion/ChatRequestSettingsConverter.cs @@ -31,6 +31,10 @@ public class ChatRequestSettingsConverter : JsonConverter switch (propertyName) { + case "MODELID": + case "MODEL_ID": + requestSettings.ModelId = reader.GetString(); + break; case "TEMPERATURE": requestSettings.Temperature = reader.GetDouble(); break; @@ -62,10 +66,6 @@ public class ChatRequestSettingsConverter : JsonConverter case "TOKEN_SELECTION_BIASES": requestSettings.TokenSelectionBiases = JsonSerializer.Deserialize>(ref reader, options) ?? new Dictionary(); break; - case "SERVICEID": - case "SERVICE_ID": - requestSettings.ServiceId = reader.GetString(); - break; default: reader.Skip(); break; @@ -98,7 +98,6 @@ public class ChatRequestSettingsConverter : JsonConverter writer.WriteNumber("results_per_prompt", value.ResultsPerPrompt); writer.WritePropertyName("token_selection_biases"); JsonSerializer.Serialize(writer, value.TokenSelectionBiases, options); - writer.WriteString("service_id", value.ServiceId); writer.WriteEndObject(); } diff --git a/LLama.SemanticKernel/ChatCompletion/LLamaSharpChatCompletion.cs b/LLama.SemanticKernel/ChatCompletion/LLamaSharpChatCompletion.cs index 9611a0cf..b1c0d347 100644 --- a/LLama.SemanticKernel/ChatCompletion/LLamaSharpChatCompletion.cs +++ b/LLama.SemanticKernel/ChatCompletion/LLamaSharpChatCompletion.cs @@ -1,8 +1,7 @@ using LLama; using LLama.Abstractions; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.AI; -using Microsoft.SemanticKernel.AI.ChatCompletion; +using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Services; using System; using System.IO; @@ -22,11 +21,9 @@ public sealed class LLamaSharpChatCompletion : IChatCompletionService private readonly IHistoryTransform historyTransform; private readonly ITextStreamTransform outputTransform; - private readonly Dictionary _attributes = new(); + private readonly Dictionary _attributes = new(); - public IReadOnlyDictionary Attributes => this._attributes; - - IReadOnlyDictionary IAIService.Attributes => throw new NotImplementedException(); + public IReadOnlyDictionary Attributes => this._attributes; static ChatRequestSettings GetDefaultSettings() { diff --git a/LLama.SemanticKernel/ExtensionMethods.cs b/LLama.SemanticKernel/ExtensionMethods.cs index 6f39e373..85f9064c 100644 --- a/LLama.SemanticKernel/ExtensionMethods.cs +++ b/LLama.SemanticKernel/ExtensionMethods.cs @@ -1,6 +1,5 @@ using LLamaSharp.SemanticKernel.ChatCompletion; -using Microsoft.SemanticKernel.AI.ChatCompletion; - +using Microsoft.SemanticKernel.ChatCompletion; namespace LLamaSharp.SemanticKernel; public static class ExtensionMethods diff --git a/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj b/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj index 501ca9d2..8a39de53 100644 --- a/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj +++ b/LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj @@ -34,7 +34,7 @@ - + diff --git a/LLama.SemanticKernel/TextCompletion/LLamaSharpTextCompletion.cs b/LLama.SemanticKernel/TextCompletion/LLamaSharpTextCompletion.cs index e7a6151b..08ec33e1 100644 --- a/LLama.SemanticKernel/TextCompletion/LLamaSharpTextCompletion.cs +++ b/LLama.SemanticKernel/TextCompletion/LLamaSharpTextCompletion.cs @@ -1,9 +1,8 @@ using LLama.Abstractions; using LLamaSharp.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.AI; -using Microsoft.SemanticKernel.AI.TextGeneration; using Microsoft.SemanticKernel.Services; +using Microsoft.SemanticKernel.TextGeneration; using System.Runtime.CompilerServices; using System.Text; @@ -13,11 +12,9 @@ public sealed class LLamaSharpTextCompletion : ITextGenerationService { public ILLamaExecutor executor; - private readonly Dictionary _attributes = new(); + private readonly Dictionary _attributes = new(); - public IReadOnlyDictionary Attributes => this._attributes; - - IReadOnlyDictionary IAIService.Attributes => throw new NotImplementedException(); + public IReadOnlyDictionary Attributes => this._attributes; public LLamaSharpTextCompletion(ILLamaExecutor executor) { diff --git a/LLama.SemanticKernel/TextEmbedding/LLamaSharpEmbeddingGeneration.cs b/LLama.SemanticKernel/TextEmbedding/LLamaSharpEmbeddingGeneration.cs index 83c97f02..73ceb0f2 100644 --- a/LLama.SemanticKernel/TextEmbedding/LLamaSharpEmbeddingGeneration.cs +++ b/LLama.SemanticKernel/TextEmbedding/LLamaSharpEmbeddingGeneration.cs @@ -1,10 +1,10 @@ using LLama; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.AI.Embeddings; +using Microsoft.SemanticKernel.Embeddings; namespace LLamaSharp.SemanticKernel.TextEmbedding; -public sealed class LLamaSharpEmbeddingGeneration : ITextEmbeddingGeneration +public sealed class LLamaSharpEmbeddingGeneration : ITextEmbeddingGenerationService { private LLamaEmbedder _embedder; diff --git a/LLama.Unittest/SemanticKernel/ChatRequestSettingsTests.cs b/LLama.Unittest/SemanticKernel/ChatRequestSettingsTests.cs index f552114d..ef5d9670 100644 --- a/LLama.Unittest/SemanticKernel/ChatRequestSettingsTests.cs +++ b/LLama.Unittest/SemanticKernel/ChatRequestSettingsTests.cs @@ -1,5 +1,5 @@ using LLamaSharp.SemanticKernel.ChatCompletion; -using Microsoft.SemanticKernel.AI; +using Microsoft.SemanticKernel; namespace LLama.Unittest.SemanticKernel { @@ -77,7 +77,7 @@ namespace LLama.Unittest.SemanticKernel // Arrange var originalRequestSettings = new PromptExecutionSettings() { - ServiceId = "test", + ModelId = "test", }; // Act @@ -85,7 +85,7 @@ namespace LLama.Unittest.SemanticKernel // Assert Assert.NotNull(requestSettings); - Assert.Equal(originalRequestSettings.ServiceId, requestSettings.ServiceId); + Assert.Equal(originalRequestSettings.ModelId, requestSettings.ModelId); } [Fact] @@ -94,7 +94,7 @@ namespace LLama.Unittest.SemanticKernel // Arrange var originalRequestSettings = new PromptExecutionSettings() { - ServiceId = "test", + ModelId = "test", ExtensionData = new Dictionary { { "frequency_penalty", 0.5 }, @@ -133,7 +133,7 @@ namespace LLama.Unittest.SemanticKernel // Arrange var originalRequestSettings = new PromptExecutionSettings() { - ServiceId = "test", + ModelId = "test", ExtensionData = new Dictionary { { "FrequencyPenalty", 0.5 },