Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/OllamaSharp/OllamaApiClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static async Task RequestModelUnloadAsync(this IOllamaApiClient client, s
{
var request = new GenerateRequest
{
Model = client.SelectedModel,
Model = model,
Stream = false,
KeepAlive = "0s"
};
Expand Down Expand Up @@ -131,4 +131,4 @@ public static Task<ShowModelResponse> ShowModelAsync(this IOllamaApiClient clien
/// <returns>A task that represents the asynchronous push operation.</returns>
public static Task PushBlobAsync(this IOllamaApiClient client, byte[] bytes, CancellationToken cancellationToken = default)
=> client.PushBlobAsync($"sha256:{BitConverter.ToString(SHA256.Create().ComputeHash(bytes)).Replace("-", string.Empty).ToLower()}", bytes, cancellationToken);
}
}
31 changes: 30 additions & 1 deletion test/OllamaApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,35 @@ public async Task Returns_Streamed_Responses_At_Once()
}
}

/// <summary>
/// Contains tests for the RequestModelUnload extension method.
/// </summary>
public class RequestModelUnloadMethod : OllamaApiClientTests
{
/// <summary>
/// Verifies that the explicitly requested model is unloaded instead of the selected model.
/// </summary>
[Test, NonParallelizable]
public async Task Uses_Requested_Model()
{
_client.SelectedModel = "selected-model";
_response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent("""{"model":"requested-model","response":"","done":true}""")
};

await _client.RequestModelUnloadAsync("requested-model", CancellationToken.None);

_requestContent.ShouldNotBeNull();
using var requestJson = JsonDocument.Parse(_requestContent);
var root = requestJson.RootElement;
root.GetProperty("model").GetString().ShouldBe("requested-model");
root.GetProperty("stream").GetBoolean().ShouldBeFalse();
root.GetProperty("keep_alive").GetString().ShouldBe("0s");
}
}

/// <summary>
/// Contains tests for the Complete method.
/// </summary>
Expand Down Expand Up @@ -838,4 +867,4 @@ public static async Task FinishChatStreamResponse(this StreamWriter writer, stri

#pragma warning restore CS0618
#pragma warning restore CS8602 // Dereference of a possibly null reference.
#pragma warning restore CS8604 // Possible null reference argument.
#pragma warning restore CS8604 // Possible null reference argument.
Loading