From b40b1c8670596f09908ae586caa5c0c75864cdb6 Mon Sep 17 00:00:00 2001 From: JD Davis Date: Thu, 30 May 2024 23:20:34 -0500 Subject: [PATCH] feat: added additional optional fields to the ShowModalResponse class and marked nullable properties appropriately. --- src/Models/ShowModel.cs | 46 +++++++++++++++++++++++++++++------- test/OllamaApiClientTests.cs | 24 +++++++++++++++++++ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/Models/ShowModel.cs b/src/Models/ShowModel.cs index 68ed8ba..04604ff 100644 --- a/src/Models/ShowModel.cs +++ b/src/Models/ShowModel.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OllamaSharp.Models { @@ -16,16 +17,45 @@ public class ShowModelRequest public class ShowModelResponse { - [JsonPropertyName("license")] - public string License { get; set; } + [JsonPropertyName("license")] + public string? License { get; set; } - [JsonPropertyName("modelfile")] - public string Modelfile { get; set; } + [JsonPropertyName("modelfile")] + public string? Modelfile { get; set; } - [JsonPropertyName("parameters")] - public string Parameters { get; set; } + [JsonPropertyName("parameters")] + public string? Parameters { get; set; } [JsonPropertyName("template")] - public string Template { get; set; } + public string? Template { get; set; } + + [JsonPropertyName("system")] + public string? System { get; set; } + + [JsonPropertyName("details")] + public ShowModelResponseDetails Details { get; set; } = null!; + } + + + public class ShowModelResponseDetails + { + [JsonPropertyName("parent_model")] + public string? ParentModel { get; set; } + + [JsonPropertyName("format")] + public string Format { get; set; } = null!; + + [JsonPropertyName("family")] + public string Family { get; set; } = null!; + + [JsonPropertyName("families")] + public List? Families { get; set; } + + [JsonPropertyName("parameter_size")] + public string ParameterSize { get; set; } = null!; + + [JsonPropertyName("quantization_level")] + public string QuantizationLevel { get; set; } = null!; } + } \ No newline at end of file diff --git a/test/OllamaApiClientTests.cs b/test/OllamaApiClientTests.cs index 237736c..12437f7 100644 --- a/test/OllamaApiClientTests.cs +++ b/test/OllamaApiClientTests.cs @@ -181,6 +181,30 @@ public async Task Returns_Deserialized_Models() info.Parameters.Should().StartWith("stop"); info.Template.Should().StartWith("[INST]"); } + + [Test] + public async Task Returns_Deserialized_Model_WithSystem() + { + _response = new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new StringContent("{\"modelfile\":\"# Modelfile generated by \\\"ollama show\\\"\\n# To build a new Modelfile based on this, replace FROM with:\\n# FROM magicoder:latest\\n\\nFROM C:\\\\Users\\\\jd\\\\.ollama\\\\models\\\\blobs\\\\sha256-4a501ed4ce55e5611922b3ee422501ff7cc773b472d196c3c416859b6d375273\\nTEMPLATE \\\"{{ .System }}\\n\\n@@ Instruction\\n{{ .Prompt }}\\n\\n@@ Response\\n\\\"\\nSYSTEM You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.\\nPARAMETER num_ctx 16384\\n\",\"parameters\":\"num_ctx 16384\",\"template\":\"{{ .System }}\\n\\n@@ Instruction\\n{{ .Prompt }}\\n\\n@@ Response\\n\",\"system\":\"You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.\",\"details\":{\"parent_model\":\"\",\"format\":\"gguf\",\"family\":\"llama\",\"families\":null,\"parameter_size\":\"7B\",\"quantization_level\":\"Q4_0\"}}") + }; + + var info = await _client.ShowModelInformation("starcoder:latest", CancellationToken.None); + + info.License.Should().BeNullOrEmpty(); + info.Modelfile.Should().StartWith("# Modelfile generated"); + info.Parameters.Should().StartWith("num_ctx"); + info.Template.Should().StartWith("{{ .System }}"); + info.System.Should().StartWith("You are an exceptionally intelligent coding assistant"); + info.Details.ParentModel.Should().BeNullOrEmpty(); + info.Details.Format.Should().Be("gguf"); + info.Details.Family.Should().Be("llama"); + info.Details.Families.Should().BeNull(); + info.Details.ParameterSize.Should().Be("7B"); + info.Details.QuantizationLevel.Should().Be("Q4_0"); + } } public class GenerateEmbeddingsMethod : OllamaApiClientTests