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 optional system property to ShowModelResponse and set proper nullability #35

Merged
merged 1 commit into from
May 31, 2024
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
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
Loading