Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:lindexi/lindexi_gd into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Oct 23, 2023
2 parents 01bea74 + 9ee6dbf commit 6cda6b4
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Imageshack
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta2" />
</ItemGroup>

</Project>
100 changes: 100 additions & 0 deletions SemanticKernelSamples/Example12_SequentialPlanner/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planners;

using System.Numerics;
using Microsoft.SemanticKernel.AI;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.Reliability.Basic;
using Microsoft.SemanticKernel.TemplateEngine;

var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
});

// 这里的演示代码需要用到 AzureAI 的支持,需要提前申请好,申请地址:https://aka.ms/oai/access

var endpoint = "https://lindexi.openai.azure.com/"; // 请换成你的地址
var apiKey = Environment.GetEnvironmentVariable("AzureAIKey"); // 请换成你的密钥

if (string.IsNullOrEmpty(apiKey))
{
throw new ArgumentException($"请设置为你的密钥");
}

IKernel kernel = new KernelBuilder()
.WithLoggerFactory(loggerFactory)
.WithAzureChatCompletionService("GPT4", endpoint, apiKey)
// 当然,这里也可以支持 OpenAI 的服务。或者是其他第三方的服务
//.WithOpenAIChatCompletionService()
.WithRetryBasic(new BasicRetryConfig()
{
MaxRetryCount = 1000,
MinRetryDelay = TimeSpan.FromSeconds(1),
})
.Build();
kernel.RegisterSemanticFunction("WriterPlugin", "ShortPoem", new PromptTemplateConfig()
{
Description = "Turn a scenario into a short and entertaining poem.",
Input = new PromptTemplateConfig.InputConfig()
{
Parameters = new List<PromptTemplateConfig.InputParameter>()
{
new PromptTemplateConfig.InputParameter()
{
Name = "input",
Description = "The scenario to turn into a poem.",
}
}
}
}, new PromptTemplate(
@"Generate a short funny poem or limerick to explain the given event. Be creative and be funny. Let your imagination run wild.
Event:{{$input}}
", new PromptTemplateConfig()
{
}, kernel));

kernel.CreateSemanticFunction(@"Translate the input below into {{$language}}
MAKE SURE YOU ONLY USE {{$language}}.
{{$input}}
Translation:
",new PromptTemplateConfig()
{
Input = new PromptTemplateConfig.InputConfig()
{
Parameters = new List<PromptTemplateConfig.InputParameter>()
{
new PromptTemplateConfig.InputParameter()
{
Name = "input",
},
new PromptTemplateConfig.InputParameter()
{
Name = "language",
Description = "The language which will translate to",
}
}
},
Description = "Translate the input into a language of your choice",

}, functionName: "Translate", pluginName: "WriterPlugin");

var planner = new SequentialPlanner(kernel, new SequentialPlannerConfig()
{
});

var plan = await planner.CreatePlanAsync("Write a poem about John Doe, then translate it into Chinese.");

var list = plan.Steps;

var planString = plan.ToPlanString();

var result = await kernel.RunAsync(plan);

Console.Read();
8 changes: 7 additions & 1 deletion SemanticKernelSamples/SemanticKernelSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example02_Pipeline", "Examp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example03_Variables", "Example03_Variables\Example03_Variables.csproj", "{72567B18-47FA-406E-B97E-B9CE2D6A6B6C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example05_InlineFunctionDefinition", "Example05_InlineFunctionDefinition\Example05_InlineFunctionDefinition.csproj", "{B2A54D33-F0C5-4C3F-8B4C-B5D4637592CC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example05_InlineFunctionDefinition", "Example05_InlineFunctionDefinition\Example05_InlineFunctionDefinition.csproj", "{B2A54D33-F0C5-4C3F-8B4C-B5D4637592CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example12_SequentialPlanner", "Example12_SequentialPlanner\Example12_SequentialPlanner.csproj", "{19E0660F-F659-4AA0-9163-B7204CA63647}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,6 +35,10 @@ Global
{B2A54D33-F0C5-4C3F-8B4C-B5D4637592CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2A54D33-F0C5-4C3F-8B4C-B5D4637592CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2A54D33-F0C5-4C3F-8B4C-B5D4637592CC}.Release|Any CPU.Build.0 = Release|Any CPU
{19E0660F-F659-4AA0-9163-B7204CA63647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19E0660F-F659-4AA0-9163-B7204CA63647}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19E0660F-F659-4AA0-9163-B7204CA63647}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19E0660F-F659-4AA0-9163-B7204CA63647}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
foreach (var directory in Directory.GetDirectories(s))
{
var directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.CreationTime > DateTime.Now.AddDays(-2))
if (directoryInfo.CreationTime > DateTime.Now.AddDays(-3))
{
var folder = new DirectoryInfo(Path.Join(t, directoryInfo.Name));

Expand Down

0 comments on commit 6cda6b4

Please sign in to comment.