Pieces.OS.Client 0.1.2-beta

This is a prerelease version of Pieces.OS.Client.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pieces.OS.Client --version 0.1.2-beta                
NuGet\Install-Package Pieces.OS.Client -Version 0.1.2-beta                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pieces.OS.Client" Version="0.1.2-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pieces.OS.Client --version 0.1.2-beta                
#r "nuget: Pieces.OS.Client, 0.1.2-beta"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pieces.OS.Client as a Cake Addin
#addin nuget:?package=Pieces.OS.Client&version=0.1.2-beta&prerelease

// Install Pieces.OS.Client as a Cake Tool
#tool nuget:?package=Pieces.OS.Client&version=0.1.2-beta&prerelease                

Pieces OS Client SDK For C#

The Pieces OS Client SDK is a powerful code engine package designed for writing applications on top of Pieces OS. It facilitates communication with a locally hosted server to enable features such as copilot chats, asset saving, and more.

Features

The Pieces SDK offers the following key features:

  1. Copilot Chats: Communicate seamlessly with copilot chats functionality.
  2. Asset Management: Save and manage assets and formats efficiently.
  3. Local Server Interaction: Interact with a locally hosted server for various functionality.
  4. Multi-LLM support: Use any Pieces supported LLM to power your app.

Installation

To get started with the Pieces OS Client SDK, follow these steps:

  1. Download Pieces OS: Pieces OS serves as the primary backend service, providing essential functionality for the SDK. Download the appropriate version for your operating system:

  2. Install the SDK: Use nuget to install the Pieces OS Client SDK package:

    dotnet add package Pieces.OS.Client --prerelease
    

Pieces Client Examples

There is an example project using the Pieces Client in the Client.Example project. This example is a console app containing a range of different examples, each commented out. To run these examples, uncomment the one you want to run, then run dotnet run from the Client.Example project.

Quickstart

To set up the SDK, create an instance of the PiecesClient. By default this will connect to Pieces OS running locally on the default port, but you can override this by passing in the URL and port as the baseUrl parameter.

The PiecesClient constructor also optionally takes an ILogger to provide full logging for the SDK.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using Pieces.OS.Client;

// Set up logging (optional)
var services = new ServiceCollection();
services.AddLogging(builder =>builder.AddConsole());
var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();

// Create the Pieces client
IPiecesClient client = new PiecesClient(logger);

// Write out the version
Console.WriteLine($"Pieces OS version: {await client.GetVersionAsync().ConfigureAwait(false)}");

Use the copilot

To interact with the Pieces copilot, use the IPiecesClient.GetCopilotAsync() method to return an IPiecesCopilot instance.

var copilot = await client.GetCopilotAsync().ConfigureAwait(false);

Once you have the IPiecesCopilot, you can ask questions, and get the response either as a single string, or streaming data.

Create a chat and ask a question:

This will create a new copilot chat that you will be able to see in other Pieces applications, such as Pieces Desktop, or Pieces for Visual Studio Code. This chat will be named "C# question on async tasks", and you will see this name in other Pieces applications. The chat will ask a question, then return the full answer to the console once it has the complete answer.

var chat = await copilot.CreateChatAsync("C# question on async tasks").ConfigureAwait(false);
Console.WriteLine(await chat.AskQuestionAsync("What does the async keyword do in C#?"));

Create a chat and stream the response

This will create a new copilot chat, ask a question, then stream the response back token by token.

var chat = await copilot.CreateChatAsync("C# streaming question on primary constructors").ConfigureAwait(false);
await foreach (var token in chat.AskStreamingQuestionAsync("In C#, what is a primary constructor? Give me some example code that declares a class with one."))
{
    Console.Write(token);
}

Interact with assets

To interact with assets in Pieces, such as saved code snippets, use the IPiecesClient.GetAssetsAsync() method to return an IPiecesAssets instance.

var assets = await client.GetAssetsAsync().ConfigureAwait(false);

Once you have the IPiecesAssets, you can get and create assets.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pieces.OS.Client:

Package Downloads
Pieces.Extensions.AI

Support for Microsoft.Extensions.AI using Pieces for Developers as the LLM

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.3-beta 40 10/26/2024
0.1.2-beta 37 10/21/2024
0.1.1-beta 73 10/18/2024
0.0.11-beta 59 10/18/2024
0.0.10-beta 45 10/16/2024
0.0.9-beta 43 9/26/2024
0.0.7-beta 44 9/23/2024
0.0.6-beta 62 9/6/2024