Skip to content

Commit

Permalink
Merge pull request #49 from milbk/GetVersion-1
Browse files Browse the repository at this point in the history
Add GetVersion
  • Loading branch information
awaescher authored Jun 25, 2024
2 parents 5219e40 + 4dc9b71 commit 51c165e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/IOllamaApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
Expand Down Expand Up @@ -236,4 +237,10 @@ Task<ConversationContext> StreamCompletion(
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
Task<bool> IsRunning(CancellationToken cancellationToken = default);

/// <summary>
/// Get the version of Ollama
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
Task<Version> GetVersion(CancellationToken cancellationToken = default);
}
7 changes: 7 additions & 0 deletions src/OllamaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using OllamaSharp.Models;
Expand Down Expand Up @@ -249,6 +250,12 @@ public async Task<bool> IsRunning(CancellationToken cancellationToken = default)
return !string.IsNullOrWhiteSpace(stringContent);
}

public async Task<Version> GetVersion(CancellationToken cancellationToken = default)
{
var data = await GetAsync<JsonNode>("api/version", cancellationToken);
return Version.Parse(data["version"]?.ToString());
}

private async Task<ConversationContext> GenerateCompletion(
GenerateCompletionRequest generateRequest,
IResponseStreamer<GenerateCompletionResponseStream?> streamer,
Expand Down
6 changes: 6 additions & 0 deletions test/TestOllamaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ internal void DefineChatResponse(ChatRole role, string answer)
}

public Task<bool> IsRunning(CancellationToken cancellationToken = default) => Task.FromResult(true);

public Task<Version> GetVersion(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public IAsyncEnumerable<CreateModelResponse?> CreateModel(CreateModelRequest request, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
Expand Down

0 comments on commit 51c165e

Please sign in to comment.