Seperate out LLamaSharp plugin.#100

This commit is contained in:
Haiping Chen 2023-08-19 08:25:47 -05:00
parent 316d7d9b0b
commit 47f8fddbac
27 changed files with 104 additions and 20 deletions

View file

@ -43,7 +43,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.PaddleSharp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MetaMessenger", "src\Plugins\BotSharp.Plugin.MetaMessenger\BotSharp.Plugin.MetaMessenger.csproj", "{8300F66D-9EB8-438A-BF0F-70DFBE07D9DE}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MetaMessenger", "src\Plugins\BotSharp.Plugin.MetaMessenger\BotSharp.Plugin.MetaMessenger.csproj", "{8300F66D-9EB8-438A-BF0F-70DFBE07D9DE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.OpenAPI", "src\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj", "{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.OpenAPI", "src\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj", "{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.LLamaSharp", "src\Plugins\BotSharp.Plugin.LLamaSharp\BotSharp.Plugin.LLamaSharp.csproj", "{46B7B54F-1425-4C9D-824A-9B826855D249}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -157,6 +159,14 @@ Global
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|Any CPU.Build.0 = Release|Any CPU {7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|Any CPU.Build.0 = Release|Any CPU
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|x64.ActiveCfg = Release|Any CPU {7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|x64.ActiveCfg = Release|Any CPU
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|x64.Build.0 = Release|Any CPU {7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}.Release|x64.Build.0 = Release|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Debug|x64.ActiveCfg = Debug|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Debug|x64.Build.0 = Debug|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|Any CPU.Build.0 = Release|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|x64.ActiveCfg = Release|Any CPU
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -179,6 +189,7 @@ Global
{0308FBFD-57EB-4709-9AE4-A80D516AD84D} = {B797EC3E-B5B9-4047-A6C8-6D330B7C6763} {0308FBFD-57EB-4709-9AE4-A80D516AD84D} = {B797EC3E-B5B9-4047-A6C8-6D330B7C6763}
{8300F66D-9EB8-438A-BF0F-70DFBE07D9DE} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00} {8300F66D-9EB8-438A-BF0F-70DFBE07D9DE} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749} {7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{46B7B54F-1425-4C9D-824A-9B826855D249} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2023-08-15T02:10:02.985Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" version="20.6.0" etag="WycAnBgN-yxZpTCzoOFG" type="device"><diagram id="6jfvZ688tm8pOZHgqSFM" name="Page-1">zZVdb4MgFIZ/jZdNFLraXbau3W72kXTLromcCimCo3Ta/frBxFq1TdZkSZcYA+85HOB5EQOc5NW9JgV7VBREgEJaBfguQCgaIxS4J6T7WomnYS1kmlOf1Aor/gVebNJ2nMK2k2iUEoYXXTFVUkJqOhrRWpXdtLUS3VkLksFAWKVEDNV3Tg2r1SmKW/0BeMaamaPJbR3JSZPsd7JlhKrySMKLACdaKVO38ioB4eA1XOpxyzPRw8I0SPObAZundLwc4dnHm6axmC03rxUa+SqfROz8hhNGjF+w2TcUtNpJCq5QFOB5ybiBVUFSFy2t71ZjJhc+7EuCNlCdXWt0IGCPDqgcjN7bFD8AjT20fa9fth5EDVh2xH/iNeJtzw6lWzK24eFcAAoNQL0wJeHqpMb/jhQekHp2nMK5JlxenRfu8cLxtXnFpz5BRypUa/uaZXZn2wE3S8B04WyNVhtIlFDaKtIdTjxfcyF6EhE8k7ab2rpg9bnjye2NN/OBnFPqpjnpRutX+DeGRLhnyPRmYMjkhB/4cj9st71uf2JHPy28+AY=</diagram></mxfile>

View file

@ -1 +1,31 @@
# Hooks # Hooks
`Hook` is a place in `BotSharp` that allows you to tap in to a module to either provide different behavior or to react.
## Agent Hook
`IAgentHook`
```csharp
bool OnAgentLoading(ref string id);
bool OnInstructionLoaded(ref string instruction);
bool OnFunctionsLoaded(ref string functions);
bool OnSamplesLoaded(ref string samples);
Agent OnAgentLoaded();
```
## Conversation Hook
`IConversationHook`
```csharp
Task OnDialogsLoaded(List<RoleDialogModel> dialogs);
Task BeforeCompletion();
Task OnFunctionExecuting(RoleDialogModel message);
Task OnFunctionExecuted(RoleDialogModel message);
Task AfterCompletion(RoleDialogModel message);
```
### Conversation State Hook
`IConversationHook`
```csharp
Task OnStateLoaded(ConversationState state);
Task OnStateChanged(string name, string preValue, string currentValue);
```

View file

@ -73,14 +73,16 @@ The main documentation for the site is organized into the following sections:
knowledge-base/similarity-search knowledge-base/similarity-search
knowledge-base/build-qa-bot knowledge-base/build-qa-bot
.. _prompting: .. _llm:
.. toctree:: .. toctree::
:maxdepth: 3 :maxdepth: 3
:caption: Prompt Engineering :caption: Prompt Engineering
prompt/intro prompt/prompt
prompt/template prompt/template
llm/function
llm/few-shot-learning
.. _architecture-docs: .. _architecture-docs:

View file

@ -0,0 +1 @@
# Few-Shot Learning

1
docs/llm/function.md Normal file
View file

@ -0,0 +1 @@
# Function

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<VersionPrefix>0.8.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
<PackageIcon>Icon.png</PackageIcon> <PackageIcon>Icon.png</PackageIcon>
</PropertyGroup> </PropertyGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<VersionPrefix>0.8.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
@ -76,7 +76,6 @@
<PackageReference Include="Colorful.Console" Version="1.2.15" /> <PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" /> <PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" />
<PackageReference Include="Fluid.Core" Version="2.4.0" /> <PackageReference Include="Fluid.Core" Version="2.4.0" />
<PackageReference Include="LLamaSharp" Version="0.4.2-preview" />
<PackageReference Include="TensorFlow.Keras" Version="0.11.2" /> <PackageReference Include="TensorFlow.Keras" Version="0.11.2" />
</ItemGroup> </ItemGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<VersionPrefix>0.8.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.8.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.8.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,6 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LLamaSharp" Version="0.4.2-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
</Project>

View file

@ -1,5 +1,9 @@
using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Plugins;
using BotSharp.Plugin.LLamaSharp.Providers;
using BotSharp.Plugin.LLamaSharp.Settings;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BotSharp.Core.Plugins.LLamaSharp; namespace BotSharp.Core.Plugins.LLamaSharp;

View file

@ -1,3 +1,4 @@
using BotSharp.Plugin.LLamaSharp.Settings;
using LLama; using LLama;
using LLama.Common; using LLama.Common;

View file

@ -1,10 +1,16 @@
using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.MLTasks;
using BotSharp.Core.Plugins.LLamaSharp;
using LLama; using LLama;
using LLama.Common; using LLama.Common;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BotSharp.Core.Plugins.LLamaSharp; namespace BotSharp.Plugin.LLamaSharp.Providers;
public class ChatCompletionProvider : IChatCompletion public class ChatCompletionProvider : IChatCompletion
{ {
@ -19,8 +25,8 @@ public class ChatCompletionProvider : IChatCompletion
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<bool> GetChatCompletionsAsync(Agent agent, public async Task<bool> GetChatCompletionsAsync(Agent agent,
List<RoleDialogModel> conversations, List<RoleDialogModel> conversations,
Func<RoleDialogModel, Task> onMessageReceived, Func<RoleDialogModel, Task> onMessageReceived,
Func<RoleDialogModel, Task> onFunctionExecuting) Func<RoleDialogModel, Task> onFunctionExecuting)
{ {

View file

@ -1,8 +1,12 @@
using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.MLTasks;
using BotSharp.Core.Plugins.LLamaSharp;
using LLama; using LLama;
using LLama.Common; using LLama.Common;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
namespace BotSharp.Core.Plugins.LLamaSharp; namespace BotSharp.Plugin.LLamaSharp.Providers;
public class TextCompletionProvider : ITextCompletion public class TextCompletionProvider : ITextCompletion
{ {

View file

@ -1,8 +1,11 @@
using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.MLTasks;
using BotSharp.Plugin.LLamaSharp.Settings;
using LLama; using LLama;
using LLama.Common; using LLama.Common;
using System;
using System.Collections.Generic;
namespace BotSharp.Core.Plugins.LLamaSharp; namespace BotSharp.Plugin.LLamaSharp.Providers;
public class TextEmbeddingProvider : ITextEmbedding public class TextEmbeddingProvider : ITextEmbedding
{ {

View file

@ -1,4 +1,4 @@
namespace BotSharp.Core.Plugins.LLamaSharp; namespace BotSharp.Plugin.LLamaSharp.Settings;
public class LlamaSharpSettings public class LlamaSharpSettings
{ {

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.5.1</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.5.1</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<VersionPrefix>0.6.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -12,7 +12,7 @@
<PackageProjectUrl>https://github.com/Oceania2018/botsharp-channel-weixin</PackageProjectUrl> <PackageProjectUrl>https://github.com/Oceania2018/botsharp-channel-weixin</PackageProjectUrl>
<Copyright>Apache 2.0</Copyright> <Copyright>Apache 2.0</Copyright>
<PackageTags>botsharp, wechat, wexin, chatbot</PackageTags> <PackageTags>botsharp, wechat, wexin, chatbot</PackageTags>
<Version>0.6.0</Version> <VersionPrefix>0.9.0</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View file

@ -39,6 +39,7 @@
<ProjectReference Include="..\Plugins\BotSharp.Plugin.AzureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.AzureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.ChatbotUI\BotSharp.Plugin.ChatbotUI.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.ChatbotUI\BotSharp.Plugin.ChatbotUI.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.HuggingFace\BotSharp.Plugin.HuggingFace.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.HuggingFace\BotSharp.Plugin.HuggingFace.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.LLamaSharp\BotSharp.Plugin.LLamaSharp.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MetaAI\BotSharp.Plugin.MetaAI.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.MetaAI\BotSharp.Plugin.MetaAI.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.PaddleSharp\BotSharp.Plugin.PaddleSharp.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.PaddleSharp\BotSharp.Plugin.PaddleSharp.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.Qdrant\BotSharp.Plugin.Qdrant.csproj" /> <ProjectReference Include="..\Plugins\BotSharp.Plugin.Qdrant\BotSharp.Plugin.Qdrant.csproj" />