diff --git a/README.md b/README.md
index f7847271..5f4b7c81 100644
--- a/README.md
+++ b/README.md
@@ -23,11 +23,11 @@ Flappy is a production-ready Language Language Model (LLM) Application/Agent SDK
## SDK
-| | Source | Package | Documentation | CI Status | Coverage |
-| - | ------ | ------- | -------------- | --------- | -------- |
-| | [**NodeJS**][NodeJS integration] | [![NPM version](https://img.shields.io/npm/v/%40pleisto/node-flappy/next.svg)](https://npmjs.org/package/@pleisto/node-flappy) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://flappy.pleisto.com) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/nodejs-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/nodejs-ci.yml) | |
-| | [**Java**][Kotlin integration] | [![Maven metadata URL](https://img.shields.io/maven-metadata/v.svg?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fcom%2Fpleisto%2Fflappy%2Fmaven-metadata.xml&color=blue)](https://central.sonatype.com/artifact/com.pleisto/flappy) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://javadoc.io/doc/com.pleisto/flappy) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/kotlin-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/kotlin-ci.yml) | [![codecov](https://codecov.io/gh/pleisto/flappy/graph/badge.svg?token=8C94YY3KBD)](https://codecov.io/gh/pleisto/flappy)
-| | [**C#**][C# integration] | [![NuGet version (Pleisto.Flappy)](https://img.shields.io/nuget/v/Pleisto.Flappy.svg?style=flat-square)](https://www.nuget.org/packages/Pleisto.Flappy/) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://flappy.pleisto.com) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/csharp-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/csharp-ci.yml) | |
+| | Source | Package | Documentation | CI Status |
+| - | ------ | ------- | -------------- | --------- |
+| | [**NodeJS**][NodeJS integration] | [![NPM version](https://img.shields.io/npm/v/%40pleisto/node-flappy/next.svg)](https://npmjs.org/package/@pleisto/node-flappy) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://flappy.pleisto.com) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/nodejs-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/nodejs-ci.yml) |
+| | [**Java**][Kotlin integration] | [![Maven metadata URL](https://img.shields.io/maven-metadata/v.svg?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fcom%2Fpleisto%2Fflappy%2Fmaven-metadata.xml&color=blue)](https://central.sonatype.com/artifact/com.pleisto/flappy) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://javadoc.io/doc/com.pleisto/flappy) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/kotlin-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/kotlin-ci.yml)
+| | [**C#**][C# integration] | [![NuGet version (Pleisto.Flappy)](https://img.shields.io/nuget/v/Pleisto.Flappy.svg?style=flat-square)](https://www.nuget.org/packages/Pleisto.Flappy/) | [![Documentation](https://img.shields.io/badge/documentation-documentation.svg)](https://flappy.pleisto.com) | [![CI](https://img.shields.io/github/actions/workflow/status/pleisto/flappy/csharp-ci.yml.svg)](https://github.com/pleisto/flappy/actions/workflows/csharp-ci.yml) |
[nodejs integration]: ./packages/nodejs/README.md
[kotlin integration]: ./packages/kotlin/README.md
diff --git a/docs/i18n/ja/docusaurus-plugin-content-docs/current/quick-start.mdx b/docs/i18n/ja/docusaurus-plugin-content-docs/current/quick-start.mdx
index 3ad0e37e..827ac814 100644
--- a/docs/i18n/ja/docusaurus-plugin-content-docs/current/quick-start.mdx
+++ b/docs/i18n/ja/docusaurus-plugin-content-docs/current/quick-start.mdx
@@ -79,7 +79,11 @@ implementation("com.pleisto:flappy-java-bindings:0.0.8:${osdetector.classifier}"
- Coming soon
+
+```csharp
+
+```
+
@@ -140,7 +144,16 @@ val llm = ChatGPT(
- Coming soon
+
+```csharp
+ var gpt35 = new ChatGPT(new OpenAIAPI
+ {
+ Auth = new APIAuthentication(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")),
+ ApiUrlFormat = "https://openai.api2d.net/{0}/{1}",
+ ApiVersion = "v1",
+ }, "gpt-3.5-turbo", null, null);
+```
+
@@ -434,7 +447,114 @@ suspend fun main(args: Array) {
- Coming soon
+
+
+```csharp
+ internal class LawCase
+ {
+ public static void Main()
+ {
+ var gpt35 = new ChatGPT(new OpenAIAPI
+ {
+ Auth = new APIAuthentication(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")),
+ ApiUrlFormat = "https://openai.api2d.net/{0}/{1}",
+ ApiVersion = "v1",
+ }, "gpt-3.5-turbo", null, Logger.CreateLogger());
+
+ var lawAgent = new FlappyAgent(new FlappyAgentConfig
+ {
+ LLM = gpt35,
+ Features = new IFlappyFeature[]
+ {
+ new SynthesizedFeature(new SynthesizedFeatureDefinition
+ {
+ Name = "getMeta",
+ Description = "Extract meta data from a lawsuit full text.",
+ Args = new getMeta_Args(),
+ ReturnType = new getMeta_Return()
+ }),
+ new InvokeFeature(new InvokeFeatureDefinition
+ {
+ Name = "getLatestLawsuitsByPlaintiff",
+ Description= "Get the latest lawsuits by plaintiff.",
+ Args = new getLatestLawsuits_Args(),
+ ReturnType = new getMeta_Args(),
+ Resolve = (args) =>
+ {
+ Console.WriteLine($"====================== getLatestLawsuitsByPlaintiff call =========================");
+ Console.WriteLine($"getLatestLawsuitsByPlaintiff called");
+ Console.WriteLine(JObject.FromObject(args).ToString());
+ Console.WriteLine($"====================== getLatestLawsuitsByPlaintiff call =========================");
+ return Task.FromResult(new getMeta_Args
+ {
+ lawsuit =MOCK_LAWSUIT_DATA
+ });
+ }
+ })
+ },
+ }, null, null, Logger.CreateLogger());
+ }
+
+ private const string LAW_EXECUTE_PLAN_PROMPT = "Find the resume of a frontend engineer and return their metadata.";
+
+ private const string MOCK_LAWSUIT_DATA =
+ "As Alex Jones continues telling his Infowars audience about his money problems and pleads for them to buy his products, his own documents show life is not all that bad — his net worth is around $14 million and his personal spending topped $93,000 in July alone, including thousands of dollars on meals and entertainment. The conspiracy theorist and his lawyers file monthly financial reports in his personal bankruptcy case, and the latest one has struck a nerve with the families of victims of Sandy Hook Elementary School shooting. They're still seeking the $1.5 billion they won last year in lawsuits against Jones and his media company for repeatedly calling the 2012 massacre a hoax on his shows. “It is disturbing that Alex Jones continues to spend money on excessive household expenditures and his extravagant lifestyle when that money rightfully belongs to the families he spent years tormenting,” said Christopher Mattei, a Connecticut lawyer for the families. “The families are increasingly concerned and will continue to contest these matters in court.” In an Aug. 29 court filing, lawyers for the families said that if Jones doesn’t reduce his personal expenses to a “reasonable” level, they will ask the bankruptcy judge to bar him from “further waste of estate assets,” appoint a trustee to oversee his spending, or dismiss the bankruptcy case. On his Infowars show Tuesday, Jones said he’s not doing anything wrong.";
+ }
+
+ internal class getLatestLawsuits_Args
+ {
+ public string plantiff { get; set; }
+
+ [Description("For demo purpose. set to False")]
+ public bool arg1 { get; set; }
+
+ [Description("ignore it")]
+ public bool arg2 { get; set; }
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ internal class getMeta_Args
+ {
+ [Description("Lawsuit full text.")]
+ public string lawsuit { get; set; }
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ [JsonObject(ItemRequired = Required.Always)]
+ public class getMeta_Return
+ {
+ [JsonConverter(typeof(StringEnumConverter))]
+ [DefaultValue(Verdict.Unknow)]
+ public Verdict verdict { get; set; } = Verdict.Unknow;
+
+ public string plaintiff { get; set; } = string.Empty;
+
+ public string defendant { get; set; } = string.Empty;
+
+ public string[] judgeOptions { get; set; } = Array.Empty();
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ public enum Verdict
+ {
+ Innocent,
+ Guilty,
+ Unknow
+ }
+```
+
@@ -471,7 +591,11 @@ lawAgent.use {
- Coming soon
+
+```csharp
+var data = lawAgent.ExecutePlan(LAW_EXECUTE_PLAN_PROMPT).GetAwaiter().GetResult();
+```
+
@@ -506,7 +630,11 @@ agent.use {
- Coming soon
+
+```csharp
+var result = await agent.CallFeature(callName, LAW_EXECUTE_PLAN_PROMPT);
+```
+
@@ -549,6 +677,10 @@ agent.use {
- Coming soon
+
+```csharp
+var data = lawAgent.ExecutePlan("There are some rabbits and chickens in a barn. What is the number of chickens if there are 396 legs and 150 heads in the barn?").GetAwaiter().GetResult();
+```
+
diff --git a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/quick-start.mdx b/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/quick-start.mdx
index 730b6b62..a9f6879a 100644
--- a/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/quick-start.mdx
+++ b/docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/quick-start.mdx
@@ -79,7 +79,12 @@ implementation("com.pleisto:flappy-java-bindings:0.0.8:${osdetector.classifier}"
- Coming soon
+
+```csharp
+
+```
+
+
@@ -142,7 +147,17 @@ val llm = ChatGPT(
- Coming soon
+
+
+```csharp
+ var gpt35 = new ChatGPT(new OpenAIAPI
+ {
+ Auth = new APIAuthentication(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")),
+ ApiUrlFormat = "https://openai.api2d.net/{0}/{1}",
+ ApiVersion = "v1",
+ }, "gpt-3.5-turbo", null, null);
+```
+
@@ -437,7 +452,115 @@ suspend fun main(args: Array) {
- Coming soon
+
+
+```csharp
+ internal class LawCase
+ {
+ public static void Main()
+ {
+ var gpt35 = new ChatGPT(new OpenAIAPI
+ {
+ Auth = new APIAuthentication(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")),
+ ApiUrlFormat = "https://openai.api2d.net/{0}/{1}",
+ ApiVersion = "v1",
+ }, "gpt-3.5-turbo", null, Logger.CreateLogger());
+
+ var lawAgent = new FlappyAgent(new FlappyAgentConfig
+ {
+ LLM = gpt35,
+ Features = new IFlappyFeature[]
+ {
+ new SynthesizedFeature(new SynthesizedFeatureDefinition
+ {
+ Name = "getMeta",
+ Description = "Extract meta data from a lawsuit full text.",
+ Args = new getMeta_Args(),
+ ReturnType = new getMeta_Return()
+ }),
+ new InvokeFeature(new InvokeFeatureDefinition
+ {
+ Name = "getLatestLawsuitsByPlaintiff",
+ Description= "Get the latest lawsuits by plaintiff.",
+ Args = new getLatestLawsuits_Args(),
+ ReturnType = new getMeta_Args(),
+ Resolve = (args) =>
+ {
+ Console.WriteLine($"====================== getLatestLawsuitsByPlaintiff call =========================");
+ Console.WriteLine($"getLatestLawsuitsByPlaintiff called");
+ Console.WriteLine(JObject.FromObject(args).ToString());
+ Console.WriteLine($"====================== getLatestLawsuitsByPlaintiff call =========================");
+ return Task.FromResult(new getMeta_Args
+ {
+ lawsuit =MOCK_LAWSUIT_DATA
+ });
+ }
+ })
+ },
+ }, null, null, Logger.CreateLogger());
+ }
+
+ private const string LAW_EXECUTE_PLAN_PROMPT = "Find the resume of a frontend engineer and return their metadata.";
+
+ private const string MOCK_LAWSUIT_DATA =
+ "As Alex Jones continues telling his Infowars audience about his money problems and pleads for them to buy his products, his own documents show life is not all that bad — his net worth is around $14 million and his personal spending topped $93,000 in July alone, including thousands of dollars on meals and entertainment. The conspiracy theorist and his lawyers file monthly financial reports in his personal bankruptcy case, and the latest one has struck a nerve with the families of victims of Sandy Hook Elementary School shooting. They're still seeking the $1.5 billion they won last year in lawsuits against Jones and his media company for repeatedly calling the 2012 massacre a hoax on his shows. “It is disturbing that Alex Jones continues to spend money on excessive household expenditures and his extravagant lifestyle when that money rightfully belongs to the families he spent years tormenting,” said Christopher Mattei, a Connecticut lawyer for the families. “The families are increasingly concerned and will continue to contest these matters in court.” In an Aug. 29 court filing, lawyers for the families said that if Jones doesn’t reduce his personal expenses to a “reasonable” level, they will ask the bankruptcy judge to bar him from “further waste of estate assets,” appoint a trustee to oversee his spending, or dismiss the bankruptcy case. On his Infowars show Tuesday, Jones said he’s not doing anything wrong.";
+ }
+
+ internal class getLatestLawsuits_Args
+ {
+ public string plantiff { get; set; }
+
+ [Description("For demo purpose. set to False")]
+ public bool arg1 { get; set; }
+
+ [Description("ignore it")]
+ public bool arg2 { get; set; }
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ internal class getMeta_Args
+ {
+ [Description("Lawsuit full text.")]
+ public string lawsuit { get; set; }
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ [JsonObject(ItemRequired = Required.Always)]
+ public class getMeta_Return
+ {
+ [JsonConverter(typeof(StringEnumConverter))]
+ [DefaultValue(Verdict.Unknow)]
+ public Verdict verdict { get; set; } = Verdict.Unknow;
+
+ public string plaintiff { get; set; } = string.Empty;
+
+ public string defendant { get; set; } = string.Empty;
+
+ public string[] judgeOptions { get; set; } = Array.Empty();
+
+ public override string ToString()
+ {
+ return JObject.FromObject(this).ToString();
+ }
+ }
+
+ public enum Verdict
+ {
+ Innocent,
+ Guilty,
+ Unknow
+ }
+```
+
+
@@ -474,7 +597,11 @@ lawAgent.use {
- Coming soon
+
+```csharp
+var data = lawAgent.ExecutePlan(LAW_EXECUTE_PLAN_PROMPT).GetAwaiter().GetResult();
+```
+
@@ -510,7 +637,11 @@ agent.use {
- Coming soon
+
+```csharp
+var result = await agent.CallFeature(callName, LAW_EXECUTE_PLAN_PROMPT);
+```
+
@@ -553,6 +684,10 @@ agent.use {
- Coming soon
+
+```csharp
+var data = lawAgent.ExecutePlan("There are some rabbits and chickens in a barn. What is the number of chickens if there are 396 legs and 150 heads in the barn?").GetAwaiter().GetResult();
+```
+
diff --git a/examples/csharp/Pleisto.Flappy.Examples/GlobalSuppressions.cs b/examples/csharp/Pleisto.Flappy.Examples/GlobalSuppressions.cs
index ce9c5cb2..380fa4ba 100644
--- a/examples/csharp/Pleisto.Flappy.Examples/GlobalSuppressions.cs
+++ b/examples/csharp/Pleisto.Flappy.Examples/GlobalSuppressions.cs
@@ -5,4 +5,4 @@
using System.Diagnostics.CodeAnalysis;
-[assembly: SuppressMessage("Performance", "CA1822:将成员标记为 static", Justification = "<挂起>")]
+[assembly: SuppressMessage("Performance", "CA1822")]
diff --git a/examples/csharp/Pleisto.Flappy.Examples/Pleisto.Flappy.Examples.csproj b/examples/csharp/Pleisto.Flappy.Examples/Pleisto.Flappy.Examples.csproj
index 440bd07d..8110eeaa 100644
--- a/examples/csharp/Pleisto.Flappy.Examples/Pleisto.Flappy.Examples.csproj
+++ b/examples/csharp/Pleisto.Flappy.Examples/Pleisto.Flappy.Examples.csproj
@@ -2,6 +2,7 @@
Exe
+ net7.0;net6.0;netcoreapp3.1
diff --git a/examples/csharp/Pleisto.Flappy.Examples/Resume/ResumeCase.cs b/examples/csharp/Pleisto.Flappy.Examples/Resume/ResumeCase.cs
index f0bceb9c..6bcc7378 100644
--- a/examples/csharp/Pleisto.Flappy.Examples/Resume/ResumeCase.cs
+++ b/examples/csharp/Pleisto.Flappy.Examples/Resume/ResumeCase.cs
@@ -54,7 +54,9 @@ public override async Task OnExecuteAsync()
Auth = new APIAuthentication(apiKey: OpenAIApiKey),
ApiUrlFormat = "https://openai.api2d.net/{0}/{1}",
ApiVersion = "v1",
- }, "gpt-3.5-turbo", null, Logger.CreateLogger());
+ }, "gpt-3.5-turbo", null, Logger.CreateLogger())
+ {
+ };
var lawAgent = new FlappyAgent(new FlappyAgentConfig
{
diff --git a/packages/csharp/Directory.Build.props b/packages/csharp/Directory.Build.props
index 474fb8c5..c485af6d 100644
--- a/packages/csharp/Directory.Build.props
+++ b/packages/csharp/Directory.Build.props
@@ -5,7 +5,6 @@
Pleisto.LTD
https://github.com/pleisto/flappy
0.0.0.5
-
@@ -21,7 +20,6 @@
disable
true
IDE1006
- net7.0;net6.0;netcoreapp3.1;netstandard2.1
true
true
diff --git a/packages/csharp/Pleisto.Flappy.Test/Agent.cs b/packages/csharp/Pleisto.Flappy.Test/Agent.cs
index db6d5358..53d26db7 100644
--- a/packages/csharp/Pleisto.Flappy.Test/Agent.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/Agent.cs
@@ -1,7 +1,11 @@
using Newtonsoft.Json.Linq;
using NUnit.Framework;
+using Pleisto.Flappy.Features.CodeInterpreter;
using Pleisto.Flappy.Features.Invoke;
+using Pleisto.Flappy.Features.Syntehesized;
using Pleisto.Flappy.Interfaces;
+using Pleisto.Flappy.Utils;
+using System.Reflection;
namespace Pleisto.Flappy.Tests
{
@@ -16,20 +20,69 @@ public async Task CallFeatureTestAsync()
{
Features = new IFlappyFeature[]
{
- new InvokeFeature(new InvokeFeatureDefinition
+ new InvokeFeature, EasyPayload, FlappyFeatureOption>(new InvokeFeatureDefinition, EasyPayload>
{
Name = callName,
Args = string.Empty,
Description = string.Empty,
ReturnType = string.Empty,
- Resolve = new FlappyAgent.ResolveFeature(i => Task.FromResult(i))
+ Resolve = new FlappyAgent.ResolveFeature, EasyPayload>(i => Task.FromResult(i))
})
}
}, null, null, null);
- var result = await agent.CallFeature(callName, callResult) as string;
+ var result = await agent.CallFeature(callName, new EasyPayload { Payload = callResult }) as EasyPayload;
if (result == null)
Assert.Fail("result is null!");
Assert.That(result, Is.EqualTo(callResult));
}
+
+ [Test]
+ public void AgentFunctionFilterTest()
+ {
+ var agent = new FlappyAgent(new FlappyAgentConfig
+ {
+ Features = new IFlappyFeature[]
+ {
+ new InvokeFeature, EasyPayload, FlappyFeatureOption>(new InvokeFeatureDefinition, EasyPayload>
+ {
+ Name = "test-1",
+ Args = string.Empty,
+ Description = string.Empty,
+ ReturnType = string.Empty,
+ Resolve = new FlappyAgent.ResolveFeature, EasyPayload>(i => Task.FromResult(i))
+ }),
+ new SynthesizedFeature,EasyPayload,FlappyFeatureOption>(new SynthesizedFeatureDefinition, EasyPayload>
+ {
+ Name = "test-2",
+ Args = string.Empty,
+ Description = string.Empty,
+ ReturnType = string.Empty,
+ }),
+ new CodeInterpreterFeature("test"),
+ }
+ }, null, null, null);
+ Assert.Multiple(() =>
+ {
+ Assert.That(agent.InvokeFeatures().Count(), Is.EqualTo(1));
+ Assert.That(agent.SynthesizedFeatures().Count(), Is.EqualTo(1));
+ Assert.That(agent.CodeInterpreterFeatures().Count(), Is.EqualTo(1));
+ });
+ }
+
+ [Test]
+ public void BasicTypeOfFeatureDefinition()
+ {
+ var type = new InvokeFeature, EasyPayload, FlappyFeatureOption>(new InvokeFeatureDefinition, EasyPayload>
+ {
+ Name = "test-1",
+ Args = string.Empty,
+ Description = string.Empty,
+ ReturnType = string.Empty,
+ Resolve = new FlappyAgent.ResolveFeature, EasyPayload>(i => Task.FromResult(i))
+ }) as IFlappyFeature;
+ var gotName = type.GetType().GetInterface(typeof(IInvokeFeature).FullName)?.FullName;
+ Console.WriteLine(gotName);
+ Assert.That(gotName, Is.EqualTo(typeof(IInvokeFeature).FullName));
+ }
}
}
diff --git a/packages/csharp/Pleisto.Flappy.Test/CodeInterpreter.cs b/packages/csharp/Pleisto.Flappy.Test/CodeInterpreter.cs
index c19aeb76..b1c33f0f 100644
--- a/packages/csharp/Pleisto.Flappy.Test/CodeInterpreter.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/CodeInterpreter.cs
@@ -1,7 +1,6 @@
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Pleisto.Flappy.CodeInterpreter;
-using Pleisto.Flappy.Examples.CodeInterpreter;
namespace Pleisto.Flappy.Tests
{
@@ -26,21 +25,13 @@ public void PythonHelloWorldTest()
Assert.That(result.StdOut.Trim(), Is.EqualTo("Hello World"));
}
- ///
- /// Test result of python version
- ///
- [Test]
- public void PythonInspect()
- {
- new NativeCall().OnExecute();
- }
-
///
/// Test of environment
///
[Test]
public void PythonEnvironment()
{
+ const string env = "this_is_env_test_success";
const string pythonEnvironment = @"
import os
@@ -48,10 +39,10 @@ import os
";
var result = NativeHandler.EvalPythonCode(pythonEnvironment, false, new Dictionary
{
- ["testEnv"] = "123123123"
+ ["testEnv"] = env
});
Console.WriteLine(JObject.FromObject(result).ToString());
- Assert.That(result.StdOut.Trim(), Is.EqualTo("123123123"));
+ Assert.That(result.StdOut.Trim(), Is.EqualTo(env));
}
///
diff --git a/packages/csharp/Pleisto.Flappy.Test/Features/CodeInterpreterFeatureTest.cs b/packages/csharp/Pleisto.Flappy.Test/Features/CodeInterpreterFeatureTest.cs
new file mode 100644
index 00000000..65741f42
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy.Test/Features/CodeInterpreterFeatureTest.cs
@@ -0,0 +1,25 @@
+using Pleisto.Flappy.Features.CodeInterpreter;
+using Pleisto.Flappy.Interfaces;
+
+namespace Pleisto.Flappy.Tests.Features
+{
+ ///
+ /// Code Interpreter Feature test
+ ///
+ public class CodeInterpreterFeatureTest :
+ FeatureTestBase<
+ CodeInterpreterFeature,
+ CodeInterpreterFeatureDefinition
+ >
+ {
+ protected override FeatureGenerated CreateFeature()
+ {
+ var ret = new CodeInterpreterFeature("testCodeInterpreter");
+ return new()
+ {
+ Feature = ret,
+ Define = ret.Define as CodeInterpreterFeatureDefinition
+ };
+ }
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy.Test/Features/FeatureTestBase.cs b/packages/csharp/Pleisto.Flappy.Test/Features/FeatureTestBase.cs
new file mode 100644
index 00000000..0e18356e
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy.Test/Features/FeatureTestBase.cs
@@ -0,0 +1,45 @@
+using NUnit.Framework;
+using Pleisto.Flappy.Interfaces;
+
+namespace Pleisto.Flappy.Tests.Features
+{
+ public abstract class FeatureTestBase
+ where TFeature : class, IFlappyFeature
+ where TFeatureDefine : IFlappyFeatureDefinition, new()
+
+ {
+ protected class FeatureGenerated
+ {
+ public TFeature Feature { get; set; }
+ public TFeatureDefine Define { get; set; }
+ }
+
+ protected virtual FeatureGenerated CreateFeature()
+ {
+ var define = new TFeatureDefine()
+ {
+ Name = "Test",
+ Description = "test-description",
+ };
+ return new FeatureGenerated
+ {
+ Feature = Activator.CreateInstance(typeof(TFeature), new object[] { define }) as TFeature,
+ Define = define
+ };
+ }
+
+ ///
+ /// Test map from feature to define
+ ///
+ [Test]
+ public void DefineMapper()
+ {
+ var feature = CreateFeature();
+ Assert.Multiple(() =>
+ {
+ Assert.That(feature.Feature.Name, Is.EqualTo(feature.Define.Name));
+ Assert.That(feature.Define, Is.EqualTo(feature.Feature.Define));
+ });
+ }
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy.Test/Features/InvokeFeatureTest.cs b/packages/csharp/Pleisto.Flappy.Test/Features/InvokeFeatureTest.cs
new file mode 100644
index 00000000..712835c5
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy.Test/Features/InvokeFeatureTest.cs
@@ -0,0 +1,50 @@
+using NUnit.Framework;
+using Pleisto.Flappy.Features.Invoke;
+using Pleisto.Flappy.Interfaces;
+using Pleisto.Flappy.Utils;
+
+namespace Pleisto.Flappy.Tests.Features
+{
+ ///
+ /// Invoke Feature test
+ ///
+ public class InvokeFeatureTest :
+ FeatureTestBase<
+ InvokeFeature, EasyPayload, FlappyFeatureOption>,
+ InvokeFeatureDefinition, EasyPayload>
+ >
+ {
+ ///
+ /// Test invoke feature resolve call
+ ///
+ ///
+ [Test]
+ public async Task InvokeFeatureCallTestAsync()
+ {
+ var feature = CreateFeature();
+ feature.Define.Resolve = new(TestResolve);
+
+ var result = await feature.Feature.Call(null, "testData123");
+ Assert.That(result?.Payload, Is.EqualTo("testData123"));
+ }
+
+ ///
+ /// Test invoke feature system call
+ ///
+ ///
+ [Test]
+ public async Task InvokeFeatureSystemCallTestAsync()
+ {
+ var feature = CreateFeature();
+ feature.Define.Resolve = new(TestResolve);
+
+ var result = await (feature.Feature as IFlappyFeature).SystemCall(null, new EasyPayload { Payload = "testData123" });
+ Assert.That(result, Is.EqualTo(new EasyPayload { Payload = "testData123" }));
+ }
+
+ private static Task> TestResolve(EasyPayload payload)
+ {
+ return Task.FromResult((EasyPayload)payload.Payload);
+ }
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy.Test/Features/SynthesizedFeatureTest.cs b/packages/csharp/Pleisto.Flappy.Test/Features/SynthesizedFeatureTest.cs
new file mode 100644
index 00000000..ddf3023d
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy.Test/Features/SynthesizedFeatureTest.cs
@@ -0,0 +1,19 @@
+using NUnit.Framework;
+using Pleisto.Flappy.Features.Syntehesized;
+using Pleisto.Flappy.Interfaces;
+using Pleisto.Flappy.Utils;
+
+namespace Pleisto.Flappy.Tests.Features
+{
+ ///
+ /// Synthesized Feature test
+ ///
+ public class SynthesizedFeatureTest :
+ FeatureTestBase<
+ SynthesizedFeature, EasyPayload, FlappyFeatureOption>,
+ SynthesizedFeatureDefinition, EasyPayload>
+ >
+ {
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy.Test/GlobalSuppressions.cs b/packages/csharp/Pleisto.Flappy.Test/GlobalSuppressions.cs
new file mode 100644
index 00000000..d1ef30cf
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy.Test/GlobalSuppressions.cs
@@ -0,0 +1,9 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage("Performance", "CA1822")]
+[assembly: SuppressMessage("CodeQuality", "IDE0079")]
diff --git a/packages/csharp/Pleisto.Flappy.Test/LLM/BaichuanTest.cs b/packages/csharp/Pleisto.Flappy.Test/LLM/BaichuanTest.cs
index bf1da18b..123747e6 100644
--- a/packages/csharp/Pleisto.Flappy.Test/LLM/BaichuanTest.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/LLM/BaichuanTest.cs
@@ -3,6 +3,9 @@
namespace Pleisto.Flappy.Tests.LLM
{
+ ///
+ /// Baichuan test
+ ///
public class BaichuanTest : LLMTest
{
private string BaichuanToken => Environment.GetEnvironmentVariable("BAICHUAN_API_KEY");
diff --git a/packages/csharp/Pleisto.Flappy.Test/LLM/ChatGPTTest.cs b/packages/csharp/Pleisto.Flappy.Test/LLM/ChatGPTTest.cs
index 24cf64aa..53678e8c 100644
--- a/packages/csharp/Pleisto.Flappy.Test/LLM/ChatGPTTest.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/LLM/ChatGPTTest.cs
@@ -5,9 +5,12 @@
namespace Pleisto.Flappy.Tests.LLM
{
+ ///
+ /// ChatGPT test
+ ///
public class ChatGPTTest : LLMTest
{
- [SuppressMessage("Performance", "CA1822:将成员标记为 static", Justification = "<挂起>")]
+ [SuppressMessage("Performance", "CA1822")]
private string OpenAIApiKey => Environment.GetEnvironmentVariable("OPENAI_API_KEY");
protected override ChatGPT OnLLMCreate()
diff --git a/packages/csharp/Pleisto.Flappy.Test/LLM/LLMTest.cs b/packages/csharp/Pleisto.Flappy.Test/LLM/LLMTest.cs
index e74cc899..1426ac45 100644
--- a/packages/csharp/Pleisto.Flappy.Test/LLM/LLMTest.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/LLM/LLMTest.cs
@@ -27,7 +27,7 @@ public async Task HelloWorldTestAsync()
var llm = OnLLMCreate();
var result = await llm.ChatComplete(new ChatMLMessage[]
{
- new ChatMLMessage(){ Content = "Hello world", Role = ChatMLMessageRole.User}
+ new ChatMLMessage(){ Content = "Hello world", Role = ChatMLMessageRole.User}
}, null);
if (result.Success == false)
Assert.Fail();
diff --git a/packages/csharp/Pleisto.Flappy.Test/Pleisto.Flappy.Test.csproj b/packages/csharp/Pleisto.Flappy.Test/Pleisto.Flappy.Test.csproj
index 5886fdbb..b975824d 100644
--- a/packages/csharp/Pleisto.Flappy.Test/Pleisto.Flappy.Test.csproj
+++ b/packages/csharp/Pleisto.Flappy.Test/Pleisto.Flappy.Test.csproj
@@ -5,11 +5,9 @@
false
true
Pleisto.Flappy.Tests
-
-
+ net7.0;net6.0;netcoreapp3.1
-
@@ -22,7 +20,6 @@
-
diff --git a/packages/csharp/Pleisto.Flappy.Test/ProgramTest.cs b/packages/csharp/Pleisto.Flappy.Test/ProgramTest.cs
index bd972cc9..dd74f726 100644
--- a/packages/csharp/Pleisto.Flappy.Test/ProgramTest.cs
+++ b/packages/csharp/Pleisto.Flappy.Test/ProgramTest.cs
@@ -1,5 +1,8 @@
using Newtonsoft.Json.Linq;
using NUnit.Framework;
+using Pleisto.Flappy.Features;
+using Pleisto.Flappy.Features.Invoke;
+using Pleisto.Flappy.Interfaces;
using Pleisto.Flappy.Utils;
namespace Pleisto.Flappy.Tests
@@ -21,5 +24,18 @@ public void JsonConvert()
}
}.JsonToString());
}
+
+ ///
+ /// Test Schema output
+ ///
+ [Test]
+ public void FeatureToSchema()
+ {
+ Assert.Pass(FlappyFeatureBase, EasyPayload, FlappyFeatureOption>.BuildJsonSchema(new InvokeFeatureDefinition, EasyPayload>
+ {
+ Name = "test",
+ Description = "validator",
+ }).ToString());
+ }
}
}
diff --git a/packages/csharp/Pleisto.Flappy.Test/Samples.cs b/packages/csharp/Pleisto.Flappy.Test/Samples.cs
deleted file mode 100644
index 3d77ac26..00000000
--- a/packages/csharp/Pleisto.Flappy.Test/Samples.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using NUnit.Framework;
-using Pleisto.Flappy.Examples;
-using Pleisto.Flappy.Examples.CodeInterpreter;
-using Pleisto.Flappy.Examples.Law;
-using Pleisto.Flappy.Examples.Resume;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Pleisto.Flappy.Tests
-{
- ///
- /// ChatGPT Test Case
- ///
- public class Samples
- {
- ///
- /// Disable GPT Test Case on environment set
- ///
- private static bool NoGptTest => Environment.GetEnvironmentVariable("NO_GPT_TEST") == "true";
-
- [SuppressMessage("Performance", "CA1822:将成员标记为 static", Justification = "<挂起>")]
- private async Task TestCaseBase()
- where T : ExampleBase, new()
- {
- if (NoGptTest == false)
- await new T().OnExecuteAsync();
- }
-
- ///
- /// Case test of Law
- ///
- ///
- [Test]
- public async Task LawTestAsync() => await TestCaseBase();
-
- ///
- /// Case test of Law
- ///
- ///
- [Test]
- public async Task ResumeTestAsync()
- => await TestCaseBase();
-
- ///
- /// Case test of Code Interpreter
- ///
- ///
- [Test]
- public async Task CodeInterpreterTaskAsync()
- => await TestCaseBase();
- }
-}
diff --git a/packages/csharp/Pleisto.Flappy/AssemblyInfo.cs b/packages/csharp/Pleisto.Flappy/AssemblyInfo.cs
index 464c567c..65bee5f1 100644
--- a/packages/csharp/Pleisto.Flappy/AssemblyInfo.cs
+++ b/packages/csharp/Pleisto.Flappy/AssemblyInfo.cs
@@ -1,3 +1,5 @@
+global using JsonSchema = NJsonSchema.JsonSchema;
+
using System.Runtime.CompilerServices;
// for test app
diff --git a/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeHandler.cs b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeHandler.cs
index b6ddad09..ca5ba46f 100644
--- a/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeHandler.cs
+++ b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeHandler.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
+using Pleisto.Flappy.Exceptions;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
@@ -9,10 +10,6 @@ namespace Pleisto.Flappy.CodeInterpreter
///
public static class NativeHandler
{
- static NativeHandler()
- {
- }
-
#region Import of native
///
@@ -20,7 +17,7 @@ static NativeHandler()
///
///
[DllImport("flappy_csharp_bindings", EntryPoint = "eval_native_call")]
- [SuppressMessage("Interoperability", "SYSLIB1054:使用 “LibraryImportAttribute” 而不是 “DllImportAttribute” 在编译时生成 P/Invoke 封送代码", Justification = "<挂起>")]
+ [SuppressMessage("Interoperability", "SYSLIB1054")]
private static extern bool EvalNativeCall();
///
@@ -29,7 +26,7 @@ static NativeHandler()
///
///
[DllImport("flappy_csharp_bindings", EntryPoint = "eval_python_code_by_json")]
- [SuppressMessage("Interoperability", "SYSLIB1054:使用 “LibraryImportAttribute” 而不是 “DllImportAttribute” 在编译时生成 P/Invoke 封送代码", Justification = "<挂起>")]
+ [SuppressMessage("Interoperability", "SYSLIB1054")]
private static extern IntPtr EvalPythonCodeResultJson(IntPtr jsonIn);
#endregion Import of native
@@ -68,9 +65,9 @@ internal static void Free(IntPtr ptr)
/// environment
/// cache directory
///
- public static RustStdOutputManaged EvalPythonCode(string code, bool enableNetwork, Dictionary env, string cacheDir = null)
+ public static NativeResult EvalPythonCode(string code, bool enableNetwork, Dictionary env, string cacheDir = null)
{
- var sendTo = JObject.FromObject(new RustStdInputManaged
+ var sendTo = JObject.FromObject(new NativeInput
{
Code = code,
Network = enableNetwork,
@@ -83,8 +80,11 @@ public static RustStdOutputManaged EvalPythonCode(string code, bool enableNetwor
try
{
result = EvalPythonCodeResultJson(sendToPtr);
- var json = JObject.Parse(Marshal.PtrToStringAnsi(result));
- return json.ToObject();
+ var json = JObject.Parse(Marshal.PtrToStringAnsi(result)).ToObject();
+ if (!string.IsNullOrWhiteSpace(json.ExceptionString))
+ throw new CodeInterpreterNativeException(json);
+ else
+ return json;
}
finally
{
diff --git a/packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdInputManaged.cs b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeInput.cs
similarity index 94%
rename from packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdInputManaged.cs
rename to packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeInput.cs
index 54060a2d..c28ba146 100644
--- a/packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdInputManaged.cs
+++ b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeInput.cs
@@ -5,7 +5,7 @@ namespace Pleisto.Flappy.CodeInterpreter
///
/// CodeInterpreter Input Argument
///
- internal sealed class RustStdInputManaged
+ internal sealed class NativeInput
{
///
/// Python Code
diff --git a/packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdOutputManaged.cs b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeResult.cs
similarity index 94%
rename from packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdOutputManaged.cs
rename to packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeResult.cs
index a0f9b6e9..3331b7aa 100644
--- a/packages/csharp/Pleisto.Flappy/CodeInterpreter/RustStdOutputManaged.cs
+++ b/packages/csharp/Pleisto.Flappy/CodeInterpreter/NativeResult.cs
@@ -5,7 +5,9 @@ namespace Pleisto.Flappy.CodeInterpreter
///
/// Managed of Rust Result
///
- public sealed class RustStdOutputManaged
+ public sealed class NativeResult
+
+
{
///
/// Std Error
diff --git a/packages/csharp/Pleisto.Flappy/Exceptions/CodeInterpreterNativeException.cs b/packages/csharp/Pleisto.Flappy/Exceptions/CodeInterpreterNativeException.cs
new file mode 100644
index 00000000..dd884ad1
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Exceptions/CodeInterpreterNativeException.cs
@@ -0,0 +1,29 @@
+using Pleisto.Flappy.CodeInterpreter;
+
+namespace Pleisto.Flappy.Exceptions
+{
+ ///
+ /// CodeInterpreter native call exception
+ ///
+ public class CodeInterpreterNativeException : Exception
+ {
+ internal CodeInterpreterNativeException(NativeResult result) :
+ base($"Exception={result.ExceptionString}{Environment.NewLine}" +
+ $"Output={result.StdOut}{Environment.NewLine}" +
+ $"Error={result.StdErr}{Environment.NewLine}")
+ {
+ StdOut = result.StdOut;
+ StdErr = result.StdErr;
+ }
+
+ ///
+ /// Std Out
+ ///
+ public string StdOut { get; private set; }
+
+ ///
+ /// Std Error
+ ///
+ public string StdErr { get; private set; }
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Exceptions/InvalidJsonWithSchemaValidationException.cs b/packages/csharp/Pleisto.Flappy/Exceptions/InvalidJsonWithSchemaValidationException.cs
index c32b37f2..ab19bcd6 100644
--- a/packages/csharp/Pleisto.Flappy/Exceptions/InvalidJsonWithSchemaValidationException.cs
+++ b/packages/csharp/Pleisto.Flappy/Exceptions/InvalidJsonWithSchemaValidationException.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Schema;
+using NJsonSchema.Validation;
using System.Text;
namespace Pleisto.Flappy.Exceptions
diff --git a/packages/csharp/Pleisto.Flappy/Exceptions/TooMoreRetryException.cs b/packages/csharp/Pleisto.Flappy/Exceptions/TooMoreRetryException.cs
index 11853e06..40007672 100644
--- a/packages/csharp/Pleisto.Flappy/Exceptions/TooMoreRetryException.cs
+++ b/packages/csharp/Pleisto.Flappy/Exceptions/TooMoreRetryException.cs
@@ -8,7 +8,7 @@ public class TooMoreRetryException : Exception
internal TooMoreRetryException(int count, Exception inner)
: base($"retried count={count}", inner)
{
- this.RetryCount = count;
+ RetryCount = count;
}
///
diff --git a/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeature.cs b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeature.cs
index cc7db57f..47689a61 100644
--- a/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeature.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeature.cs
@@ -24,7 +24,7 @@ public CodeInterpreterFeature(string Name, CodeInterpreterOptions options = null
/// Argument of feature
/// Return of feature
/// Options of feature
- public class CodeInterpreterFeature : FlappyFeatureBase, IFlappyFeature
+ public class CodeInterpreterFeature : FlappyFeatureBase, IFlappyFeature,ICodeInterpreterFeature
where TArgs : CodeInterpreterInput
where TReturn : CodeInterpreterOutput, new()
where TOptions : CodeInterpreterOptions
@@ -39,7 +39,7 @@ public CodeInterpreterFeature(string Name, CodeInterpreterOptions options = null
Name = Name,
Description = TemplateRenderer.Render("features.codeInterpreter.description", new Dictionary
{
- ["enabled"] = options?.EnableNetwork ?? false
+ ["#enabled"] = options?.EnableNetwork ?? false
})
})
{
diff --git a/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeatureDefinition.cs b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeatureDefinition.cs
index c2a23318..c8a907e3 100644
--- a/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeatureDefinition.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/CodeInterpreterFeatureDefinition.cs
@@ -7,18 +7,18 @@ namespace Pleisto.Flappy.Features.CodeInterpreter
///
///
///
- public class CodeInterpreterFeatureDefinition : IFlappyFeatureDefinition
+ public class CodeInterpreterFeatureDefinition : IFlappyFeatureDefinition
where TArgs : CodeInterpreterInput
where TReturn : CodeInterpreterOutput
{
///
/// Name of CodeInterpreter
///
- public string Name { get; internal set; }
+ public string Name { get; set; }
///
/// Description of CodeInterpreter
///
- public string Description { get; internal set; }
+ public string Description { get; set; }
}
}
diff --git a/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/ICodeInterpreterFeature.cs b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/ICodeInterpreterFeature.cs
new file mode 100644
index 00000000..be54b066
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Features/CodeInterpreter/ICodeInterpreterFeature.cs
@@ -0,0 +1,12 @@
+using Pleisto.Flappy.Interfaces;
+
+namespace Pleisto.Flappy.Features.CodeInterpreter
+{
+ ///
+ /// CodeInterpreter Feature Mark
+ ///
+ public interface ICodeInterpreterFeature : IFlappyFeature
+ {
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Features/FlappyFeatureBase.cs b/packages/csharp/Pleisto.Flappy/Features/FlappyFeatureBase.cs
index d1d37a73..4ce45d22 100644
--- a/packages/csharp/Pleisto.Flappy/Features/FlappyFeatureBase.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/FlappyFeatureBase.cs
@@ -1,7 +1,5 @@
using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Schema.Generation;
using Pleisto.Flappy.Interfaces;
-using Pleisto.Flappy.Utils;
namespace Pleisto.Flappy.Features
{
@@ -19,7 +17,7 @@ public abstract class FlappyFeatureBase : IFlappyFeatu
///
/// Feature definition
///
- public IFlappyFeatureDefinition Define;
+ public IFlappyFeatureDefinition Define { get; private set; }
///
/// Feature options
@@ -40,15 +38,14 @@ public abstract class FlappyFeatureBase : IFlappyFeatu
/// Create Flappy Fature Base
///
/// Feature Definition
- public FlappyFeatureBase(IFlappyFeatureDefinition define)
+ public FlappyFeatureBase(IFlappyFeatureDefinition define)
{
Define = define;
CallingSchema = BuildJsonSchema(define);
}
- private static JObject BuildJsonSchema(IFlappyFeatureDefinition define)
+ internal static JObject BuildJsonSchema(IFlappyFeatureDefinition define)
{
- var schemaGenerator = new JSchemaGenerator();
return new JObject
{
["name"] = define.Name,
@@ -58,8 +55,8 @@ private static JObject BuildJsonSchema(IFlappyFeatureDefinition
["type"] = "object",
["properties"] = new JObject
{
- ["args"] = JObject.FromObject(schemaGenerator.Generate(typeof(TArgs))),
- ["returnType"] = JObject.FromObject(schemaGenerator.Generate(typeof(TReturn)))
+ ["args"] = JObject.FromObject(JsonSchema.FromType()),
+ ["returnType"] = JObject.FromObject(JsonSchema.FromType())
}
}
};
diff --git a/packages/csharp/Pleisto.Flappy/Features/Invoke/IInvokeFeature.cs b/packages/csharp/Pleisto.Flappy/Features/Invoke/IInvokeFeature.cs
new file mode 100644
index 00000000..497649ea
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Features/Invoke/IInvokeFeature.cs
@@ -0,0 +1,12 @@
+using Pleisto.Flappy.Interfaces;
+
+namespace Pleisto.Flappy.Features.Invoke
+{
+ ///
+ /// InvokeFeature Mark
+ ///
+ public interface IInvokeFeature : IFlappyFeature
+ {
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeature.cs b/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeature.cs
index 13a40b05..349f656f 100644
--- a/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeature.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeature.cs
@@ -8,7 +8,7 @@ namespace Pleisto.Flappy.Features.Invoke
/// Argument of feature
/// Return of feature
/// Options of feature
- public class InvokeFeature : FlappyFeatureBase, IFlappyFeature
+ public class InvokeFeature : FlappyFeatureBase, IFlappyFeature,IInvokeFeature
where TArgs : class
where TReturn : class
where TOptions : FlappyFeatureOption
@@ -24,9 +24,9 @@ public InvokeFeature(InvokeFeatureDefinition define) : base(defi
///
/// Invoke function call
///
- ///
- ///
- ///
+ /// FlappyAgent Caller
+ /// Call args
+ /// Execution result
public override async Task Call(FlappyAgent agent, TArgs args)
{
return await (Define as InvokeFeatureDefinition).Resolve(args);
diff --git a/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeatureDefinition.cs b/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeatureDefinition.cs
index 9e678fc0..c1efb45a 100644
--- a/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeatureDefinition.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/Invoke/InvokeFeatureDefinition.cs
@@ -8,7 +8,7 @@ namespace Pleisto.Flappy.Features.Invoke
///
/// Argument of feature
/// Return of feature
- public class InvokeFeatureDefinition : FeaturesDefinitionBase, IFlappyFeatureDefinition
+ public class InvokeFeatureDefinition : FeaturesDefinitionBase, IFlappyFeatureDefinition
where TArgs : class
where TReturn : class
{
diff --git a/packages/csharp/Pleisto.Flappy/Features/Synthesized/ISynthesizedFeature.cs b/packages/csharp/Pleisto.Flappy/Features/Synthesized/ISynthesizedFeature.cs
new file mode 100644
index 00000000..3a973e49
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Features/Synthesized/ISynthesizedFeature.cs
@@ -0,0 +1,12 @@
+using Pleisto.Flappy.Interfaces;
+
+namespace Pleisto.Flappy.Features.Syntehesized
+{
+ ///
+ /// SynthesizedFeature mark
+ ///
+ public interface ISynthesizedFeature : IFlappyFeature
+ {
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeature.cs b/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeature.cs
index 52a53c26..76453b89 100644
--- a/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeature.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeature.cs
@@ -6,13 +6,14 @@
namespace Pleisto.Flappy.Features.Syntehesized
{
+
///
/// Synthesized Feature
///
/// Argument of feature
/// Return of feature
/// Options of feature
- public class SynthesizedFeature : FlappyFeatureBase, IFlappyFeature
+ public class SynthesizedFeature : FlappyFeatureBase, IFlappyFeature , ISynthesizedFeature
where TArgs : class
where TReturn : class
where TOptions : FlappyFeatureOption
@@ -26,9 +27,8 @@ public class SynthesizedFeature : FlappyFeatureBase Call(FlappyAgent agent, TArgs args)
{
var describe = Define.Description;
- var schema = FlappyAgent.GetSchemaGenerator();
- var returnTypeSchema = schema.Generate(typeof(TReturn)); //extractSchema(callingSchema, "returnType");
- var argsSchema = schema.Generate(typeof(TArgs)); ;
+ var returnTypeSchema = JsonSchema.FromType();
+ var argsSchema = JsonSchema.FromType();
var prompt = JObject.FromObject(args); //(args as object) is string ? args as string : JObject.FromObject(args).ToString();
var originalRequestMessage = new ChatMLMessage[]{
new ChatMLMessage
diff --git a/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeatureDefinition.cs b/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeatureDefinition.cs
index 67bde7d4..580d0be0 100644
--- a/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeatureDefinition.cs
+++ b/packages/csharp/Pleisto.Flappy/Features/Synthesized/SynthesizedFeatureDefinition.cs
@@ -8,7 +8,7 @@ namespace Pleisto.Flappy.Features.Syntehesized
///
///
///
- public class SynthesizedFeatureDefinition : InvokeFeatureDefinition, IFlappyFeatureDefinition
+ public class SynthesizedFeatureDefinition : InvokeFeatureDefinition, IFlappyFeatureDefinition
where TArgs : class
where TReturn : class
{
diff --git a/packages/csharp/Pleisto.Flappy/FlappyAgent.Constants.cs b/packages/csharp/Pleisto.Flappy/FlappyAgent.Constants.cs
index fba68e38..b857bacc 100644
--- a/packages/csharp/Pleisto.Flappy/FlappyAgent.Constants.cs
+++ b/packages/csharp/Pleisto.Flappy/FlappyAgent.Constants.cs
@@ -1,5 +1,3 @@
-using Newtonsoft.Json.Schema.Generation;
-
namespace Pleisto.Flappy
{
public partial class FlappyAgent
@@ -19,16 +17,5 @@ public partial class FlappyAgent
public delegate Task ResolveFeature(TArgs args)
where TArgs : class
where TReturn : class;
-
- ///
- /// Get Schema Generator
- ///
- ///
- internal static JSchemaGenerator GetSchemaGenerator()
- {
- var ret = new JSchemaGenerator();
- ret.GenerationProviders.Add(new StringEnumGenerationProvider());
- return ret;
- }
}
}
diff --git a/packages/csharp/Pleisto.Flappy/FlappyAgent.cs b/packages/csharp/Pleisto.Flappy/FlappyAgent.cs
index e0d38b74..15e893c7 100644
--- a/packages/csharp/Pleisto.Flappy/FlappyAgent.cs
+++ b/packages/csharp/Pleisto.Flappy/FlappyAgent.cs
@@ -2,6 +2,7 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Pleisto.Flappy.Exceptions;
+using Pleisto.Flappy.Features.CodeInterpreter;
using Pleisto.Flappy.Features.Invoke;
using Pleisto.Flappy.Features.Syntehesized;
using Pleisto.Flappy.Interfaces;
@@ -9,6 +10,7 @@
using Pleisto.Flappy.LLM.Interfaces;
using Pleisto.Flappy.Utils;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
namespace Pleisto.Flappy
{
@@ -55,9 +57,9 @@ public partial class FlappyAgent
///
/// Logger of FlappyAgent
///
- public FlappyAgent(FlappyAgentConfig config, ILLMBase llm, ILLMBase llmPlaner, ILogger logger)
+ public FlappyAgent(FlappyAgentConfig config,[AllowNull] ILLMBase llm, [AllowNull] ILLMBase llmPlaner,[AllowNull] ILogger logger)
{
- this.config = config;
+ this.config = config ?? throw new ArgumentNullException(nameof(config));
if ((config.Features?.Length ?? 0) <= 0)
throw new NullReferenceException($"{nameof(Features)} not be null");
this.llm = llm ?? config.LLM;
@@ -73,6 +75,7 @@ public FlappyAgent(FlappyAgentConfig config, ILLMBase llm, ILLMBase llmPlaner, I
public IEnumerable FeatureDefinitions() => from i in config.Features
select i;
+
///
/// Find feature by name.
///
@@ -82,23 +85,34 @@ public IFlappyFeature FindFeature(string name) => (from i in config.Features
where i.Name.Equals(name?.Trim(), StringComparison.OrdinalIgnoreCase)
select i).FirstOrDefault();
+ ///
+ /// Find features with feature type marker
+ ///
+ ///
+ ///
+ private IEnumerable FeatureDefinitions()
+ where T : IFlappyFeature
+ => from i in config.Features
+ where i.GetType().GetInterface(typeof(T).FullName) != null
+ select i;
+
///
/// List all synthesized features.
///
///
- public IEnumerable SynthesizedFeatures() => from i in config.Features
- let type = i.GetType()
- where type.BaseType == typeof(SynthesizedFeature<,,>)
- select i;
+ public IEnumerable SynthesizedFeatures() => FeatureDefinitions();
///
/// List all invoke features.
///
///
- public IEnumerable InvokeFeatures() => from i in config.Features
- let type = i.GetType()
- where type.BaseType == typeof(InvokeFeature<,,>)
- select i;
+ public IEnumerable InvokeFeatures() => FeatureDefinitions();
+
+ ///
+ /// List all codeinterpreter features.
+ ///
+ ///
+ public IEnumerable CodeInterpreterFeatures() => FeatureDefinitions();
///
/// Call a feature by name.
@@ -110,7 +124,6 @@ public IEnumerable InvokeFeatures() => from i in config.Features
public async Task
string Name { get; }
+
+ ///
+ /// Feature definition
+ ///
+ IFlappyFeatureDefinition Define { get; }
+
///
/// System convert json to argument
///
diff --git a/packages/csharp/Pleisto.Flappy/Interfaces/IFlappyFeatureDefinition.cs b/packages/csharp/Pleisto.Flappy/Interfaces/IFlappyFeatureDefinition.cs
index d859851e..5a43ff9e 100644
--- a/packages/csharp/Pleisto.Flappy/Interfaces/IFlappyFeatureDefinition.cs
+++ b/packages/csharp/Pleisto.Flappy/Interfaces/IFlappyFeatureDefinition.cs
@@ -3,20 +3,16 @@ namespace Pleisto.Flappy.Interfaces
///
/// Flappy Feature Definition
///
- /// Argument of Feature Call
- /// Function Return
- public interface IFlappyFeatureDefinition
- where TArgs : class
- where TReturn : class
+ public interface IFlappyFeatureDefinition
{
///
/// Name of feature
///
- public string Name { get; }
+ public string Name { get; set; }
///
/// Description of feature
///
- public string Description { get; }
+ public string Description { get; set; }
}
}
diff --git a/packages/csharp/Pleisto.Flappy/LLM/ChatGPT.cs b/packages/csharp/Pleisto.Flappy/LLM/ChatGPT.cs
index ea0d25ec..0fed9c84 100644
--- a/packages/csharp/Pleisto.Flappy/LLM/ChatGPT.cs
+++ b/packages/csharp/Pleisto.Flappy/LLM/ChatGPT.cs
@@ -74,6 +74,7 @@ public virtual async Task ChatComplete(ChatMLMessage[] message,
//MaxTokens = (config?.maxTokens ?? maxTokens),
Temperature = config?.Temperature,
TopP = config?.Top_P,
+
});
logger?.LogDebug("chatGpt: {}", resp.Choices[0].Message.Content);
diff --git a/packages/csharp/Pleisto.Flappy/Pleisto.Flappy.csproj b/packages/csharp/Pleisto.Flappy/Pleisto.Flappy.csproj
index 527b5890..14324836 100644
--- a/packages/csharp/Pleisto.Flappy/Pleisto.Flappy.csproj
+++ b/packages/csharp/Pleisto.Flappy/Pleisto.Flappy.csproj
@@ -2,6 +2,7 @@
Pleisto.Flappy
+ net7.0;net6.0;netcoreapp3.1;netstandard2.1
true
true
true
@@ -11,7 +12,6 @@
true
true
agent;transfromers;llama;llm;generative-ai;chatgpt;rewoo
-
@@ -29,9 +29,10 @@
-
+
+
diff --git a/packages/csharp/Pleisto.Flappy/Utils/EasyPayload.cs b/packages/csharp/Pleisto.Flappy/Utils/EasyPayload.cs
new file mode 100644
index 00000000..944c6de1
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Utils/EasyPayload.cs
@@ -0,0 +1,56 @@
+namespace Pleisto.Flappy.Utils
+{
+ ///
+ /// Generic payload type packer
+ ///
+ /// call reference
+ public class EasyPayload : IEquatable>, IEquatable
+ {
+ ///
+ /// Payload
+ ///
+ public T Payload { get; set; }
+
+ ///
+ /// Equals
+ ///
+ ///
+ ///
+ public bool Equals(T other)
+ {
+ return Payload.Equals(other);
+ }
+
+ ///
+ /// Equals
+ ///
+ ///
+ ///
+ public bool Equals(EasyPayload other)
+ {
+ return Payload.Equals((T)other);
+ }
+
+ ///
+ /// Fast convert to payload
+ ///
+ ///
+ public static implicit operator EasyPayload(T payload)
+ {
+ return new EasyPayload { Payload = payload };
+ }
+
+ ///
+ /// Fast convert from payload
+ ///
+ ///
+ public static implicit operator T(EasyPayload payload)
+ {
+ if (payload == null)
+ return default;
+ else
+ return payload.Payload;
+ }
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Utils/JsonExtensions.cs b/packages/csharp/Pleisto.Flappy/Utils/JsonExtensions.cs
index 2fd9a162..d7ced83e 100644
--- a/packages/csharp/Pleisto.Flappy/Utils/JsonExtensions.cs
+++ b/packages/csharp/Pleisto.Flappy/Utils/JsonExtensions.cs
@@ -63,5 +63,7 @@ public static JObject ObjectToJson(this object obj)
{
//NullValueHandling = NullValueHandling.Ignore,
};
+
+
}
}
diff --git a/packages/csharp/Pleisto.Flappy/Utils/SystemJson.cs b/packages/csharp/Pleisto.Flappy/Utils/SystemJson.cs
new file mode 100644
index 00000000..2634186a
--- /dev/null
+++ b/packages/csharp/Pleisto.Flappy/Utils/SystemJson.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Pleisto.Flappy.Utils
+{
+ ///
+ /// Extension of Json
+ ///
+ internal static class SystemJson
+ {
+
+
+ }
+}
diff --git a/packages/csharp/Pleisto.Flappy/Utils/Templates.cs b/packages/csharp/Pleisto.Flappy/Utils/Templates.cs
index a12dc051..f28ad608 100644
--- a/packages/csharp/Pleisto.Flappy/Utils/Templates.cs
+++ b/packages/csharp/Pleisto.Flappy/Utils/Templates.cs
@@ -1,10 +1,14 @@
using Mustache;
+using Stubble.Core.Builders;
using System.Reflection;
namespace Pleisto.Flappy.Utils
{
internal static class TemplateRenderer
{
+ ///
+ /// Template lists
+ ///
public static IEnumerable Templates
=> from i in CurrentAssembly.GetManifestResourceNames()
where i.EndsWith(".mustache")
@@ -46,12 +50,18 @@ public static string GetTemplate(string name)
/// e.g features.synthesized.systemMessage.mustache or features.synthesized.systemMessage
///
/// render argument
- ///
+ /// Rendered string
public static string Render(string name, Dictionary argument)
{
- FormatCompiler compiler = new FormatCompiler();
- Generator generator = compiler.Compile(GetTemplate(name));
- return generator.Render(argument);
+ try
+ {
+ var builder = new StubbleBuilder().Build();
+ return builder.Render(GetTemplate(name), argument);
+ }
+ catch (Exception ex)
+ {
+ throw new InvalidDataException($"unable to render template:{name}", ex);
+ }
}
}
}