Skip to content

Commit 9f1c034

Browse files
committed
feat: Initial commit
1 parent 7530115 commit 9f1c034

File tree

19 files changed

+1513
-3
lines changed

19 files changed

+1513
-3
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "nuget" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
all:
14+
patterns:
15+
- "*"

.github/workflows/auto-merge.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Auto-approve and auto-merge bot pull requests
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-merge:
13+
runs-on: ubuntu-latest
14+
if: ${{ (github.actor == 'dependabot[bot]' || github.actor == 'HavenDV') && github.repository_owner == 'tryAGI' }}
15+
steps:
16+
- name: Dependabot metadata
17+
if: ${{ github.actor == 'dependabot[bot]' }}
18+
id: metadata
19+
uses: dependabot/fetch-metadata@0fb21704c18a42ce5aa8d720ea4b912f5e6babef
20+
with:
21+
github-token: "${{ secrets.GITHUB_TOKEN }}"
22+
23+
- name: Show sender
24+
run: echo ${{ github.event.pull_request.sender }}
25+
26+
- name: Show triggering_actor
27+
run: echo ${{ github.triggering_actor }}
28+
29+
- name: Approve a PR
30+
run: gh pr review --approve "$PR_URL"
31+
env:
32+
PR_URL: ${{ github.event.pull_request.html_url }}
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Enable auto-merge
36+
run: gh pr merge --auto --merge "$PR_URL"
37+
env:
38+
PR_URL: ${{ github.event.pull_request.html_url }}
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/dotnet.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Build, test and publish
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build-test-publish:
9+
name: Build, test and publish
10+
uses: HavenDV/workflows/.github/workflows/dotnet_build-test-publish.yml@main
11+
with:
12+
generate-build-number: false
13+
conventional-commits-publish-conditions: false
14+
enable-caching: false
15+
additional-test-arguments: '--logger GitHubActions'
16+
secrets:
17+
nuget-key: ${{ secrets.NUGET_KEY }}

.github/workflows/pull-request.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Build and test
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build-test:
9+
name: Build abd test
10+
uses: HavenDV/workflows/.github/workflows/dotnet_build-test-publish.yml@main
11+
with:
12+
generate-build-number: false
13+
conventional-commits-publish-conditions: false
14+
enable-caching: false
15+
additional-test-arguments: '--logger GitHubActions'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
/.idea/

CLAUDE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
C# SDK originally based on the Ollama OpenAPI specification, generated using [OpenApiGenerator](https://github.com/HavenDV/OpenApiGenerator) (the predecessor to AutoSDK). This repository uses a **source-generator-based approach** rather than the CLI-based AutoSDK pipeline used by newer tryAGI SDKs. The code is generated at build time from the OpenAPI spec via a Roslyn source generator.
8+
9+
**Note:** This repo does not follow the standard AutoSDK pattern. It uses the older `OpenApiGenerator` NuGet package as a build-time source generator.
10+
11+
## Build Commands
12+
13+
```bash
14+
# Build the solution
15+
dotnet build Reka.sln
16+
17+
# Build for release (also produces NuGet package)
18+
dotnet build Reka.sln -c Release
19+
20+
# Run integration tests (uses Testcontainers, no API key required -- runs Ollama in Docker)
21+
dotnet test src/tests/Reka.IntegrationTests/Reka.IntegrationTests.csproj
22+
```
23+
24+
## Architecture
25+
26+
### Code Generation
27+
28+
Unlike newer tryAGI SDKs, there is **no `generate.sh` script** and **no `Generated/` directory**. Code is generated at build time by the `OpenApiGenerator` Roslyn source generator, which reads from `docs/openapi.yaml`.
29+
30+
- `docs/openapi.yaml` -- the OpenAPI spec consumed at build time
31+
- The `OpenApiGenerator` NuGet package (v0.7.1) generates client code as a source generator during compilation
32+
- Hand-written file: `src/libs/Reka/SourceGenerationContext.cs` -- JSON serializer context for trimming/AOT support
33+
34+
### Project Layout
35+
36+
| Project | Purpose |
37+
|---------|---------|
38+
| `src/libs/Reka/` | Main SDK library (`OllamaApiClient`), namespace `Ollama` |
39+
| `src/libs/Reka.Models/` | Separate models library, namespace `Ollama` |
40+
| `src/tests/Reka.IntegrationTests/` | Integration tests using Testcontainers (Docker-based) |
41+
42+
### Build Configuration
43+
44+
- **Targets:** `netstandard2.0;net4.6.2;net6.0;net8.0` (multi-target)
45+
- **Language:** C# preview with nullable reference types
46+
- **Signing:** Strong-named assemblies via `src/key.snk`
47+
- **Versioning:** Fixed version (`1.1.2`) set in `src/libs/Directory.Build.props` (no MinVer)
48+
- **Analysis:** All .NET analyzers enabled, AOT/trimming compatibility enforced
49+
- **Testing:** MSTest + FluentAssertions + Moq + Testcontainers
50+
51+
### Key Differences from Standard tryAGI SDKs
52+
53+
- Uses `OpenApiGenerator` source generator instead of `AutoSDK` CLI
54+
- Multi-target framework (netstandard2.0 through net8.0) instead of net10.0 only
55+
- No `src/helpers/` directory (no FixOpenApiSpec, GenerateDocs, or TrimmingHelper)
56+
- Tests use Docker via Testcontainers rather than API key-based integration
57+
- Namespace is `Ollama`, not `Reka`
58+
- Fixed version in Directory.Build.props instead of MinVer-based versioning

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 tryAGI
3+
Copyright (c) 2024 tryAGI, Andreas Wäscher and David Miguel Lozano
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# Reka
2-
Generated C# SDK based on Reka OpenAPI specification
1+
# Ollama SDK for .NET 🦙
2+
3+
Generated C# SDK based on Ollama OpenAPI specification and [official docs](https://github.com/jmorganca/ollama/blob/main/docs/api.md) using [OpenApiGenerator](https://github.com/HavenDV/OpenApiGenerator).
4+
5+
## Features 🔥
6+
7+
- Intuitive API client: Set up and interact with Ollama in just a few lines of code.
8+
- API endpoint coverage: Support for all Ollama API endpoints including chats, embeddings, listing models, pulling and creating new models, and more.
9+
- Real-time streaming: Stream responses directly to your application.
10+
- Progress reporting: Get real-time progress feedback on tasks like model pulling.
11+
12+
## Usage
13+
14+
### Initializing
15+
16+
```csharp
17+
var ollama = new OllamaApiClient();
18+
19+
var models = await ollama.ListModelsAsync();
20+
21+
// Pulling a model and reporting progress
22+
await ollama.PullModelAsync("mistral", status => Console.WriteLine($"({status.Percent}%) {status.Status}"));
23+
24+
// Streaming a completion directly into the console
25+
// keep reusing the context to keep the chat topic going
26+
IList<long>? context = null;
27+
var enumerable = api.GetCompletionAsync("mistral", "How are you today?");
28+
await foreach (var response in enumerable)
29+
{
30+
Console.Write(response.Response);
31+
32+
context = response.Context;
33+
}
34+
35+
var lastResponse = await api.GetCompletionAsync("mistral", "How are you today?", stream: false).WaitAsync();
36+
context = response.lastResponse;
37+
Console.WriteLine(lastResponse.Response);
38+
39+
var chat = container.ApiClient.Chat("mistral");
40+
while (true)
41+
{
42+
var message = await chat.SendAsync("answer 123");
43+
44+
Console.WriteLine(message.Content);
45+
46+
var newMessage = Console.ReadLine();
47+
await chat.Send(newMessage);
48+
}
49+
```
50+
51+
## Credits
52+
53+
Icon and name were reused from the amazing [Ollama project](https://github.com/jmorganca/ollama).
54+
The project was forked from [this repository](https://github.com/awaescher/OllamaSharp),
55+
after which automatic code generation was applied based on [this OpenAPI specification](https://github.com/davidmigloz/langchain_dart/blob/main/packages/ollama_dart/oas/ollama-curated.yaml)
56+
(in the future it will be replaced by the official one, if one appears)

Reka.slnx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Solution>
2+
<Folder Name="/libs/">
3+
<File Path="src/libs/Directory.Build.props" />
4+
<Project Path="src/libs/Ollama.Models/Ollama.Models.csproj" />
5+
<Project Path="src/libs/Ollama/Ollama.csproj" />
6+
</Folder>
7+
<Folder Name="/Solution Items/">
8+
<File Path=".github/workflows/dotnet.yml" />
9+
<File Path=".github/workflows/pull-request.yml" />
10+
<File Path=".gitignore" />
11+
<File Path="docs/openapi.yaml" />
12+
<File Path="LICENSE" />
13+
<File Path="README.md" />
14+
<File Path="src/Directory.Build.props" />
15+
</Folder>
16+
<Folder Name="/tests/">
17+
<Project Path="src/tests/Ollama.IntegrationTests/Ollama.IntegrationTests.csproj" />
18+
</Folder>
19+
</Solution>

assets/nuget_icon.png

130 KB
Loading

0 commit comments

Comments
 (0)