Skip to content

Commit 21be41d

Browse files
committed
update SharpAIKit
0 parents  commit 21be41d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+11779
-0
lines changed

.editorconfig

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# EditorConfig for SharpAIKit
2+
# https://editorconfig.org
3+
4+
root = true
5+
6+
# All files
7+
[*]
8+
indent_style = space
9+
indent_size = 4
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
# C# files
16+
[*.cs]
17+
indent_size = 4
18+
19+
# C# code style settings
20+
dotnet_sort_system_directives_first = true
21+
dotnet_separate_import_directive_groups = false
22+
23+
# Use "var" everywhere
24+
csharp_style_var_for_built_in_types = true:suggestion
25+
csharp_style_var_when_type_is_apparent = true:suggestion
26+
csharp_style_var_elsewhere = true:suggestion
27+
28+
# Prefer expression-bodied members
29+
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
30+
csharp_style_expression_bodied_constructors = when_on_single_line:suggestion
31+
csharp_style_expression_bodied_operators = when_on_single_line:suggestion
32+
csharp_style_expression_bodied_properties = when_on_single_line:suggestion
33+
csharp_style_expression_bodied_indexers = when_on_single_line:suggestion
34+
csharp_style_expression_bodied_accessors = when_on_single_line:suggestion
35+
36+
# Prefer pattern matching
37+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
38+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
39+
40+
# Null checking preferences
41+
csharp_style_throw_expression = true:suggestion
42+
csharp_style_conditional_delegate_call = true:suggestion
43+
44+
# New line preferences
45+
csharp_new_line_before_open_brace = all
46+
csharp_new_line_before_else = true
47+
csharp_new_line_before_catch = true
48+
csharp_new_line_before_finally = true
49+
50+
# Indentation preferences
51+
csharp_indent_case_contents = true
52+
csharp_indent_switch_labels = true
53+
54+
# Space preferences
55+
csharp_space_after_cast = false
56+
csharp_space_after_keywords_in_control_flow_statements = true
57+
csharp_space_between_method_declaration_parameter_list_parentheses = false
58+
csharp_space_between_method_call_parameter_list_parentheses = false
59+
60+
# XML project files
61+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
62+
indent_size = 2
63+
64+
# XML config files
65+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
66+
indent_size = 2
67+
68+
# JSON files
69+
[*.json]
70+
indent_size = 2
71+
72+
# YAML files
73+
[*.{yml,yaml}]
74+
indent_size = 2
75+
76+
# Markdown files
77+
[*.md]
78+
trim_trailing_whitespace = false
79+
80+
# Shell scripts
81+
[*.sh]
82+
end_of_line = lf
83+

.github/workflows/build.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: '8.0.x'
21+
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
25+
- name: Build
26+
run: dotnet build --no-restore --configuration Release
27+
28+
- name: Run tests
29+
run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage"
30+
31+
- name: Upload coverage reports
32+
uses: codecov/codecov-action@v3
33+
with:
34+
files: ./tests/**/coverage.cobertura.xml
35+
fail_ci_if_error: false
36+
37+
pack:
38+
runs-on: ubuntu-latest
39+
needs: build
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
45+
- name: Setup .NET
46+
uses: actions/setup-dotnet@v4
47+
with:
48+
dotnet-version: '8.0.x'
49+
50+
- name: Restore dependencies
51+
run: dotnet restore
52+
53+
- name: Create NuGet package
54+
run: dotnet pack src/SharpAIKit/SharpAIKit.csproj --configuration Release --output ./nupkg
55+
56+
- name: Upload NuGet package artifact
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: nuget-package
60+
path: ./nupkg/*.nupkg
61+
retention-days: 7
62+

.gitignore

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Build results
2+
[Dd]ebug/
3+
[Dd]ebugPublic/
4+
[Rr]elease/
5+
[Rr]eleases/
6+
x64/
7+
x86/
8+
[Ww][Ii][Nn]32/
9+
[Aa][Rr][Mm]/
10+
[Aa][Rr][Mm]64/
11+
bld/
12+
[Bb]in/
13+
[Oo]bj/
14+
[Ll]og/
15+
[Ll]ogs/
16+
17+
# Visual Studio
18+
.vs/
19+
*.user
20+
*.suo
21+
*.userosscache
22+
*.sln.docstates
23+
*.rsuser
24+
25+
# Rider
26+
.idea/
27+
*.sln.iml
28+
29+
# VS Code
30+
.vscode/
31+
32+
# NuGet
33+
*.nupkg
34+
*.snupkg
35+
**/[Pp]ackages/*
36+
!**/[Pp]ackages/build/
37+
*.nuget.props
38+
*.nuget.targets
39+
project.lock.json
40+
project.fragment.lock.json
41+
artifacts/
42+
43+
# .NET Core
44+
project.lock.json
45+
project.fragment.lock.json
46+
artifacts/
47+
48+
# Test Results
49+
[Tt]est[Rr]esult*/
50+
[Bb]uild[Ll]og.*
51+
*.trx
52+
TestResult.xml
53+
coverage*.json
54+
coverage*.xml
55+
coverage*.info
56+
57+
# NCrunch
58+
_NCrunch_*
59+
.*crunch*.local.xml
60+
nCrunchTemp_*
61+
62+
# Publish
63+
*.publish.xml
64+
*.azurePubxml
65+
*.pubxml
66+
*.publishproj
67+
68+
# OS generated files
69+
.DS_Store
70+
.DS_Store?
71+
._*
72+
.Spotlight-V100
73+
.Trashes
74+
ehthumbs.db
75+
Thumbs.db
76+
77+
# User-specific files
78+
*.env
79+
*.env.local
80+
appsettings.Development.json
81+

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MIT License
2+
3+
Copyright (c) 2025
4+
SharpAIKit Authors and Contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the “Software”), to deal
8+
in the Software without restriction, including without limitation the rights to:
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10+
of the Software, and to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software, along with attribution to
15+
“SharpAIKit Authors and Contributors”.
16+
17+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
20+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21+
DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT,
22+
OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
23+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<div align="center">
2+
3+
## SharpAIKit: A Unified AI/LLM Toolkit for .NET
4+
<img src="imgs/logo.jpg" alt="SharpAIKit Logo" width="900">
5+
6+
[![.NET Version](https://img.shields.io/badge/.NET-8.0-512BD4?style=for-the-badge&logo=dotnet&logoColor=white)](https://dotnet.microsoft.com/)
7+
[![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)](LICENSE)
8+
[![NuGet](https://img.shields.io/badge/NuGet-v2.0.0-004880?style=for-the-badge&logo=nuget&logoColor=white)](https://www.nuget.org/)
9+
[![Build](https://img.shields.io/badge/Build-Passing-brightgreen?style=for-the-badge)](https://github.com/)
10+
11+
<br/>
12+
13+
**One API, All LLMs** — Supports OpenAI, DeepSeek, Qwen, Mistral, Yi, Groq and any OpenAI-compatible API
14+
15+
**🎯 Killer Features Beyond LangChain:**
16+
- 🔮 **Native C# Code Interpreter** - Execute C# code directly, no Python needed
17+
- 🕸️ **SharpGraph** - Graph orchestration with loops and complex branches
18+
- 🧬 **DSPy Optimizer** - Auto-optimize prompts, gets smarter over time
19+
20+
<br/>
21+
22+
---
23+
24+
### 📖 Documentation
25+
26+
<br/>
27+
28+
[![English](https://img.shields.io/badge/English-Documentation-blue?style=for-the-badge&logo=readme&logoColor=white)](README_EN.md)
29+
[![中文](https://img.shields.io/badge/中文-文档-red?style=for-the-badge&logo=readme&logoColor=white)](README_CN.md)
30+
31+
<br/>
32+
33+
---
34+
35+
</div>
36+
37+
## ⚡ Quick Example
38+
39+
```csharp
40+
using SharpAIKit.LLM;
41+
42+
// Works with ANY OpenAI-compatible API
43+
var client = LLMClientFactory.Create("api-key", "https://api.deepseek.com/v1", "deepseek-chat");
44+
45+
// Chat
46+
var response = await client.ChatAsync("Hello!");
47+
48+
// Streaming
49+
await foreach (var chunk in client.ChatStreamAsync("Tell me a story"))
50+
{
51+
Console.Write(chunk);
52+
}
53+
```
54+
55+
## 📦 Installation
56+
57+
```bash
58+
dotnet add package SharpAIKit
59+
```
60+
61+
## 🌐 Supported Providers
62+
63+
| Provider | URL |
64+
|:---------|:----|
65+
| OpenAI | `https://api.openai.com/v1` |
66+
| DeepSeek | `https://api.deepseek.com/v1` |
67+
| Qwen (Alibaba) | `https://dashscope.aliyuncs.com/compatible-mode/v1` |
68+
| Mistral | `https://api.mistral.ai/v1` |
69+
| Yi (01.AI) | `https://api.lingyiwanwu.com/v1` |
70+
| Groq | `https://api.groq.com/openai/v1` |
71+
| Moonshot (Kimi) | `https://api.moonshot.cn/v1` |
72+
| Ollama (Local) | `http://localhost:11434` |
73+
| **Any OpenAI-compatible** | Custom URL |
74+
75+
---
76+
77+
<div align="center">
78+
79+
**⭐ Star this project if it helps you!**
80+
81+
---
82+
83+
## 🎯 Killer Features
84+
85+
### 🔮 Native C# Code Interpreter
86+
Execute C# code directly using Roslyn - no Python dependency, blazing fast!
87+
88+
```csharp
89+
var interpreter = new RoslynCodeInterpreter();
90+
var result = await interpreter.ExecuteAsync<double>("Math.Pow(3, 5)");
91+
// Result: 243
92+
```
93+
94+
### 🕸️ SharpGraph
95+
Graph-based orchestration with FSM - handle loops and complex workflows!
96+
97+
```csharp
98+
var graph = new SharpGraphBuilder("start")
99+
.Node("start", async state => { ... })
100+
.Edge("start", "next", condition: state => ...)
101+
.Build();
102+
```
103+
104+
### 🧬 DSPy-style Optimizer
105+
Automatically optimize prompts through iterative improvement!
106+
107+
```csharp
108+
var optimizer = new DSPyOptimizer(client)
109+
.AddExample("input", "expected output")
110+
.SetMetric(Metrics.Contains);
111+
var result = await optimizer.OptimizeAsync("initial prompt");
112+
```
113+
114+
See [中文文档](README_CN.md) for detailed examples.
115+
116+
</div>

0 commit comments

Comments
 (0)