Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Documentation, Updated Access Modifiers, and Corrected Null Checking/Assertions #142

Merged
merged 15 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
awaescher marked this conversation as resolved.
Show resolved Hide resolved
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/
awaescher marked this conversation as resolved.
Show resolved Hide resolved
api/
55 changes: 55 additions & 0 deletions OllamaSharp.FunctionalTests/ChatTests.cs
awaescher marked this conversation as resolved.
Show resolved Hide resolved
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
Loading