Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dclipca committed Jan 26, 2025
1 parent eb6ff14 commit 4045ef0
Show file tree
Hide file tree
Showing 30 changed files with 948 additions and 6 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish-nuget-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish NuGet Package

on:
release:
types: [published]
workflow_dispatch: # Enables the "Run workflow" button

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Get version from source
id: get-version
run: |
VERSION=$(cat SpongeEngine.LLMSharp.Core/SpongeEngine.LLMSharp.Core.csproj | grep '<Version>' | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Using version: $VERSION"
- name: Restore dependencies
run: dotnet restore

- name: Build for .NET 6.0
run: dotnet build --configuration Release --framework net6.0 --no-restore

- name: Build for .NET 7.0
run: dotnet build --configuration Release --framework net7.0 --no-restore

- name: Build for .NET 8.0
run: dotnet build --configuration Release --framework net8.0 --no-restore

- name: Pack NuGet Package
run: dotnet pack --configuration Release --output ./output /p:Version=${{ env.VERSION }}

- name: Publish NuGet Package
run: dotnet nuget push ./output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ StyleCopReport.xml
*.pgc
*.pgd
*.rsp
# but not Directory.Build.rsp, as it configures directory-level build defaults
!Directory.Build.rsp
*.sbr
*.tlb
*.tli
Expand Down Expand Up @@ -397,4 +395,5 @@ FodyWeavers.xsd
*.msp

# JetBrains Rider
*.sln.iml
.idea/
*.sln.iml
67 changes: 67 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Contributing to LLMSharp.Core

## Publishing to NuGet

### Prerequisites
1. Create a NuGet account at https://www.nuget.org
2. Generate an API key:
- Go to https://www.nuget.org/account/apikeys
- Click "Create"
- Name: "SpongeEngine.LLMSharp.Core Publishing" (or your preferred name)
- Expiration: 365 days
- Select "Push new packages and package versions"
- Glob Pattern: "SpongeEngine.LLMSharp.Core*"
- Save the generated key securely

### Publishing Process
1. Update version in `SpongeEngine.LLMSharp/SpongeEngine.LLMSharp.csproj`:
```xml
<Version>1.0.1</Version> <!-- Change this to new version -->
```

2. Clean and pack:
```bash
dotnet clean
dotnet pack -c Release
```

3. Push to NuGet:
```bash
dotnet nuget push .\SpongeEngine.LLMSharp\bin\Release\SpongeEngine.LLMSharp.1.0.1.nupkg --api-key YOUR_API_KEY --source https://api.nuget.org/v3/index.json
```
Replace:
- `1.0.0` with your new version number
- `YOUR_API_KEY` with your NuGet API key

4. Wait 15-30 minutes for the package to appear on NuGet.org

### Version Guidelines
- Use [Semantic Versioning](https://semver.org/):
- MAJOR version for incompatible API changes
- MINOR version for backwards-compatible functionality
- PATCH version for backwards-compatible bug fixes

## Development Guidelines

### Code Style
- Use C# latest features and best practices
- Follow Microsoft's [C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions)
- Use meaningful names for variables, methods, and classes
- Add XML documentation comments for public APIs

### Testing
1. Write unit tests for new features
2. Ensure all tests pass before submitting PR:
```bash
dotnet test
```

### Pull Request Process
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Update documentation and tests
5. Submit a pull request

## Questions?
Open an issue on GitHub if you have questions or need help.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2025 Sponge Engine
Copyright (c) 2024 Sponge Engine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# LLMSharp.Core
# LLMSharp.Core (In Progress)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<TargetFrameworks>net8.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<Version>0.0.1</Version>
<PackageId>SpongeEngine.SpongeLLM.Core.Tests</PackageId>
<Authors>SpongeEngine.SpongeLLM.Core.Tests</Authors>
<AssemblyName>SpongeEngine.SpongeLLM.Core.Tests</AssemblyName>
<RootNamespace>SpongeEngine.SpongeLLM.Core.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="8.0.1" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.5.1" />
<PackageReference Include="MicroElements.Testing.xUnit" Version="0.4.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="WireMock.Net" Version="1.7.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\SpongeEngine.SpongeLLM.Core\SpongeEngine.SpongeLLM.Core.csproj" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions SpongeEngine.SpongeLLM.Core.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpongeEngine.SpongeLLM.Core", "SpongeEngine.SpongeLLM.Core\SpongeEngine.SpongeLLM.Core.csproj", "{3AA31654-601E-4A2D-ABAB-66B2C99C9886}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpongeEngine.SpongeLLM.Core.Tests", "SpongeEngine.SpongeLLM.Core.Tests\SpongeEngine.SpongeLLM.Core.Tests.csproj", "{B4C06852-1A11-45B9-8E83-CF7ABEE36F12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3AA31654-601E-4A2D-ABAB-66B2C99C9886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AA31654-601E-4A2D-ABAB-66B2C99C9886}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AA31654-601E-4A2D-ABAB-66B2C99C9886}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AA31654-601E-4A2D-ABAB-66B2C99C9886}.Release|Any CPU.Build.0 = Release|Any CPU
{B4C06852-1A11-45B9-8E83-CF7ABEE36F12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4C06852-1A11-45B9-8E83-CF7ABEE36F12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4C06852-1A11-45B9-8E83-CF7ABEE36F12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4C06852-1A11-45B9-8E83-CF7ABEE36F12}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Exceptions/LLMSharpException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace SpongeEngine.LLMSharp.Core.Exceptions
{
public class LlmSharpException : Exception
{
public int? StatusCode { get; }
public string? ResponseContent { get; }

public LlmSharpException(
string message,
int? statusCode = null,
string? responseContent = null,
Exception? innerException = null)
: base(message, innerException)
{
StatusCode = statusCode;
ResponseContent = responseContent;
}
}
}
16 changes: 16 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Exceptions/ModelNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace SpongeEngine.LLMSharp.Core.Exceptions
{
public class ModelNotFoundException : LlmSharpException
{
public string ModelId { get; }

public ModelNotFoundException(
string modelId,
string provider,
string? message = null)
: base(message ?? $"Model {modelId} not found")
{
ModelId = modelId;
}
}
}
13 changes: 13 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Exceptions/ProviderException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SpongeEngine.LLMSharp.Core.Exceptions
{
public class ProviderException : LlmSharpException
{
public ProviderException(
string message,
string provider,
Exception? innerException = null)
: base(message, innerException: innerException)
{
}
}
}
15 changes: 15 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Exceptions/ValidationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace SpongeEngine.LLMSharp.Core.Exceptions
{
public class ValidationException : LlmSharpException
{
public IDictionary<string, string> ValidationErrors { get; }

public ValidationException(
IDictionary<string, string> errors,
string provider)
: base("Validation failed")
{
ValidationErrors = errors;
}
}
}
25 changes: 25 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Interfaces/IChatService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using SpongeEngine.LLMSharp.Core.Models;

namespace SpongeEngine.LLMSharp.Core.Interfaces
{
/// <summary>
/// Interface for chat-style interactions
/// </summary>
public interface IChatService
{
/// <summary>
/// Performs chat completion with a list of messages
/// </summary>
Task<ChatResponse> ChatCompleteAsync(ChatRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Streams chat response tokens as they're generated
/// </summary>
IAsyncEnumerable<ChatToken> StreamChatAsync(ChatRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Gets chat model configuration and limitations
/// </summary>
Task<ChatModelConfig> GetModelConfigAsync(string modelId, CancellationToken cancellationToken = default);
}
}
25 changes: 25 additions & 0 deletions SpongeEngine.SpongeLLM.Core/Interfaces/IEmbeddingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using SpongeEngine.LLMSharp.Core.Models;

namespace SpongeEngine.LLMSharp.Core.Interfaces
{
/// <summary>
/// Interface for generating text embeddings
/// </summary>
public interface IEmbeddingService
{
/// <summary>
/// Generates embeddings for the input text
/// </summary>
Task<EmbeddingResponse> CreateEmbeddingAsync(EmbeddingRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Creates embeddings for multiple texts in batch
/// </summary>
Task<BatchEmbeddingResponse> CreateEmbeddingsAsync(BatchEmbeddingRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Gets embedding model information including vector dimensions
/// </summary>
Task<EmbeddingModelInfo> GetModelInfoAsync(string modelId, CancellationToken cancellationToken = default);
}
}
Loading

0 comments on commit 4045ef0

Please sign in to comment.