InstructSharp 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package InstructSharp --version 1.0.0
                    
NuGet\Install-Package InstructSharp -Version 1.0.0
                    
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="InstructSharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="InstructSharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="InstructSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add InstructSharp --version 1.0.0
                    
#r "nuget: InstructSharp, 1.0.0"
                    
#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.
#:package InstructSharp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=InstructSharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=InstructSharp&version=1.0.0
                    
Install as a Cake Tool

InstructSharp Banner

InstructSharp

InstructSharp is your go-to .NET library for seamless, provider-agnostic LLM integrations. Whether you’re working with ChatGPT, Claude, Gemini, Grok, DeepSeek or LLaMA, InstructSharp wraps every call in a consistent QueryAsync<T> pattern and returns crisp, structured JSON objects 📦✨. Just define your POCO schema, pick your model, and you’re ready to 🚀:

  • 🔌 Multi-provider support: OpenAI, Anthropic, Google, X.AI, DeepSeek & more
  • 🔖 Type-safe outputs: Deserialize straight into your custom classes
  • ⚙️ Fully configurable: Tweak temperature, max_tokens, and other settings
  • 🛠️ Minimal setup: Install via NuGet & start querying in minutes

Crafted for clarity and speed, InstructSharp turns advanced AI workflows into everyday dev tasks 🎯👍.


Installation

dotnet add package InstructSharp

Or via Package Manager:

Install-Package InstructSharp

Supported Providers

  • OpenAI ChatGPT (ChatGPTClient)
  • Anthropic Claude (ClaudeClient)
  • Google Gemini (GeminiClient)
  • X.AI Grok (GrokClient)
  • DeepSeek (DeepSeekClient)
  • Meta LLaMA (via DeepInfra) (LLamaClient)

Each client implements the same QueryAsync<T> pattern and returns a LLMResponse<T>.


Quick Start

  1. Define your output schema

    class QuestionAnswer
    {
        public string Question { get; set; }
        public string Answer   { get; set; }
    }
    
  2. Instantiate a client

    // ChatGPT example
    var chat = new ChatGPTClient("YOUR_OPENAI_API_KEY");
    
  3. Build a request

    var req = new ChatGPTRequest
    {
        Model       = ChatGPTModels.GPT41,
        Instruction = "Talk like a pirate.",
        Input       = "Are semicolons optional in JavaScript?"
    };
    
  4. Send and receive structured output

    var res = await chat.QueryAsync<QuestionAnswer>(req);
    
    Console.WriteLine($"Q: {res.Result.Question}");
    Console.WriteLine($"A: {res.Result.Answer}");
    
  5. Plain‐text fallback

    // For unstructured responses:
    var textRes = await chat.QueryAsync<string>(req);
    Console.WriteLine(textRes.Result);
    

Full Demo

using InstructSharp.Clients.ChatGPT;
using InstructSharp.Core;
using System.Text.Json;

// ...

var client = new ChatGPTClient("sk-...");
var request = new ChatGPTRequest {
    Model       = ChatGPTModels.GPT41,
    Instruction = "Talk like a pirate.",
    Input       = "What is 2 + 2?"
};

var response = await client.QueryAsync<QuestionAnswer>(request);

Console.WriteLine(JsonSerializer.Serialize(response.Result));
// → { "Question":"What is 2 + 2?","Answer":"Arr, 'tis four, matey!" }

Repeat the same steps for any other provider:

var claude = new ClaudeClient("YOUR_CLAUDE_KEY");
var gemini = new GeminiClient("YOUR_GOOGLE_KEY", GeminiModels.Flash25);
// …and so on…

Advanced

  • Custom types: any POCO can be used as T.
  • Temperature, max_tokens, etc. available via each provider’s request class.
  • Error handling: exceptions thrown on non-2xx responses. Inspect response.Usage and response.AdditionalData for extra info.

Contributing

  1. Fork the repo
  2. Implement your feature / fix
  3. Send a PR
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 135 7/8/2025
1.0.6 133 7/7/2025
1.0.5 134 6/24/2025
1.0.4 78 6/20/2025
1.0.3 163 6/14/2025
1.0.2 159 6/14/2025
1.0.1 271 6/13/2025
1.0.0 278 6/13/2025