Skip to content

Commit

Permalink
.NET SDK (#80)
Browse files Browse the repository at this point in the history
* init

* minor

* fix

* fix

* add interrupt to demos

* fix

* fixes

* fixes

* fixes

* fix

* fixes

* fix

* add .net2.1 testing

* fix

* fix

* release
  • Loading branch information
laves authored Jan 31, 2025
1 parent 77d9ae7 commit 2aed1db
Show file tree
Hide file tree
Showing 28 changed files with 4,497 additions and 20 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dotnet-codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: .NET Codestyle

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- 'binding/dotnet/**/*.cs'
- 'demo/dotnet/**/*.cs'
- '.github/workflows/dotnet-codestyle.yml'
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]
paths:
- 'binding/dotnet/**/*.cs'
- 'demo/dotnet/**/*.cs'
- '.github/workflows/dotnet-codestyle.yml'

jobs:
check-dotnet-codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up .NET 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Run Binding Codestyle
run: dotnet format --verify-no-changes
working-directory: binding/dotnet

- name: Run Demo Codestyle
run: dotnet format --verify-no-changes
working-directory: demo/dotnet
52 changes: 52 additions & 0 deletions .github/workflows/dotnet-demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: .NET Demos

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '.github/workflows/dotnet-demos.yml'
- 'demo/dotnet/**'
- '!demo/dotnet/README.md'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/dotnet-demos.yml'
- 'demo/dotnet/**'
- '!demo/dotnet/README.md'

defaults:
run:
working-directory: demo/dotnet/PicoLLMDemo

jobs:
build-self-hosted:
runs-on: ${{ matrix.machine }}

strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows, pv-windows-arm64 ]
include:
- xpu: gpu
machine: pv-linux
- xpu: gpu
machine: pv-windows
- xpu: gpu
machine: pv-windows-igpu

steps:
- uses: actions/checkout@v3

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/04-d5f2aa0/phi2-290.pllm -o phi2-290.pllm

- name: Package restore
run: dotnet restore

- name: Build completion demo
run: dotnet build -c CompletionDemo.Release

- name: Run completion demo
run: dotnet run -c CompletionDemo.Release -- --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --model_path phi2-290.pllm --completion_token_limit 10 --prompt "Hello my name is" --device ${{matrix.xpu}}
82 changes: 82 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: .NET

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '.github/workflows/dotnet.yml'
- 'binding/dotnet/**'
- '!binding/dotnet/README.md'
- 'lib/linux/**'
- 'lib/mac/**'
- 'lib/raspberry-pi/**'
- 'lib/windows/**'
- 'resources/.test/**'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/dotnet.yml'
- 'binding/dotnet/**'
- '!binding/dotnet/README.md'
- 'lib/linux/**'
- 'lib/mac/**'
- 'lib/raspberry-pi/**'
- 'lib/windows/**'
- 'resources/.test/**'

defaults:
run:
working-directory: binding/dotnet

jobs:
build-self-hosted:
runs-on: ${{ matrix.machine }}
env:
ACCESS_KEY: ${{secrets.PV_VALID_ACCESS_KEY}}
MODEL_PATH: ../../../../phi2-290.pllm
DEVICE: ${{matrix.xpu}}

strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
dotnet:
- binding-framework: net8.0
test-framework: net8.0
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows, pv-windows-arm64 ]
include:
- xpu: gpu
dotnet:
binding-framework: net8.0
test-framework: net8.0
machine: pv-windows
- dotnet:
binding-framework: netstandard2.0
test-framework: netcoreapp2.1
xpu: cpu
machine: pv-windows
- xpu: gpu
dotnet:
binding-framework: net8.0
test-framework: net8.0
machine: pv-linux
- xpu: gpu
dotnet:
binding-framework: net8.0
test-framework: net8.0
machine: pv-windows-igpu


steps:
- uses: actions/checkout@v3

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/04-d5f2aa0/phi2-290.pllm -o phi2-290.pllm
working-directory: binding/dotnet

- name: Build binding
run: dotnet build PicoLLM/PicoLLM.csproj --framework ${{ matrix.dotnet.binding-framework }}

- name: Test
run: dotnet test --framework ${{ matrix.dotnet.test-framework }} -v n
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![npm](https://img.shields.io/npm/v/@picovoice/picollm-web?label=npm%20%5Bweb%5D)](https://www.npmjs.com/package/@picovoice/picollm-web)
[![CocoaPods](https://img.shields.io/cocoapods/v/picoLLM-iOS)](https://cocoapods.org/pods/picoLLM-iOS)<!-- markdown-link-check-disable-line -->
[![PyPI](https://img.shields.io/pypi/v/picollm)](https://pypi.org/project/picollm/)
[![Nuget](https://img.shields.io/nuget/v/picollm)](https://www.nuget.org/packages/PicoLLM/)

Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)

Expand Down Expand Up @@ -43,13 +44,15 @@ models. picoLLM Inference Engine is:
- [AccessKey](#accesskey)
- [Demos](#demos)
- [Python](#python-demos)
- [.NET](#net-demos)
- [Node.js](#nodejs-demos)
- [Android](#android-demos)
- [iOS](#ios-demos)
- [Web](#web-demos)
- [C](#c-demos)
- [SDKs](#sdks)
- [Python](#python-sdk)
- [.NET](#net-sdk)
- [Node.js](#nodejs-sdk)
- [Android](#android-sdk)
- [iOS](#ios-sdk)
Expand Down Expand Up @@ -132,6 +135,8 @@ picoLLM Inference Engine supports the following open-weight models. The models a
- `phi2`
- Phi-3
- `phi3`
- Phi-3.5
- `phi3.5`

## AccessKey

Expand Down Expand Up @@ -162,6 +167,20 @@ downloaded from Picovoice Console, and `${PROMPT}` with a prompt string.

For more information about Python demos go to [demo/python](demo/python/README.md).

### .NET Demos

From [demo/dotnet/PicoLLMDemo](demo/dotnet/PicoLLMDemo) build and run the demo:

```console
dotnet build -c CompletionDemo.Release
dotnet run -c CompletionDemo.Release -- --access_key ${ACCESS_KEY} --model_path ${MODEL_PATH} --prompt ${PROMPT}
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_PATH}` with the path to a model file
downloaded from Picovoice Console, and `${PROMPT}` with a prompt string.

For more information about .NET demos go to [demo/dotnet](demo/dotnet).

### Node.js Demos

Install the demo package:
Expand Down Expand Up @@ -270,6 +289,38 @@ Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_PAT
downloaded from Picovoice Console, and `${PROMPT}` to a prompt string. Finally, when done be sure to explicitly release
the resources using `pllm.release()`.

### .NET SDK

Install the .NET SDK using NuGet or the dotnet CLI:

```console
dotnet add package PicoLLM
```

Create an instance of the engine and generate a prompt completion:

```csharp
using Pv;

PicoLLM pllm = PicoLLM.Create("${ACCESS_KEY}", "${MODEL_PATH}");

PicoLLMCompletion res = pllm.Generate('${PROMPT}');
Console.WriteLine(res.Completion);
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_PATH}` to the path to a model file
downloaded from Picovoice Console, and `${PROMPT}` to a prompt string.

`PicoLLM` will have its resources freed by the garbage collector, but to have resources freed immediately after use,
wrap it in a using statement or call `.Dispose()` directly:

```csharp
using(PicoLLM pllm = PicoLLM.Create(accessKey, modelPath))
{
// .. picoLLM usage here
}
```

### Node.js SDK

Install the Node.js SDK:
Expand Down
Loading

0 comments on commit 2aed1db

Please sign in to comment.