Skip to content

Commit

Permalink
feat: added additional optional fields to the ShowModalResponse class…
Browse files Browse the repository at this point in the history
… and marked nullable properties appropriately.
  • Loading branch information
JerrettDavis committed May 31, 2024
1 parent a5d3d0c commit b40b1c8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/Models/ShowModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
Expand All @@ -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<string>? Families { get; set; }

[JsonPropertyName("parameter_size")]
public string ParameterSize { get; set; } = null!;

[JsonPropertyName("quantization_level")]
public string QuantizationLevel { get; set; } = null!;
}

}
24 changes: 24 additions & 0 deletions test/OllamaApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b40b1c8

Please sign in to comment.