Skip to content

Commit

Permalink
update 0.5.0 (#27)
Browse files Browse the repository at this point in the history
* 1. Update Semantic Kernel to version 1.3.0
* 2. Cleaned up vector databases and embedding configurations that cannot currently provide a better user experience.

* update logo and version
  • Loading branch information
xbotter authored Feb 6, 2024
1 parent 9ca7ca6 commit 8da153b
Show file tree
Hide file tree
Showing 52 changed files with 709 additions and 2,402 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,4 @@ $RECYCLE.BIN/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/Output
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<Version>0.4.0</Version>
<Version>0.5.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
4 changes: 2 additions & 2 deletions PromptPlayground.Desktop/PromptPlayground.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>WinExe</OutputType>
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net7.0-windows TFM, one for MacOS with net7.0-macos and one with net7.0 TFM for Linux.-->
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand All @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file modified PromptPlayground.Desktop/logo.ico
Binary file not shown.
Binary file modified PromptPlayground/Assets/logo.ico
Binary file not shown.
Binary file modified PromptPlayground/Assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/CloseFunctionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace PromptPlayground.Messages
{
public class CloseFunctionMessage
{
public CloseFunctionMessage(SemanticFunctionViewModel function)
public CloseFunctionMessage(SemanticPluginViewModel function)
{
Function = function;
}

public SemanticFunctionViewModel Function { get; }
public SemanticPluginViewModel Function { get; }
}
}
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/FunctionCreateMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
public class FunctionCreateMessage
{
public FunctionCreateMessage(SemanticFunctionViewModel? function = null)
public FunctionCreateMessage(SemanticPluginViewModel? function = null)
{
Function = function;
}

public SemanticFunctionViewModel? Function { get; }
public SemanticPluginViewModel? Function { get; }
}
}
4 changes: 2 additions & 2 deletions PromptPlayground/Messages/FunctionSelectedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace PromptPlayground.Messages
{
public class FunctionSelectedMessage
{
public SemanticFunctionViewModel Function { get; set; }
public SemanticPluginViewModel Function { get; set; }

public FunctionSelectedMessage(SemanticFunctionViewModel viewModel)
public FunctionSelectedMessage(SemanticPluginViewModel viewModel)
{
this.Function = viewModel;
}
Expand Down
33 changes: 17 additions & 16 deletions PromptPlayground/PromptPlayground.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>Assets\logo.ico</ApplicationIcon>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
<Platforms>AnyCPU;x64</Platforms>
<NoWarn>SKEXP0001;SKEXP0002;SKEXP0050</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
Expand All @@ -23,24 +24,24 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Xaml.Interactions" Version="11.0.2" />
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageReference Include="DashScope.SemanticKernel" Version="0.1.0-preview" />
<PackageReference Include="Avalonia" Version="11.0.7" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.7" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.7" />
<PackageReference Include="Avalonia.Xaml.Interactions" Version="11.0.6" />
<PackageReference Include="Bogus" Version="35.4.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="DashScope.SemanticKernel" Version="0.8.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Memory.Qdrant" Version="0.21.230828.2-preview" />
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="8.1.0" />
<PackageReference Include="Semi.Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="1.3.0-alpha" />
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="9.0.1" />
<PackageReference Include="Semi.Avalonia" Version="11.0.7" />

<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageReference Include="ERNIE-Bot.SemanticKernel" Version="0.5.1-preview" />
<PackageReference Include="MessageBox.Avalonia" Version="3.0.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.21.230828.2-preview" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.7" />
<PackageReference Include="ERNIE-Bot.SemanticKernel" Version="0.14.0" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
130 changes: 51 additions & 79 deletions PromptPlayground/Services/PromptService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.SemanticFunctions;
using Microsoft.SemanticKernel.Skills.Core;
using Microsoft.SemanticKernel.Plugins.Core;
using PromptPlayground.ViewModels.ConfigViewModels;
using PromptPlayground.ViewModels.ConfigViewModels.Embedding;
using PromptPlayground.ViewModels.ConfigViewModels.LLM;
using PromptPlayground.ViewModels.ConfigViewModels.VectorDB;
using System;
using System.Diagnostics;
using System.Linq;
Expand All @@ -14,80 +10,56 @@

namespace PromptPlayground.Services
{
public class PromptService
{
private readonly IKernel _kernel;
private readonly ILLMConfigViewModel model;
private readonly IConfigAttributesProvider provider;

public PromptService(IConfigAttributesProvider provider)
{
this.provider = provider;

this.model = provider.GetLLM() ?? throw new Exception("无法创建Kernel,请检查LLM配置");

var builder = model.CreateKernelBuilder();

if (provider.GetEmbedding() is IEmbeddingConfigViewModel embedding)
{
embedding.RegisterEmbedding(builder);

if (provider.GetVectorDb() is IVectorDbConfigViewModel vectorDb)
{
vectorDb.RegisterMemory(builder);
}
}

_kernel = builder.Build();

if (_kernel.Memory is not null)
{
_kernel.ImportSkill(new TextMemorySkill(_kernel.Memory));
}

_kernel.ImportSkill(new TimeSkill());

}

public async Task<GenerateResult> RunAsync(string prompt, PromptTemplateConfig config, SKContext context, CancellationToken cancellationToken = default)
{
var sw = Stopwatch.StartNew();
var func = _kernel.CreateSemanticFunction(prompt, config);

if (provider.GetVectorDb() is IVectorDbConfigViewModel vectorDb)
{
context.Variables[TextMemorySkill.CollectionParam] = vectorDb.Collection;
context.Variables[TextMemorySkill.LimitParam] = vectorDb.Limit.ToString();
context.Variables[TextMemorySkill.RelevanceParam] = vectorDb.Relevance.ToString();
}

var result = await func.InvokeAsync(context);
sw.Stop();
if (!result.ErrorOccurred)
{
var usage = model.GetUsage(result.ModelResults.Last());

return new GenerateResult()
{
Text = result.Result,
Elapsed = sw.Elapsed,
Error = result.LastException?.Message,
TokenUsage = usage
};
}
else
{
return new GenerateResult()
{
Text = result.Result,
Elapsed = sw.Elapsed,
Error = result.LastException!.Message,
};
}
}

public SKContext CreateContext() => _kernel.CreateNewContext();
}
public class PromptService
{
private readonly Kernel _kernel;
private readonly ILLMConfigViewModel model;

public PromptService(IConfigAttributesProvider provider)
{
this.model = provider.GetLLM() ?? throw new Exception("无法创建Kernel,请检查LLM配置");

var builder = model.CreateKernelBuilder();


_kernel = builder.Build();

_kernel.ImportPluginFromType<TimePlugin>();

}

public async Task<GenerateResult> RunAsync(string prompt, PromptExecutionSettings? config, KernelArguments arguments, CancellationToken cancellationToken = default)
{
var sw = Stopwatch.StartNew();
var func = _kernel.CreateFunctionFromPrompt(prompt, config);

var result = await func.InvokeAsync(_kernel, arguments);
sw.Stop();
try
{
var usage = model.GetUsage(result);
return new GenerateResult()
{
Text = result.GetValue<string>() ?? "",
TokenUsage = usage,
Elapsed = sw.Elapsed,

};

}
catch (KernelException ex)
{
return new GenerateResult()
{
Text = ex.Message,
Elapsed = sw.Elapsed,
Error = ex.Message,
};
}
}

public KernelArguments CreateArguments() => new KernelArguments();
}


}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8da153b

Please sign in to comment.