Pieces.OS.Client
0.1.1-beta
See the version list below for details.
dotnet add package Pieces.OS.Client --version 0.1.1-beta
NuGet\Install-Package Pieces.OS.Client -Version 0.1.1-beta
<PackageReference Include="Pieces.OS.Client" Version="0.1.1-beta" />
paket add Pieces.OS.Client --version 0.1.1-beta
#r "nuget: Pieces.OS.Client, 0.1.1-beta"
// Install Pieces.OS.Client as a Cake Addin #addin nuget:?package=Pieces.OS.Client&version=0.1.1-beta&prerelease // Install Pieces.OS.Client as a Cake Tool #tool nuget:?package=Pieces.OS.Client&version=0.1.1-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:
- Copilot Chats: Communicate seamlessly with copilot chats functionality.
- Asset Management: Save and manage assets and formats efficiently.
- Local Server Interaction: Interact with a locally hosted server for various functionality.
- 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:
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:
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 | Versions 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. |
-
net8.0
- JsonSubTypes (>= 2.0.1)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.1.0)
- RestSharp (>= 112.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
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.4-beta | 45 | 11/14/2024 |
0.1.3-beta | 57 | 10/26/2024 |
0.1.2-beta | 43 | 10/21/2024 |
0.1.1-beta | 79 | 10/18/2024 |
0.0.11-beta | 63 | 10/18/2024 |
0.0.10-beta | 49 | 10/16/2024 |
0.0.9-beta | 46 | 9/26/2024 |
0.0.7-beta | 47 | 9/23/2024 |
0.0.6-beta | 65 | 9/6/2024 |