diff --git a/featbit/evaluate/README.md b/featbit/evaluate/README.md new file mode 100644 index 0000000..cca0c57 --- /dev/null +++ b/featbit/evaluate/README.md @@ -0,0 +1,13 @@ +With prompt, you just need to give it a sentence in Devlake's input: + +for example: + +``` +generate ff code with key "game-runner" and return "true" +``` + +or + +``` +key "difficulty", return value "hard" +``` diff --git a/featbit/evaluate/command.yml b/featbit/evaluate/command.yml new file mode 100644 index 0000000..20f5ba2 --- /dev/null +++ b/featbit/evaluate/command.yml @@ -0,0 +1 @@ +description: Generate C# code using FeatBit to evaluate feature flags. \ No newline at end of file diff --git a/featbit/evaluate/prompt.txt b/featbit/evaluate/prompt.txt new file mode 100644 index 0000000..50aa4d2 --- /dev/null +++ b/featbit/evaluate/prompt.txt @@ -0,0 +1,177 @@ +This is FeatBit's .NET sdk tutorial. FeatBit is a feature flag service. + +The following code demonstrates basic usage of FeatBit.ServerSdk. + +```cs +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Model; +using FeatBit.Sdk.Server.Options; + +// setup SDK options +var options = new FbOptionsBuilder("") + .Event(new Uri("")) + .Steaming(new Uri("")) + .Build(); + +// Creates a new client instance that connects to FeatBit with the custom option. +var client = new FbClient(options); +if (!client.Initialized) +{ + Console.WriteLine("FbClient failed to initialize. All Variation calls will use fallback value."); +} +else +{ + Console.WriteLine("FbClient successfully initialized!"); +} + +// flag to be evaluated +const string flagKey = "game-runner"; + +// create a user +var user = FbUser.Builder("anonymous").Build(); + +// evaluate a boolean flag for a given user +var boolVariation = client.BoolVariation(flagKey, user, defaultValue: false); +Console.WriteLine($"flag '{flagKey}' returns {boolVariation} for user {user.Key}"); + +// evaluate a boolean flag for a given user with evaluation detail +var boolVariationDetail = client.BoolVariationDetail(flagKey, user, defaultValue: false); +Console.WriteLine( + $"flag '{flagKey}' returns {boolVariationDetail.Value} for user {user.Key}. " + + $"Reason Kind: {boolVariationDetail.Kind}, Reason Description: {boolVariationDetail.Reason}" +); + +// close the client to ensure that all insights are sent out before the app exits +await client.CloseAsync(); +``` + +The `FbClient` is the heart of the SDK which providing access to FeatBit server. + +#### FbClient Using Default Options + +```csharp +using FeatBit.Sdk.Server; + +// Creates a new client instance that connects to FeatBit with the default option. +var client = new FbClient(""); +``` + +#### FbClient Using Custom Options + +```csharp +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Options; +using Microsoft.Extensions.Logging; + +var consoleLoggerFactory = LoggerFactory.Create(x => x.AddConsole()); + +var options = new FbOptionsBuilder("") + .Steaming(new Uri("ws://localhost:5100")) + .Event(new Uri("http://localhost:5100")) + .StartWaitTime(TimeSpan.FromSeconds(3)) + .LoggerFactory(consoleLoggerFactory) + .Build(); + +// Creates a new client instance that connects to FeatBit with the custom option. +var client = new FbClient(options); +``` + +#### Dependency Injection + +We can register the FeatBit services using standard conventions. + +```csharp +using FeatBit.Sdk.Server.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllers(); + +// add FeatBit service +builder.Services.AddFeatBit(options => +{ + options.EnvSecret = ""; + options.StartWaitTime = TimeSpan.FromSeconds(3); +}); + +var app = builder.Build(); +app.Run(); +``` + +Then the `IFbClient` interface can be obtained through dependency injection. + +```csharp +public class HomeController : ControllerBase +{ + private readonly IFbClient _fbClient; + + public HomeController(IFbClient fbClient) + { + _fbClient = fbClient; + } +} +``` + +### FbUser + +FbUser defines the attributes of a user for whom you are evaluating feature flags. FbUser has two built-in +attributes: `key` and `name`. The only mandatory attribute of a FbUser is the key, which must uniquely identify each +user. + +Besides these built-in properties, you can define any additional attributes associated with the user +using `Custom(string key, string value)` method on `IFbUserBuilder`. Both built-in attributes and custom attributes can +be referenced in targeting rules, and are included in analytics data. + +There is only one method for building FbUser. + +```csharp +var bob = FbUser.Builder("a-unique-key-of-user") + .Name("bob") + .Custom("age", "15") + .Custom("country", "FR") + .Build(); +``` + +### Evaluating flags + +By using the feature flag data it has already received, the SDK **locally calculates** the value of a feature flag for a +given user. + +There is a `Variation` method that returns a flag value, and a `VariationDetail` method that returns an object +describing how the value was determined for each type. + +- BoolVariation/BoolVariationDetail +- StringVariation/StringVariationDetail +- DoubleVariation/DoubleVariationDetail +- FloatVariation/FloatVariationDetail +- IntVariation/IntVariationDetail +- JsonVariation/JsonVariationDetail (in consideration) + +Variation calls take the feature flag key, a FbUser, and a default value. If any error makes it impossible to +evaluate the flag (for instance, the feature flag key does not match any existing flag), default value is returned. + +```csharp +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Model; + +// Creates a new client instance that connects to FeatBit with the default option. +var client = new FbClient(""); + +// The flag key to be evaluated +const string flagKey = "game-runner"; + +// The user +var user = FbUser.Builder("anonymous").Build(); + +// Evaluate a boolean flag for a given user +var boolVariation = client.BoolVariation(flagKey, user, defaultValue: false); +Console.WriteLine($"flag '{flagKey}' returns {boolVariation} for user {user.Key}"); + +// evaluate a boolean flag for a given user with evaluation detail +var boolVariationDetail = client.BoolVariationDetail(flagKey, user, defaultValue: false); +Console.WriteLine( + $"flag '{flagKey}' returns {boolVariationDetail.Value} for user {user.Key}. " + + $"Reason Kind: {boolVariationDetail.Kind}, Reason Description: {boolVariationDetail.Reason}" +); +``` + +Please help me to init my featbit sdk in asp.net app \ No newline at end of file diff --git a/featbit/init/command.yml b/featbit/init/command.yml new file mode 100644 index 0000000..a6cd463 --- /dev/null +++ b/featbit/init/command.yml @@ -0,0 +1 @@ +description: Initialize and use the FeatBit SDK in a C# application. \ No newline at end of file diff --git a/featbit/init/prompt.txt b/featbit/init/prompt.txt new file mode 100644 index 0000000..50aa4d2 --- /dev/null +++ b/featbit/init/prompt.txt @@ -0,0 +1,177 @@ +This is FeatBit's .NET sdk tutorial. FeatBit is a feature flag service. + +The following code demonstrates basic usage of FeatBit.ServerSdk. + +```cs +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Model; +using FeatBit.Sdk.Server.Options; + +// setup SDK options +var options = new FbOptionsBuilder("") + .Event(new Uri("")) + .Steaming(new Uri("")) + .Build(); + +// Creates a new client instance that connects to FeatBit with the custom option. +var client = new FbClient(options); +if (!client.Initialized) +{ + Console.WriteLine("FbClient failed to initialize. All Variation calls will use fallback value."); +} +else +{ + Console.WriteLine("FbClient successfully initialized!"); +} + +// flag to be evaluated +const string flagKey = "game-runner"; + +// create a user +var user = FbUser.Builder("anonymous").Build(); + +// evaluate a boolean flag for a given user +var boolVariation = client.BoolVariation(flagKey, user, defaultValue: false); +Console.WriteLine($"flag '{flagKey}' returns {boolVariation} for user {user.Key}"); + +// evaluate a boolean flag for a given user with evaluation detail +var boolVariationDetail = client.BoolVariationDetail(flagKey, user, defaultValue: false); +Console.WriteLine( + $"flag '{flagKey}' returns {boolVariationDetail.Value} for user {user.Key}. " + + $"Reason Kind: {boolVariationDetail.Kind}, Reason Description: {boolVariationDetail.Reason}" +); + +// close the client to ensure that all insights are sent out before the app exits +await client.CloseAsync(); +``` + +The `FbClient` is the heart of the SDK which providing access to FeatBit server. + +#### FbClient Using Default Options + +```csharp +using FeatBit.Sdk.Server; + +// Creates a new client instance that connects to FeatBit with the default option. +var client = new FbClient(""); +``` + +#### FbClient Using Custom Options + +```csharp +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Options; +using Microsoft.Extensions.Logging; + +var consoleLoggerFactory = LoggerFactory.Create(x => x.AddConsole()); + +var options = new FbOptionsBuilder("") + .Steaming(new Uri("ws://localhost:5100")) + .Event(new Uri("http://localhost:5100")) + .StartWaitTime(TimeSpan.FromSeconds(3)) + .LoggerFactory(consoleLoggerFactory) + .Build(); + +// Creates a new client instance that connects to FeatBit with the custom option. +var client = new FbClient(options); +``` + +#### Dependency Injection + +We can register the FeatBit services using standard conventions. + +```csharp +using FeatBit.Sdk.Server.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllers(); + +// add FeatBit service +builder.Services.AddFeatBit(options => +{ + options.EnvSecret = ""; + options.StartWaitTime = TimeSpan.FromSeconds(3); +}); + +var app = builder.Build(); +app.Run(); +``` + +Then the `IFbClient` interface can be obtained through dependency injection. + +```csharp +public class HomeController : ControllerBase +{ + private readonly IFbClient _fbClient; + + public HomeController(IFbClient fbClient) + { + _fbClient = fbClient; + } +} +``` + +### FbUser + +FbUser defines the attributes of a user for whom you are evaluating feature flags. FbUser has two built-in +attributes: `key` and `name`. The only mandatory attribute of a FbUser is the key, which must uniquely identify each +user. + +Besides these built-in properties, you can define any additional attributes associated with the user +using `Custom(string key, string value)` method on `IFbUserBuilder`. Both built-in attributes and custom attributes can +be referenced in targeting rules, and are included in analytics data. + +There is only one method for building FbUser. + +```csharp +var bob = FbUser.Builder("a-unique-key-of-user") + .Name("bob") + .Custom("age", "15") + .Custom("country", "FR") + .Build(); +``` + +### Evaluating flags + +By using the feature flag data it has already received, the SDK **locally calculates** the value of a feature flag for a +given user. + +There is a `Variation` method that returns a flag value, and a `VariationDetail` method that returns an object +describing how the value was determined for each type. + +- BoolVariation/BoolVariationDetail +- StringVariation/StringVariationDetail +- DoubleVariation/DoubleVariationDetail +- FloatVariation/FloatVariationDetail +- IntVariation/IntVariationDetail +- JsonVariation/JsonVariationDetail (in consideration) + +Variation calls take the feature flag key, a FbUser, and a default value. If any error makes it impossible to +evaluate the flag (for instance, the feature flag key does not match any existing flag), default value is returned. + +```csharp +using FeatBit.Sdk.Server; +using FeatBit.Sdk.Server.Model; + +// Creates a new client instance that connects to FeatBit with the default option. +var client = new FbClient(""); + +// The flag key to be evaluated +const string flagKey = "game-runner"; + +// The user +var user = FbUser.Builder("anonymous").Build(); + +// Evaluate a boolean flag for a given user +var boolVariation = client.BoolVariation(flagKey, user, defaultValue: false); +Console.WriteLine($"flag '{flagKey}' returns {boolVariation} for user {user.Key}"); + +// evaluate a boolean flag for a given user with evaluation detail +var boolVariationDetail = client.BoolVariationDetail(flagKey, user, defaultValue: false); +Console.WriteLine( + $"flag '{flagKey}' returns {boolVariationDetail.Value} for user {user.Key}. " + + $"Reason Kind: {boolVariationDetail.Kind}, Reason Description: {boolVariationDetail.Reason}" +); +``` + +Please help me to init my featbit sdk in asp.net app \ No newline at end of file diff --git a/featbit/prompt.txt b/featbit/prompt.txt new file mode 100644 index 0000000..e69de29 diff --git a/featbit/remove/README.md b/featbit/remove/README.md new file mode 100644 index 0000000..6b11c18 --- /dev/null +++ b/featbit/remove/README.md @@ -0,0 +1,22 @@ +With prompt, you just need to give it the code source, feature flag key, and feature flag return value. + +Here's an example: + +Code selected in VSCode with DevLake + + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;(new Pmpt()).P(); public class Pmpt{public void P(){var o=new FbOptionsBuilder().Offline(true).Build();var c=new FbClient(o);var u=FbUser.Builder("anonymous").Build();var b=c.StringVariation("f33",u,defaultValue:"on");if(b=="on"){F.R1();F.R2();}}}``` + +Sentence in Devlake's input: + +``` +Remove feature flag f33 and related code when it return `on` +``` + +``` +Remove feature flag "f33" and related code if it returns "on" +``` + +``` +In the given code, eliminate the feature flags tied to the key `f33`, while preserving the code associated with the `on` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions. +``` \ No newline at end of file diff --git a/featbit/remove/command.yml b/featbit/remove/command.yml new file mode 100644 index 0000000..7fa8fd0 --- /dev/null +++ b/featbit/remove/command.yml @@ -0,0 +1 @@ +description: Remove dead feature flags from selected C# code. \ No newline at end of file diff --git a/featbit/remove/prompt.txt b/featbit/remove/prompt.txt new file mode 100644 index 0000000..331c367 --- /dev/null +++ b/featbit/remove/prompt.txt @@ -0,0 +1,63 @@ +Hello Assistant, as a developer, I need your assistance in cleaning up the code by removing unnecessary and expired feature flags. Please also help me maintain the relevant business logic that is directly or indirectly wrapped within these feature flags. + +user: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;(new Pmpt()).P(); public class Pmpt{public void P(){var o=new FbOptionsBuilder().Offline(true).Build();var c=new FbClient(o);var u=FbUser.Builder("anonymous").Build();var f1=c.BoolVariation("f1k",u,defaultValue:false);if(f1==true){var b=c.StringVariation("f2",u,defaultValue:"on");if(b=="on"){F.R1();F.R2();}}else if(f1==false)F.RN();else F.RN();}}``` + +In the given code, eliminate the feature flags tied to the key `f1k`, while preserving the code associated with the `true` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions. + +assistant: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;(new Pmpt()).P(); public class Pmpt{public void P(){var o=new FbOptionsBuilder().Offline(true).Build();var c=new FbClient(o);var u=FbUser.Builder("anonymous").Build();var b=c.StringVariation("f2",u,defaultValue:"on");if(b=="on"){F.R1();F.R2();}}}``` + +user: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;var o=new FbOptionsBuilder().Offline(true).Build();var c=new FbClient(o);(new Pmpt()).P(c); public class Pmpt{public void P(FbClient c){var u=FbUser.Builder("anonymous").Build();var f1=c.BoolVariation("f1",u,defaultValue:false);if(f1==true){F.R1();var b=c.StringVariation("f2k",u,defaultValue:"on");if(b=="on"){F.RR2();}}else F.R1();var f2=c.StringVariation("f2k",u,defaultValue:"on");if(f2=="t")F.RN3();else if(f2=="on")F.R2();else F.R1();}}``` + +In the given code, eliminate the feature flags tied to the key `f2k`, while preserving the code associated with the `on` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions.', + +assistant: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;var o=new FbOptionsBuilder().Offline(true).Build();var c=new FbClient(o);(new Pmpt()).P(c); public class Pmpt{public void P(FbClient c){var u=FbUser.Builder("anonymous").Build();var f1=c.BoolVariation("f1",u,defaultValue:false);if(f1==true){F.R1();F.RR2();}else F.R1();F.R2();}}``` + +user: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;using System.Net;var option=new FbOptionsBuilder().Offline(true).Build();var client=new FbClient(option);(new Pmpt()).P(client); public class Pmpt{public bool P(FbClient c){var u=FbUser.Builder("anonymous").Build();var f1=c.BoolVariation("f-f-1",u,defaultValue:false);if(f1==true){F.R1();}else F.RNN1();if(f1){F.R1();}else F.RNN2();if(f1==false||!f1){return F.RNN();}return F.R1();}}``` + +In the given code, eliminate the feature flags tied to the key `f-f-1`, while preserving the code associated with the `false` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions. + +assistant: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using FeatBit.Sdk.Server.Options;using System.Net;var option=new FbOptionsBuilder().Offline(true).Build();var client=new FbClient(option);(new Pmpt()).P(client); public class Pmpt{public bool P(FbClient c){F.RNN1();F.RNN2();return F.RNN();}}``` + +user: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using Microsoft.AspNetCore.Mvc;namespace T4Prompt.Controllers; [ApiController][Route("[controller]")]public class HelloController:ControllerBase{private readonly FbClient _client;public HelloController(FbClient client){_client=client;}[HttpGet]public string HelloWorld(){var u=FbUser.Builder("bob").Name("bob").Build();var variation=_client.StringVariation("language",u,"en-us");return variation switch{"zh-cn"=>"你好世界!","en-us"=>"Hello World!",_=>string.Empty};}}``` + +In the given code, eliminate the feature flags tied to the key `language`, while preserving the code associated with the `zh-cn` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions.' + +assistant: + +```csharp using FeatBit.Sdk.Server;using FeatBit.Sdk.Server.Model;using Microsoft.AspNetCore.Mvc;namespace T4Prompt.Controllers; [ApiController][Route("[controller]")]public class HelloController:ControllerBase{private readonly FbClient _client;public HelloController(FbClient client){_client=client;}[HttpGet]public string HelloWorld(){return"你好世界!";}}``` + +user: + +```csharp public class UProm{public string UP(FbClient c,FbUser user){string total="0",num1="3",num2="12";var ifC=c.BoolVariation("ifC",user,defaultValue:false);if(ifC==true){return total+num1+num2;}return total;}}``` + +In the given code, eliminate the feature flags tied to the key `ifC`, while preserving the code associated with the `true` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions. + +assistant: + +```csharp public class UProm{public string UP(FbClient c,FbUser user){string total="0",num1="3",num2="12";return total+num1+num2;}}```', + +user: + +```csharp public class Pmpt{public bool P(FbClient c){var u=FbUser.Builder("anonymous").Build();var f1=c.BoolVariation("f-f",u,defaultValue:false);if(f1==true){return F.RNN1();}return F.RNN();}}``` + +In the given code, eliminate the feature flags tied to the key `f-f`, while preserving the code associated with the `true` return value. Also, maintain any other code not related to these feature flags. Ignore the defaultValue. Provide just the code, excluding any descriptions. + +assistant: + +```csharp public class Pmpt{public bool P(FbClient c){return F.RNN();}}```", + +user: \ No newline at end of file