From 9ac9b496043a5874439c63e038a736086ce962f7 Mon Sep 17 00:00:00 2001 From: Comiscience <68597908+cosmic-flood@users.noreply.github.com> Date: Sun, 3 Sep 2023 04:12:39 +0000 Subject: [PATCH 1/4] added featbit remove, init, eval prompts --- featbit_cs_evaluate/command.yml | 1 + featbit_cs_evaluate/prompt.txt | 207 ++++++++++++++++++++++++++++ featbit_cs_init_aspnet/command.yml | 1 + featbit_cs_init_aspnet/prompt.txt | 192 ++++++++++++++++++++++++++ featbit_cs_init_console/command.yml | 1 + featbit_cs_init_console/prompt.txt | 192 ++++++++++++++++++++++++++ featbit_cs_remove/README.md | 67 +++++++++ featbit_cs_remove/command.yml | 1 + featbit_cs_remove/prompt.txt | 58 ++++++++ 9 files changed, 720 insertions(+) create mode 100644 featbit_cs_evaluate/command.yml create mode 100644 featbit_cs_evaluate/prompt.txt create mode 100644 featbit_cs_init_aspnet/command.yml create mode 100644 featbit_cs_init_aspnet/prompt.txt create mode 100644 featbit_cs_init_console/command.yml create mode 100644 featbit_cs_init_console/prompt.txt create mode 100644 featbit_cs_remove/README.md create mode 100644 featbit_cs_remove/command.yml create mode 100644 featbit_cs_remove/prompt.txt diff --git a/featbit_cs_evaluate/command.yml b/featbit_cs_evaluate/command.yml new file mode 100644 index 0000000..a13ec38 --- /dev/null +++ b/featbit_cs_evaluate/command.yml @@ -0,0 +1 @@ +description: Generate FeatBit C# code for evaluating feature flags \ No newline at end of file diff --git a/featbit_cs_evaluate/prompt.txt b/featbit_cs_evaluate/prompt.txt new file mode 100644 index 0000000..d63b55b --- /dev/null +++ b/featbit_cs_evaluate/prompt.txt @@ -0,0 +1,207 @@ +## Introduction + +This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and +applications. It is not intended for use in desktop and embedded systems applications. + +### Quick Start + +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(); +``` + +## SDK + +### FbClient + +The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. + +#### 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. + +> **Note** +> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. + +```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) + +> **Note** +> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. + +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}" +); +``` + + +Image the FeatBit sdk has been initialized and injected in constructor, please help me to generate the code c# code only for evaluating the feature flags with feature flag with key `{{feature-flag-key}}`, and if it returns `true`, then execute a fake todo code + +Output Example: + +```csharp + string flagKey = "example"; +var user = FbUser.Builder("anonymous").Build(); +var boolVariation = _fbClient.BoolVariation(flagKey, user, defaultValue: false); + +// Check the feature flag value and execute "fake todo" code if it's true +if (boolVariation) +{ + // todo; +} +``` \ No newline at end of file diff --git a/featbit_cs_init_aspnet/command.yml b/featbit_cs_init_aspnet/command.yml new file mode 100644 index 0000000..8104bfc --- /dev/null +++ b/featbit_cs_init_aspnet/command.yml @@ -0,0 +1 @@ +description: Generate FeatBit C# initialization code. \ No newline at end of file diff --git a/featbit_cs_init_aspnet/prompt.txt b/featbit_cs_init_aspnet/prompt.txt new file mode 100644 index 0000000..fc71a3d --- /dev/null +++ b/featbit_cs_init_aspnet/prompt.txt @@ -0,0 +1,192 @@ +## Introduction + +This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and +applications. It is not intended for use in desktop and embedded systems applications. + +### Quick Start + +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(); +``` + +## SDK + +### FbClient + +The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. + +#### 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. + +> **Note** +> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. + +```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) + +> **Note** +> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. + +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_cs_init_console/command.yml b/featbit_cs_init_console/command.yml new file mode 100644 index 0000000..8104bfc --- /dev/null +++ b/featbit_cs_init_console/command.yml @@ -0,0 +1 @@ +description: Generate FeatBit C# initialization code. \ No newline at end of file diff --git a/featbit_cs_init_console/prompt.txt b/featbit_cs_init_console/prompt.txt new file mode 100644 index 0000000..a102352 --- /dev/null +++ b/featbit_cs_init_console/prompt.txt @@ -0,0 +1,192 @@ +## Introduction + +This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and +applications. It is not intended for use in desktop and embedded systems applications. + +### Quick Start + +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(); +``` + +## SDK + +### FbClient + +The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. + +#### 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. + +> **Note** +> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. + +```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) + +> **Note** +> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. + +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 FeatBit sdk in my c# console app \ No newline at end of file diff --git a/featbit_cs_remove/README.md b/featbit_cs_remove/README.md new file mode 100644 index 0000000..3155f83 --- /dev/null +++ b/featbit_cs_remove/README.md @@ -0,0 +1,67 @@ +## Introduction + +As ChatGPT (Large Language Model) has gained popularity, terms like Prompt Engineer, Prompt Ops, and LLM Ops have emerged. This got me thinking about whether this powerful model could be applied to practical programming scenarios. So, I decided to test its abilities in a couple of pain points with the Feature Flags on the FeatBit service. I found that both the GPT-3.5 API and GPT-4 Chat interfaces produced impressive results. However, despite fine-tuning the model to a certain extent, the performance of GPT-3 still fell short of my expectations. I have written a blog article that delves into detail about the two scenarios I've tested: + +- Utilize ChatGPT for eliminating dead feature flag code +- Leverage prompts for developer tool onboarding + +Feel free to check out [our blog article - Developer Tool 2.0](https://www.featbit.co/blogs/LLM-Introducing-FeatBit-ChatGPT-Powered-FeatureFlags-Service), which provides more in-depth information on the two use cases mentioned above. + +In conclusion, ChatGPT has shown immense potential in addressing practical programming pain points, such as removing dead feature flags and enhancing developer tool onboarding. While the current performance may not be perfect, it is important to remember that we are still in the early stages of exploring the capabilities of these language models. As more data and real-world use cases become available for pre-training and fine-tuning, we can expect to see significant improvements in the accuracy and usefulness of ChatGPT in a variety of programming scenarios. This not only promises to revolutionize the way developers interact with code, but also paves the way for more accessible and efficient solutions for non-engineers. The future of ChatGPT and similar models is bright, and we eagerly anticipate the advancements they will bring to the software development landscape. + +This folder of FeatBit's main repository contains the executive files you can test with for the scenarios I tested. + +## Run remove-feature-flag chat-completion cli + +In the remove-feature-flags folder, you'll find a file named chat-completion-cli.py. This is a simple Python program that calls OpenAI's ChatCompletion method, instructing ChatGPT-3 to remove dead feature flags and any associated code. + +Think of chat-completion-cli.py as a prompt service. You can execute the Python file with the required parameters, and it will send a command to ChatGPT. + +Parameters: + +- `apikey`: Your API key for accessing the ChatGPT API service. +- `ffKey`: The feature flag you wish to remove from your project. +- `variation`: The feature flag return value corresponding to the code you want to retain. +- `codePath`: The file path of the code you want to scan and where you want to remove dead feature flags. + +You can run the Python file using the command below: + +```shell +python3 chat-completion-cli.py --apikey "your-openapi-key" --ffKey "language" --variation "en-us" --codePath "/mnt/c/Code/featbit/featbit/llm/dotnet-sample/U1Prompt/Program.cs" +``` +Here are two examples of what the execution process mentioned above looks like: + +![image](https://user-images.githubusercontent.com/68597908/229683743-00836ef5-f251-4e5f-9da4-120c68a28057.png) + +![image](https://user-images.githubusercontent.com/68597908/229683788-a791581d-fd83-4c6b-93ed-56d7aee406d0.png) + + + +You can refer to the `remove-feature-flags/chat-completion-cli.py` source code to see how I wrote the program. Additionally, you can explore sample-data projects for fine-tuning in another [FeatBit's GitHub repository](https://github.com/featbit/chatgpt-fine-tune). + +### Addressing feature flag technical debt in other languages + +I planned to make it possible for all other language framework, I think I need more community support for all of that. + +I have plans to expand this functionality to other language frameworks, but I will need more support from the community to achieve this goal. + + + +## Optimal Developer Tools Onboarding Experience + +Leveraging ChatGPT's code completion and code insertion capabilities, developers can effortlessly initialize FeatBit in their existing projects with just a simple prompt. Even without fine-tuning, you can utilize chat-completion to have GPT-4 read the GitHub documentation and learn how to use FeatBit's SDK. + +The image below illustrates the trial steps: + +1. I input the FeatBit .NET SDK documentation into ChatGPT-4. +2. I copy the code source from an ASP.NET Core 7's Program.cs file. +3. Instruct GPT-4 to initialize FeatBit's .NET SDK within the code source. +3. GPT-4 returned the modified code after initialization. + + +![image](https://user-images.githubusercontent.com/68597908/229688274-134318ad-3410-48f0-af18-b5f001d429f2.png) + + +## Contribution + +If you're interested in what I'm doing, please join our [online Community](https://join.slack.com/t/featbit/shared_invite/zt-1ew5e2vbb-x6Apan1xZOaYMnFzqZkGNQ). \ No newline at end of file diff --git a/featbit_cs_remove/command.yml b/featbit_cs_remove/command.yml new file mode 100644 index 0000000..548bb24 --- /dev/null +++ b/featbit_cs_remove/command.yml @@ -0,0 +1 @@ +description: Remove dead feature flag from selected c# code. \ No newline at end of file diff --git a/featbit_cs_remove/prompt.txt b/featbit_cs_remove/prompt.txt new file mode 100644 index 0000000..19605f2 --- /dev/null +++ b/featbit_cs_remove/prompt.txt @@ -0,0 +1,58 @@ +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. + +Here some examples: + +## Example 1: + +```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. + +```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();}}}``` + +## Example 2: + +```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.', + +```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();}}``` + +## Example 3: + +```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. + +```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();}}``` + +## Example 4: + +```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.' + +```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"你好世界!";}}``` + +## Example 5: + +```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. + +```csharp public class UProm{public string UP(FbClient c,FbUser user){string total="0",num1="3",num2="12";return total+num1+num2;}}```', + +## Example 6: + +```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. + +```csharp public class Pmpt{public bool P(FbClient c){return F.RNN1();}}```", + +## Practice + +{{selected-code}} + +In the given code, eliminate the feature flags tied to the key `{{feature-flag-key}}`, while preserving the code associated with the `{{return-value}}` 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 From 0b28258d5884260d314e4196e3256fc5674555db Mon Sep 17 00:00:00 2001 From: Comiscience <68597908+cosmic-flood@users.noreply.github.com> Date: Sun, 3 Sep 2023 04:59:09 +0000 Subject: [PATCH 2/4] updated featbit remove which works with dc input --- featbit_cs_remove/README.md | 69 ++++++------------------------------ featbit_cs_remove/prompt.txt | 35 ++++++++++-------- 2 files changed, 31 insertions(+), 73 deletions(-) diff --git a/featbit_cs_remove/README.md b/featbit_cs_remove/README.md index 3155f83..5940bf4 100644 --- a/featbit_cs_remove/README.md +++ b/featbit_cs_remove/README.md @@ -1,67 +1,18 @@ -## Introduction +With prompt, you just need to give it the code source, feature flag key, and feature flag return value. -As ChatGPT (Large Language Model) has gained popularity, terms like Prompt Engineer, Prompt Ops, and LLM Ops have emerged. This got me thinking about whether this powerful model could be applied to practical programming scenarios. So, I decided to test its abilities in a couple of pain points with the Feature Flags on the FeatBit service. I found that both the GPT-3.5 API and GPT-4 Chat interfaces produced impressive results. However, despite fine-tuning the model to a certain extent, the performance of GPT-3 still fell short of my expectations. I have written a blog article that delves into detail about the two scenarios I've tested: +Here's an example: -- Utilize ChatGPT for eliminating dead feature flag code -- Leverage prompts for developer tool onboarding +Code selected in VSCode with DevLake -Feel free to check out [our blog article - Developer Tool 2.0](https://www.featbit.co/blogs/LLM-Introducing-FeatBit-ChatGPT-Powered-FeatureFlags-Service), which provides more in-depth information on the two use cases mentioned above. -In conclusion, ChatGPT has shown immense potential in addressing practical programming pain points, such as removing dead feature flags and enhancing developer tool onboarding. While the current performance may not be perfect, it is important to remember that we are still in the early stages of exploring the capabilities of these language models. As more data and real-world use cases become available for pre-training and fine-tuning, we can expect to see significant improvements in the accuracy and usefulness of ChatGPT in a variety of programming scenarios. This not only promises to revolutionize the way developers interact with code, but also paves the way for more accessible and efficient solutions for non-engineers. The future of ChatGPT and similar models is bright, and we eagerly anticipate the advancements they will bring to the software development landscape. +```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();}}}``` -This folder of FeatBit's main repository contains the executive files you can test with for the scenarios I tested. +Sentence in Devlake's input: -## Run remove-feature-flag chat-completion cli - -In the remove-feature-flags folder, you'll find a file named chat-completion-cli.py. This is a simple Python program that calls OpenAI's ChatCompletion method, instructing ChatGPT-3 to remove dead feature flags and any associated code. - -Think of chat-completion-cli.py as a prompt service. You can execute the Python file with the required parameters, and it will send a command to ChatGPT. - -Parameters: - -- `apikey`: Your API key for accessing the ChatGPT API service. -- `ffKey`: The feature flag you wish to remove from your project. -- `variation`: The feature flag return value corresponding to the code you want to retain. -- `codePath`: The file path of the code you want to scan and where you want to remove dead feature flags. - -You can run the Python file using the command below: - -```shell -python3 chat-completion-cli.py --apikey "your-openapi-key" --ffKey "language" --variation "en-us" --codePath "/mnt/c/Code/featbit/featbit/llm/dotnet-sample/U1Prompt/Program.cs" ``` -Here are two examples of what the execution process mentioned above looks like: - -![image](https://user-images.githubusercontent.com/68597908/229683743-00836ef5-f251-4e5f-9da4-120c68a28057.png) - -![image](https://user-images.githubusercontent.com/68597908/229683788-a791581d-fd83-4c6b-93ed-56d7aee406d0.png) - - - -You can refer to the `remove-feature-flags/chat-completion-cli.py` source code to see how I wrote the program. Additionally, you can explore sample-data projects for fine-tuning in another [FeatBit's GitHub repository](https://github.com/featbit/chatgpt-fine-tune). - -### Addressing feature flag technical debt in other languages - -I planned to make it possible for all other language framework, I think I need more community support for all of that. - -I have plans to expand this functionality to other language frameworks, but I will need more support from the community to achieve this goal. - - - -## Optimal Developer Tools Onboarding Experience - -Leveraging ChatGPT's code completion and code insertion capabilities, developers can effortlessly initialize FeatBit in their existing projects with just a simple prompt. Even without fine-tuning, you can utilize chat-completion to have GPT-4 read the GitHub documentation and learn how to use FeatBit's SDK. - -The image below illustrates the trial steps: - -1. I input the FeatBit .NET SDK documentation into ChatGPT-4. -2. I copy the code source from an ASP.NET Core 7's Program.cs file. -3. Instruct GPT-4 to initialize FeatBit's .NET SDK within the code source. -3. GPT-4 returned the modified code after initialization. - - -![image](https://user-images.githubusercontent.com/68597908/229688274-134318ad-3410-48f0-af18-b5f001d429f2.png) - - -## Contribution +Remove feature flag f33 and related code when it return `on` +``` -If you're interested in what I'm doing, please join our [online Community](https://join.slack.com/t/featbit/shared_invite/zt-1ew5e2vbb-x6Apan1xZOaYMnFzqZkGNQ). \ No newline at end of file +``` +Remove feature flag "f33" and related code if it returns "on" +``` \ No newline at end of file diff --git a/featbit_cs_remove/prompt.txt b/featbit_cs_remove/prompt.txt index 19605f2..52333c6 100644 --- a/featbit_cs_remove/prompt.txt +++ b/featbit_cs_remove/prompt.txt @@ -1,58 +1,65 @@ 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. -Here some examples: - -## Example 1: +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();}}}``` -## Example 2: +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();}}``` -## Example 3: +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();}}``` -## Example 4: +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"你好世界!";}}``` -## Example 5: +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;}}```', -## Example 6: +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. -```csharp public class Pmpt{public bool P(FbClient c){return F.RNN1();}}```", +assistant: -## Practice - -{{selected-code}} +```csharp public class Pmpt{public bool P(FbClient c){return F.RNN1();}}```", -In the given code, eliminate the feature flags tied to the key `{{feature-flag-key}}`, while preserving the code associated with the `{{return-value}}` 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 +user: From 4b4b43f64a1b4573da48c6953bf5eb0f20db3c6d Mon Sep 17 00:00:00 2001 From: Comiscience <68597908+cosmic-flood@users.noreply.github.com> Date: Sun, 3 Sep 2023 05:14:00 +0000 Subject: [PATCH 3/4] fixing prompts --- featbit_cs_evaluate/README.md | 13 +++++++++++++ featbit_cs_evaluate/prompt.txt | 17 +++++++++++++---- featbit_cs_remove/README.md | 4 ++++ featbit_cs_remove/prompt.txt | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 featbit_cs_evaluate/README.md diff --git a/featbit_cs_evaluate/README.md b/featbit_cs_evaluate/README.md new file mode 100644 index 0000000..cca0c57 --- /dev/null +++ b/featbit_cs_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_cs_evaluate/prompt.txt b/featbit_cs_evaluate/prompt.txt index d63b55b..1b1637c 100644 --- a/featbit_cs_evaluate/prompt.txt +++ b/featbit_cs_evaluate/prompt.txt @@ -190,18 +190,27 @@ Console.WriteLine( ``` -Image the FeatBit sdk has been initialized and injected in constructor, please help me to generate the code c# code only for evaluating the feature flags with feature flag with key `{{feature-flag-key}}`, and if it returns `true`, then execute a fake todo code +Image the FeatBit sdk has been initialized and injected in constructor, when we ask to generate the evaluation code, you shouldn't generate code of initilization and dependency injection. -Output Example: +For exmaple, + +User: + +Generate feature flag code with key "example" and return "true" + +Asssistance: ```csharp string flagKey = "example"; var user = FbUser.Builder("anonymous").Build(); var boolVariation = _fbClient.BoolVariation(flagKey, user, defaultValue: false); -// Check the feature flag value and execute "fake todo" code if it's true if (boolVariation) { // todo; } -``` \ No newline at end of file +``` + + +User: + diff --git a/featbit_cs_remove/README.md b/featbit_cs_remove/README.md index 5940bf4..6b11c18 100644 --- a/featbit_cs_remove/README.md +++ b/featbit_cs_remove/README.md @@ -15,4 +15,8 @@ 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_cs_remove/prompt.txt b/featbit_cs_remove/prompt.txt index 52333c6..5bd80ec 100644 --- a/featbit_cs_remove/prompt.txt +++ b/featbit_cs_remove/prompt.txt @@ -60,6 +60,6 @@ In the given code, eliminate the feature flags tied to the key `f-f`, while pres assistant: -```csharp public class Pmpt{public bool P(FbClient c){return F.RNN1();}}```", +```csharp public class Pmpt{public bool P(FbClient c){return F.RNN();}}```", user: From bb175bb26514076a080107f3324b1249b5c08a57 Mon Sep 17 00:00:00 2001 From: Comiscience Date: Mon, 4 Sep 2023 18:15:28 +0800 Subject: [PATCH 4/4] updated prompt --- .../evaluate}/README.md | 0 featbit/evaluate/command.yml | 1 + .../evaluate}/prompt.txt | 19 +- featbit/init/command.yml | 1 + .../init}/prompt.txt | 21 +- featbit/prompt.txt | 0 .../remove}/README.md | 0 featbit/remove/command.yml | 1 + .../remove}/prompt.txt | 6 +- featbit_cs_evaluate/command.yml | 1 - featbit_cs_evaluate/prompt.txt | 216 ------------------ featbit_cs_init_aspnet/command.yml | 1 - featbit_cs_init_console/command.yml | 1 - featbit_cs_remove/command.yml | 1 - 14 files changed, 10 insertions(+), 259 deletions(-) rename {featbit_cs_evaluate => featbit/evaluate}/README.md (100%) create mode 100644 featbit/evaluate/command.yml rename {featbit_cs_init_aspnet => featbit/evaluate}/prompt.txt (86%) create mode 100644 featbit/init/command.yml rename {featbit_cs_init_console => featbit/init}/prompt.txt (86%) create mode 100644 featbit/prompt.txt rename {featbit_cs_remove => featbit/remove}/README.md (100%) create mode 100644 featbit/remove/command.yml rename {featbit_cs_remove => featbit/remove}/prompt.txt (92%) delete mode 100644 featbit_cs_evaluate/command.yml delete mode 100644 featbit_cs_evaluate/prompt.txt delete mode 100644 featbit_cs_init_aspnet/command.yml delete mode 100644 featbit_cs_init_console/command.yml delete mode 100644 featbit_cs_remove/command.yml diff --git a/featbit_cs_evaluate/README.md b/featbit/evaluate/README.md similarity index 100% rename from featbit_cs_evaluate/README.md rename to featbit/evaluate/README.md 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_cs_init_aspnet/prompt.txt b/featbit/evaluate/prompt.txt similarity index 86% rename from featbit_cs_init_aspnet/prompt.txt rename to featbit/evaluate/prompt.txt index fc71a3d..50aa4d2 100644 --- a/featbit_cs_init_aspnet/prompt.txt +++ b/featbit/evaluate/prompt.txt @@ -1,9 +1,4 @@ -## Introduction - -This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and -applications. It is not intended for use in desktop and embedded systems applications. - -### Quick Start +This is FeatBit's .NET sdk tutorial. FeatBit is a feature flag service. The following code demonstrates basic usage of FeatBit.ServerSdk. @@ -50,11 +45,7 @@ Console.WriteLine( await client.CloseAsync(); ``` -## SDK - -### FbClient - -The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. +The `FbClient` is the heart of the SDK which providing access to FeatBit server. #### FbClient Using Default Options @@ -89,9 +80,6 @@ var client = new FbClient(options); We can register the FeatBit services using standard conventions. -> **Note** -> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. - ```csharp using FeatBit.Sdk.Server.DependencyInjection; @@ -158,9 +146,6 @@ describing how the value was determined for each type. - IntVariation/IntVariationDetail - JsonVariation/JsonVariationDetail (in consideration) -> **Note** -> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. - 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. 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_cs_init_console/prompt.txt b/featbit/init/prompt.txt similarity index 86% rename from featbit_cs_init_console/prompt.txt rename to featbit/init/prompt.txt index a102352..50aa4d2 100644 --- a/featbit_cs_init_console/prompt.txt +++ b/featbit/init/prompt.txt @@ -1,9 +1,4 @@ -## Introduction - -This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and -applications. It is not intended for use in desktop and embedded systems applications. - -### Quick Start +This is FeatBit's .NET sdk tutorial. FeatBit is a feature flag service. The following code demonstrates basic usage of FeatBit.ServerSdk. @@ -50,11 +45,7 @@ Console.WriteLine( await client.CloseAsync(); ``` -## SDK - -### FbClient - -The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. +The `FbClient` is the heart of the SDK which providing access to FeatBit server. #### FbClient Using Default Options @@ -89,9 +80,6 @@ var client = new FbClient(options); We can register the FeatBit services using standard conventions. -> **Note** -> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. - ```csharp using FeatBit.Sdk.Server.DependencyInjection; @@ -158,9 +146,6 @@ describing how the value was determined for each type. - IntVariation/IntVariationDetail - JsonVariation/JsonVariationDetail (in consideration) -> **Note** -> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. - 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. @@ -189,4 +174,4 @@ Console.WriteLine( ); ``` -Please help me to init FeatBit sdk in my c# console app \ No newline at end of file +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_cs_remove/README.md b/featbit/remove/README.md similarity index 100% rename from featbit_cs_remove/README.md rename to featbit/remove/README.md 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_cs_remove/prompt.txt b/featbit/remove/prompt.txt similarity index 92% rename from featbit_cs_remove/prompt.txt rename to featbit/remove/prompt.txt index 5bd80ec..331c367 100644 --- a/featbit_cs_remove/prompt.txt +++ b/featbit/remove/prompt.txt @@ -2,9 +2,7 @@ Hello Assistant, as a developer, I need your assistance in cleaning up the code 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();}}``` +```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. @@ -62,4 +60,4 @@ assistant: ```csharp public class Pmpt{public bool P(FbClient c){return F.RNN();}}```", -user: +user: \ No newline at end of file diff --git a/featbit_cs_evaluate/command.yml b/featbit_cs_evaluate/command.yml deleted file mode 100644 index a13ec38..0000000 --- a/featbit_cs_evaluate/command.yml +++ /dev/null @@ -1 +0,0 @@ -description: Generate FeatBit C# code for evaluating feature flags \ No newline at end of file diff --git a/featbit_cs_evaluate/prompt.txt b/featbit_cs_evaluate/prompt.txt deleted file mode 100644 index 1b1637c..0000000 --- a/featbit_cs_evaluate/prompt.txt +++ /dev/null @@ -1,216 +0,0 @@ -## Introduction - -This is the .NET Server-Side SDK for the 100% open-source feature flags management. The FeatBit Server-Side SDK for .NET is designed primarily for use in multi-user systems such as web servers and -applications. It is not intended for use in desktop and embedded systems applications. - -### Quick Start - -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(); -``` - -## SDK - -### FbClient - -The FbClient is the heart of the SDK which providing access to FeatBit server. Applications should instantiate a **single instance** for the lifetime of the application. - -#### 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. - -> **Note** -> The `AddFeatBit` extension method will block the current thread for a maximum duration specified in `FbOptions.StartWaitTime`. - -```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) - -> **Note** -> Since the current version does not have native support for retrieving JSON variations, you can utilize the `StringVariation` method as an alternative to obtain the JSON string. - -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}" -); -``` - - -Image the FeatBit sdk has been initialized and injected in constructor, when we ask to generate the evaluation code, you shouldn't generate code of initilization and dependency injection. - -For exmaple, - -User: - -Generate feature flag code with key "example" and return "true" - -Asssistance: - -```csharp - string flagKey = "example"; -var user = FbUser.Builder("anonymous").Build(); -var boolVariation = _fbClient.BoolVariation(flagKey, user, defaultValue: false); - -if (boolVariation) -{ - // todo; -} -``` - - -User: - diff --git a/featbit_cs_init_aspnet/command.yml b/featbit_cs_init_aspnet/command.yml deleted file mode 100644 index 8104bfc..0000000 --- a/featbit_cs_init_aspnet/command.yml +++ /dev/null @@ -1 +0,0 @@ -description: Generate FeatBit C# initialization code. \ No newline at end of file diff --git a/featbit_cs_init_console/command.yml b/featbit_cs_init_console/command.yml deleted file mode 100644 index 8104bfc..0000000 --- a/featbit_cs_init_console/command.yml +++ /dev/null @@ -1 +0,0 @@ -description: Generate FeatBit C# initialization code. \ No newline at end of file diff --git a/featbit_cs_remove/command.yml b/featbit_cs_remove/command.yml deleted file mode 100644 index 548bb24..0000000 --- a/featbit_cs_remove/command.yml +++ /dev/null @@ -1 +0,0 @@ -description: Remove dead feature flag from selected c# code. \ No newline at end of file