Skip to content

Latest commit

 

History

History
116 lines (81 loc) · 3.75 KB

README.md

File metadata and controls

116 lines (81 loc) · 3.75 KB

Inferable Logo

.NET SDK for Inferable

NuGet version License: MIT Documentation

The Inferable .NET Client is a .NET library that allows you to interact with the Inferable API. This library provides functionality to register your .NET functions, manage services, and handle API communication easily.

Installation

To install the Inferable .NET Client, use the following command in your project:

dotnet add package Inferable

Quick Start

Initializing the Client

To create a new Inferable client, use the InferableClient class:

using Inferable;

var options = new InferableOptions
{
    ApiSecret = "your-api-secret", // Replace with your API secret
    BaseUrl = "https://api.inferable.ai" // Optional, uses default if not provided
};

var client = new InferableClient(options);

If you don't provide an API key or base URL, it will attempt to read them from the following environment variables:

  • INFERABLE_API_SECRET
  • INFERABLE_API_ENDPOINT

Registering a Function

Register a "sayHello" tool. This file will register the function with the control-plane.

public class MyInput
{
    public string Message { get; set; }
}

client.RegisterTool(new ToolRegistration<MyInput>
{
    Name = "SayHello",
    Description = "A simple greeting function",
    Func = new Func<MyInput, MyResult>>((input) => {
        // Your code here
    }),
});

_ = client.ListenAsync();
👉 The DotNet SDK for Inferable reflects the types from the input class of the function.

Unlike the NodeJs SDK, the Dotnet SDK for Inferable reflects the types from the input struct of the function. It uses the NJsonSchema under the hood to generate JSON schemas from C# types through reflection.

If the input class defines System.Text.Json.Serialization attributes, the SDK will use those in the generated schema. This allows for fine-grained control over the schema generation.

Here's an example to illustrate this:

public struct UserInput
{
  [JsonPropertyName("id")]
  public string Id { get; set; }
  [JsonPropertyName("Name")]
  public string Name { get; set; }
  [
    JsonPropertyName("email"),
    JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)
  ]
  public string Email { get; set; }
}

client.RegisterTool(new ToolRegistration<MyInput>
{
    Name = "SayHello",
    Description = "A simple greeting function",
    Func = new Func<UserInput, MyResult>>((input) => {
        // Your code here
    }),
});

In this example, the UserInput class uses System.Text.Json.Serialization attributes to define additional properties for the schema:

  • The email field is ignored when writing null.

Documentation

Support

For support or questions, please create an issue in the repository.

Contributing

Contributions to the Inferable .NET Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.