Skip to content

Commit

Permalink
Merge pull request #142 from JerrettDavis/feature/add-documentation
Browse files Browse the repository at this point in the history
Added Documentation, Updated Access Modifiers, and Corrected Null Checking/Assertions
  • Loading branch information
awaescher authored Nov 25, 2024
2 parents 5137316 + 0eeede9 commit 771afda
Show file tree
Hide file tree
Showing 50 changed files with 1,091 additions and 234 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:
pull_request:
branches: [ "main", "master" ]
paths: [ 'src/**' ]

jobs:

jobs:
build:

runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
run: dotnet build --no-restore --configuration=Release /p:Version=${{steps.gitversion.outputs.semVer}}

- name: Test
run: dotnet test --no-build --configuration=Release --verbosity normal
run: dotnet test --no-build --configuration=Release --verbosity normal --filter 'FullyQualifiedName!~FunctionalTests'

- name: pack nuget packages
run: dotnet pack --output nupkgs --configuration=Release --no-restore --no-build /p:PackageVersion=${{steps.gitversion.outputs.semVer}}
Expand All @@ -59,4 +59,4 @@ jobs:

- name: upload nuget package
if: github.event_name != 'pull_request'
run: dotnet nuget push nupkgs/OllamaSharp*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
run: dotnet nuget push nupkgs/OllamaSharp*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
40 changes: 40 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: docfx Build and Deploy

on:
push:
branches: [ "main" ]
workflow_dispatch:

permissions:
actions: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
publish-docs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Dotnet Setup
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x

- run: dotnet tool update -g docfx
- run: docfx ./docfx.json

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './_site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,8 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
/.idea
/.idea

# DocFX
_site/
api/
55 changes: 55 additions & 0 deletions OllamaSharp.FunctionalTests/ChatTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using FluentAssertions;
using Microsoft.Extensions.AI;

namespace OllamaSharp.FunctionalTests;

public class ChatTests
{
private readonly Uri _baseUri = new("http://localhost:11434");
private readonly string _model = "llama3.2:1b";

#pragma warning disable NUnit1032
private OllamaApiClient _client = null!;
private Chat _chat = null!;
#pragma warning restore NUnit1032

[SetUp]
public async Task Setup()
{
// Set up the test environment
_client = new OllamaApiClient(_baseUri);
_chat = new Chat(_client);

await _client.PullIfNotExistsAsync(_model);
}

[TearDown]
public Task Teardown()
{
// Clean up the test environment
((IChatClient?)_client)?.Dispose();

return Task.CompletedTask;
}


[Test]
public async Task SendAsync_ShouldSucceed()
{
// Arrange
_client.SelectedModel = _model;

// Act
var response = await _chat
.SendAsync("What is the ultimate answer to " +
"life, the universe, and everything, as specified in " +
"a Hitchhikers Guide to the Galaxy. " +
"Provide only the answer.",
CancellationToken.None)
.StreamToEndAsync();

// Assert
response.Should().NotBeNullOrEmpty();
response.Should().ContainAny("42", "forty-two", "forty two");
}
}
18 changes: 18 additions & 0 deletions OllamaSharp.FunctionalTests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OllamaSharp.Models;

namespace OllamaSharp.FunctionalTests;

public static class Helpers
{
public static async Task PullIfNotExistsAsync(
this IOllamaApiClient client,
string model)
{
var modelExists = (await client.ListLocalModelsAsync())
.Any(m => m.Name == model);

if (!modelExists)
await client.PullModelAsync(new PullModelRequest { Model = model })
.ToListAsync();
}
}
Loading

0 comments on commit 771afda

Please sign in to comment.