Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
feat: csharp add more test (#142)
Browse files Browse the repository at this point in the history
* feat(csharp): add more test

* fix(csharp): add more tests

* docs(csharp): fix i18n missing

* fix(csharp): fix csharp ci code coverage  upload

* fix(csharp): use NJsonSchema replace Newtonsoft

* fix(csharp): upgrade native link

* fix(csharp): fix null check

* fix(csharp): fix csharp function call test

* fix(csharp): fix csharp test

* fix(csharp): fix nativeHandler exception

* docs(readme): remove code coverage in readme

* fix(csharp): fix csproject framework define
  • Loading branch information
moyilong authored Nov 13, 2023
1 parent 3eb9a89 commit 0fb77bc
Show file tree
Hide file tree
Showing 49 changed files with 787 additions and 195 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Flappy is a production-ready Language Language Model (LLM) Application/Agent SDK

## SDK

| | Source | Package | Documentation | CI Status | Coverage |
| - | ------ | ------- | -------------- | --------- | -------- |
| <img src="./assets/languages/nodejs.png" width=24px height=24px> | [**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) | |
| <img src="./assets/languages/java.svg" width=24px height=24px> | [**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)
| <img src="./assets/languages/csharp.svg" width=24px height=24px> | [**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 |
| - | ------ | ------- | -------------- | --------- |
| <img src="./assets/languages/nodejs.png" width=24px height=24px> | [**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) |
| <img src="./assets/languages/java.svg" width=24px height=24px> | [**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)
| <img src="./assets/languages/csharp.svg" width=24px height=24px> | [**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
Expand Down
144 changes: 138 additions & 6 deletions docs/i18n/ja/docusaurus-plugin-content-docs/current/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ implementation("com.pleisto:flappy-java-bindings:0.0.8:${osdetector.classifier}"

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
<PackageReference Include="Pleisto.Flappy" Version="0.0.0.4-alpha" />
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -140,7 +144,16 @@ val llm = ChatGPT(

</TabItem>
<TabItem value="csharp" label="C#" default>
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);
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -434,7 +447,114 @@ suspend fun main(args: Array<String>) {

</TabItem>
<TabItem value="csharp" label="C#" default>
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<ChatGPT>());
var lawAgent = new FlappyAgent(new FlappyAgentConfig
{
LLM = gpt35,
Features = new IFlappyFeature[]
{
new SynthesizedFeature<getMeta_Args,getMeta_Return,FlappyFeatureOption>(new SynthesizedFeatureDefinition<getMeta_Args,getMeta_Return>
{
Name = "getMeta",
Description = "Extract meta data from a lawsuit full text.",
Args = new getMeta_Args(),
ReturnType = new getMeta_Return()
}),
new InvokeFeature<getLatestLawsuits_Args,getMeta_Args,FlappyFeatureOption>(new InvokeFeatureDefinition<getLatestLawsuits_Args, getMeta_Args>
{
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<FlappyAgent>());
}
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<string>();
public override string ToString()
{
return JObject.FromObject(this).ToString();
}
}
public enum Verdict
{
Innocent,
Guilty,
Unknow
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -471,7 +591,11 @@ lawAgent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
var data = lawAgent.ExecutePlan(LAW_EXECUTE_PLAN_PROMPT).GetAwaiter().GetResult();
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -506,7 +630,11 @@ agent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
var result = await agent.CallFeature<TestObject>(callName, LAW_EXECUTE_PLAN_PROMPT);
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -549,6 +677,10 @@ agent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
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();
```

</TabItem>
</Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ implementation("com.pleisto:flappy-java-bindings:0.0.8:${osdetector.classifier}"

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
<PackageReference Include="Pleisto.Flappy" Version="0.0.0.4-alpha" />
```


</TabItem>
</Tabs>

Expand Down Expand Up @@ -142,7 +147,17 @@ val llm = ChatGPT(

</TabItem>
<TabItem value="csharp" label="C#" default>
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);
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -437,7 +452,115 @@ suspend fun main(args: Array<String>) {

</TabItem>
<TabItem value="csharp" label="C#" default>
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<ChatGPT>());
var lawAgent = new FlappyAgent(new FlappyAgentConfig
{
LLM = gpt35,
Features = new IFlappyFeature[]
{
new SynthesizedFeature<getMeta_Args,getMeta_Return,FlappyFeatureOption>(new SynthesizedFeatureDefinition<getMeta_Args,getMeta_Return>
{
Name = "getMeta",
Description = "Extract meta data from a lawsuit full text.",
Args = new getMeta_Args(),
ReturnType = new getMeta_Return()
}),
new InvokeFeature<getLatestLawsuits_Args,getMeta_Args,FlappyFeatureOption>(new InvokeFeatureDefinition<getLatestLawsuits_Args, getMeta_Args>
{
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<FlappyAgent>());
}
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<string>();
public override string ToString()
{
return JObject.FromObject(this).ToString();
}
}
public enum Verdict
{
Innocent,
Guilty,
Unknow
}
```


</TabItem>
</Tabs>

Expand Down Expand Up @@ -474,7 +597,11 @@ lawAgent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
var data = lawAgent.ExecutePlan(LAW_EXECUTE_PLAN_PROMPT).GetAwaiter().GetResult();
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -510,7 +637,11 @@ agent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
Coming soon

```csharp
var result = await agent.CallFeature<TestObject>(callName, LAW_EXECUTE_PLAN_PROMPT);
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -553,6 +684,10 @@ agent.use {

</TabItem>
<TabItem value="csharp" label="C#" default>
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();
```

</TabItem>
</Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1822:将成员标记为 static", Justification = "<挂起>")]
[assembly: SuppressMessage("Performance", "CA1822")]
Loading

0 comments on commit 0fb77bc

Please sign in to comment.