Skip to content

A modern, production-ready .NET AI toolkit with full support for OpenAI-compatible LLMs. Includes chat, streaming, embeddings, custom providers, and unified API architecture.

License

Notifications You must be signed in to change notification settings

dxpython/SharpAIKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SharpAIKit: A Unified AI/LLM Toolkit for .NET

SharpAIKit Logo

.NET Version License NuGet Build


One API, All LLMs โ€” Supports OpenAI, DeepSeek, Qwen, Mistral, Yi, Groq and any OpenAI-compatible API

๐ŸŽฏ Killer Features Beyond LangChain:

  • ๐Ÿ”ฎ Native C# Code Interpreter - Execute C# code directly, no Python needed
  • ๐Ÿ•ธ๏ธ SharpGraph - Graph orchestration with loops and complex branches
  • ๐Ÿงฌ DSPy Optimizer - Auto-optimize prompts, gets smarter over time
  • ๐Ÿ—๏ธ Architecture Improvements - StrongContext, Modular Architecture, Middleware System, State Persistence, Parallel Execution, Event System, OpenAPI Tools, OpenTelemetry, Structured Logging, Fluent API, Pre-built Templates

Package download: https://www.nuget.org/packages/SharpAIKit/


๐Ÿ“– Documentation


English ไธญๆ–‡



โšก Quick Example

using SharpAIKit.LLM;

// Works with ANY OpenAI-compatible API
var client = LLMClientFactory.Create("api-key", "https://api.deepseek.com/v1", "deepseek-chat");

// Chat
var response = await client.ChatAsync("Hello!");

// Streaming
await foreach (var chunk in client.ChatStreamAsync("Tell me a story"))
{
    Console.Write(chunk);
}

๐Ÿ“ฆ Installation

dotnet add package SharpAIKit

๐ŸŒ Supported Providers

Provider URL
OpenAI https://api.openai.com/v1
DeepSeek https://api.deepseek.com/v1
Qwen (Alibaba) https://dashscope.aliyuncs.com/compatible-mode/v1
Mistral https://api.mistral.ai/v1
Yi (01.AI) https://api.lingyiwanwu.com/v1
Groq https://api.groq.com/openai/v1
Moonshot (Kimi) https://api.moonshot.cn/v1
Ollama (Local) http://localhost:11434
Any OpenAI-compatible Custom URL

โญ Star this project if it helps you!


๐ŸŽฏ Killer Features Beyond LangChain

๐Ÿ”ฎ Native C# Code Interpreter

Execute C# code directly using Roslyn - no Python dependency, blazing fast!

Why it's killer: LangChain's Code Interpreter depends on Python, deployment is troublesome and slow. SharpAIKit uses .NET's Roslyn compiler, executes in-memory, extremely fast.

using SharpAIKit.CodeInterpreter;

var interpreter = new RoslynCodeInterpreter();

// Math calculation
var result = await interpreter.ExecuteAsync<double>("Math.Pow(3, 5)");
Console.WriteLine($"3^5 = {result}");  // Output: 243

// Fibonacci sequence
var fibCode = """
    var n = 10;
    var fib = new List<int> { 0, 1 };
    for (int i = 2; i < n; i++) {
        fib.Add(fib[i-1] + fib[i-2]);
    }
    string.Join(", ", fib)
    """;
var fibResult = await interpreter.ExecuteAsync(fibCode);
Console.WriteLine(fibResult.Output);  // Output: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

๐Ÿ•ธ๏ธ SharpGraph

Graph-based orchestration with FSM - handle loops and complex workflows!

Why it's killer: LangChain's Chain is linear (DAG), hard to handle loops. SharpGraph uses Finite State Machine, supports loops and complex branches.

using SharpAIKit.Graph;

// Self-correcting loop graph: write code โ†’ run โ†’ check error โ†’ fix โ†’ run again
var graph = new SharpGraphBuilder("start", maxIterations: 20)
    .Node("start", async state => {
        state.Set("attempts", 0);
        state.NextNode = "write_code";
        return state;
    })
    .Node("write_code", async state => {
        // Write code logic
        state.NextNode = "execute_code";
        return state;
    })
    .Node("execute_code", async state => {
        // Execute code, handle errors
        state.NextNode = "check_result";
        return state;
    })
    .Node("check_result", async state => {
        // Check if result is valid
        if (valid) state.ShouldEnd = true;
        else state.NextNode = "fix_code";  // Loop back
        return state;
    })
    .Node("fix_code", async state => {
        state.NextNode = "write_code";  // Loop back to retry
        return state;
    })
    .Build();

var result = await graph.ExecuteAsync();

๐Ÿงฌ DSPy-style Optimizer

Automatically optimize prompts through iterative improvement!

Why it's killer: LangChain's Prompts are hardcoded, poor effects require manual tweaking. DSPy Optimizer automatically finds the best prompt through iterations.

using SharpAIKit.Optimizer;

var optimizer = new DSPyOptimizer(client)
{
    MaxIterations = 10,
    TargetScore = 0.9
};

// Add training examples
optimizer
    .AddExample("What is C#?", "C# is an object-oriented programming language...")
    .AddExample("What is Python?", "Python is an interpreted programming language...");

// Set evaluation metric
optimizer.SetMetric(Metrics.Contains);

// Optimize prompt
var initialPrompt = "Answer questions about programming languages: {input}";
var result = await optimizer.OptimizeAsync(initialPrompt);

Console.WriteLine($"Optimized: {result.OptimizedPrompt}");
Console.WriteLine($"Best score: {result.BestScore:F2}");
// The optimizer automatically adds few-shot examples and improves the prompt!

See ไธญๆ–‡ๆ–‡ๆกฃ or English Documentation for detailed examples.

๐Ÿ—๏ธ Architecture Improvements

SharpAIKit v0.1.0 introduces comprehensive architecture improvements:

  • StrongContext: Type-safe data passing with compile-time checking
  • Modular Architecture: IPlanner, IToolExecutor, IMemory interfaces
  • Middleware System: Retry, RateLimit, Logging, CircuitBreaker
  • State Persistence: Checkpoint support for task recovery
  • Parallel Execution: Fork/Join nodes for multi-branch execution
  • Event System: Lifecycle hooks (OnNodeStart/End/Error)
  • OpenAPI Tools: Auto-generate tool definitions from Swagger
  • OpenTelemetry: Built-in distributed tracing support
  • Structured Logging: Structured attributes for easy debugging
  • Fluent API: Elegant chain-style graph building
  • Pre-built Templates: ReAct, MapReduce, Reflection patterns

See Architecture Improvements Documentation for details.


๐Ÿ‘ฅ Core Authors

  1. Dustin Dong

    • Role: Creator & Lead Developer
    • GitHub: https://github.com/dxpython
    • Description: Sole creator of the SharpAIKit framework, responsible for architecture, core modules, RAG engine, agent system, DSPy-style optimizer, multimodal support, and overall ecosystem design.
  2. Evelyn-Liux

    • Role: Co-developer
    • GitHub: https://github.com/Evelyn-Liux
    • Description: Core collaborator contributing to framework refinement, architectural discussions, and ecosystem development. Recognized as an co-developer of the SharpAIKit project.

About

A modern, production-ready .NET AI toolkit with full support for OpenAI-compatible LLMs. Includes chat, streaming, embeddings, custom providers, and unified API architecture.

Resources

License

Stars

Watchers

Forks

Packages

No packages published