Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added featbit remove, init, eval prompts & commands #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions featbit/evaluate/README.md
Original file line number Diff line number Diff line change
@@ -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"
```
1 change: 1 addition & 0 deletions featbit/evaluate/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: Generate C# code using FeatBit to evaluate feature flags.
177 changes: 177 additions & 0 deletions featbit/evaluate/prompt.txt
Original file line number Diff line number Diff line change
@@ -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("<replace-with-your-env-secret>")
.Event(new Uri("<replace-with-your-event-url>"))
.Steaming(new Uri("<replace-with-your-streaming-url>"))
.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("<replace-with-your-env-secret>");
```

#### 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("<replace-with-your-env-secret>")
.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 = "<replace-with-your-env-secret>";
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("<replace-with-your-env-secret>");

// 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
1 change: 1 addition & 0 deletions featbit/init/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: Initialize and use the FeatBit SDK in a C# application.
177 changes: 177 additions & 0 deletions featbit/init/prompt.txt
Original file line number Diff line number Diff line change
@@ -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("<replace-with-your-env-secret>")
.Event(new Uri("<replace-with-your-event-url>"))
.Steaming(new Uri("<replace-with-your-streaming-url>"))
.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("<replace-with-your-env-secret>");
```

#### 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("<replace-with-your-env-secret>")
.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 = "<replace-with-your-env-secret>";
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("<replace-with-your-env-secret>");

// 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
Empty file added featbit/prompt.txt
Empty file.
Loading