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

Add Model, mark Name as obsolete; Add Quantize to CreateModelRequest for ollama v0.1.35 and v0.1.39 #38

Merged
merged 2 commits into from
Jun 4, 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
82 changes: 49 additions & 33 deletions src/Models/CreateModel.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#create-a-model
/// </summary>
public class CreateModelRequest
{
/// <summary>
/// Name of the model to create
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#create-a-model
/// </summary>

[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Skip)]
public class CreateModelRequest
{
/// <summary>
/// Name of the model to create
/// </summary>
[JsonPropertyName("model")]
public string? Model { get; set; }

/// <summary>
/// Contents of the Modelfile
/// See https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md
/// </summary>
[JsonPropertyName("modelfile")]
public string ModelFileContent { get; set; }
/// <summary>
/// Name of the model to create(Obsolete)
/// </summary>
[Obsolete("Name is deprecated, see Model")]
[JsonPropertyName("name")]
public string? Name { get; set; }

/// <summary>
/// Path to the Modelfile (optional)
/// </summary>
[JsonPropertyName("path")]
public string Path { get; set; }
/// <summary>
/// Contents of the Modelfile
/// See https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md
/// </summary>
[JsonPropertyName("modelfile")]
public string ModelFileContent { get; set; }

/// <summary>
/// If false the response will be returned as a single response object, rather than a stream of objects (optional)
/// </summary>
[JsonPropertyName("stream")]
public bool Stream { get; set; }
}
/// <summary>
/// Path to the Modelfile (optional)
/// </summary>
[JsonPropertyName("path")]
public string Path { get; set; }

public class CreateStatus
{
[JsonPropertyName("status")]
public string Status { get; set; }
}
/// <summary>
/// If false the response will be returned as a single response object, rather than a stream of objects (optional)
/// </summary>
[JsonPropertyName("stream")]
public bool Stream { get; set; }

/// <summary>
/// Set the quantization level for quantize model when importing (e.g. q4_0, optional)
/// </summary>
[JsonPropertyName("quantize")]
public string? Quantize { get; set; }
}

public class CreateStatus
{
[JsonPropertyName("status")]
public string Status { get; set; }
}
}
23 changes: 15 additions & 8 deletions src/Models/DeleteModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#delete-a-model
/// </summary>
public class DeleteModelRequest
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#delete-a-model
/// </summary>

[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Skip)]
public class DeleteModelRequest
{
[JsonPropertyName("name")]
public string Name { get; set; }
}
[Obsolete("Name is deprecated, see Model")]
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonPropertyName("model")]
public string? Model { get; set; }
}
}
24 changes: 14 additions & 10 deletions src/Models/PullModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#pull-a-model
/// </summary>
public class PullModelRequest
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#pull-a-model
/// </summary>

[Obsolete("Name is deprecated, see Model")]
public class PullModelRequest
{
[JsonPropertyName("name")]
public string Name { get; set; }
[Obsolete("Name is deprecated, see Model")]
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonPropertyName("insecure")]
public bool Insecure { get; set; }
}
[JsonPropertyName("model")]
public string? Model { get; set; }
}

public class PullStatus
{
Expand Down
22 changes: 15 additions & 7 deletions src/Models/PushModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
Expand All @@ -7,13 +8,20 @@ namespace OllamaSharp.Models
/// </summary>
public class PushRequest
{
/// <summary>
/// Name of the model to push in the form of <namespace>/<model>:<tag>
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
/// <summary>
/// Name of the model to push in the form of <namespace>/<model>:<tag> (Obsolete)
/// </summary>
[Obsolete("Name is deprecated, see Model")]
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonPropertyName("insecure")]
/// <summary>
/// Name of the model to push in the form of <namespace>/<model>:<tag>
/// </summary>
[JsonPropertyName("model")]
public string? Model { get; set; }

[JsonPropertyName("insecure")]
public bool Insecure { get; set; }

[JsonPropertyName("stream")]
Expand Down
32 changes: 21 additions & 11 deletions src/Models/ShowModel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OllamaSharp.Models
{
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#show-model-information
/// </summary>
public class ShowModelRequest
/// <summary>
/// https://github.com/jmorganca/ollama/blob/main/docs/api.md#show-model-information
/// </summary>

[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Skip)]
public class ShowModelRequest
{
/// <summary>
/// The name of the model to show
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
}
/// <summary>
/// The name of the model to show
/// </summary>
[JsonPropertyName("model")]
public string? Model { get; set; }

/// <summary>
/// The name of the model to show(Obsolete)
/// </summary>
[Obsolete("Name is deprecated, see Model")]
[JsonPropertyName("name")]
public string? Name { get; set; }
}

public class ShowModelResponse
{
Expand Down
4 changes: 2 additions & 2 deletions src/OllamaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task DeleteModel(string model, CancellationToken cancellationToken
{
var request = new HttpRequestMessage(HttpMethod.Delete, "api/delete")
{
Content = new StringContent(JsonSerializer.Serialize(new DeleteModelRequest { Name = model }), Encoding.UTF8, "application/json")
Content = new StringContent(JsonSerializer.Serialize(new DeleteModelRequest { Model = model }), Encoding.UTF8, "application/json")
};

using var response = await _client.SendAsync(request, cancellationToken);
Expand All @@ -81,7 +81,7 @@ public async Task<IEnumerable<RunningModel>> ListRunningModels(CancellationToken

public async Task<ShowModelResponse> ShowModelInformation(string model, CancellationToken cancellationToken = default)
{
return await PostAsync<ShowModelRequest, ShowModelResponse>("api/show", new ShowModelRequest { Name = model }, cancellationToken);
return await PostAsync<ShowModelRequest, ShowModelResponse>("api/show", new ShowModelRequest { Model = model }, cancellationToken);
}

public async Task CopyModel(CopyModelRequest request, CancellationToken cancellationToken = default)
Expand Down
10 changes: 5 additions & 5 deletions src/OllamaApiClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static async Task CreateModel(this IOllamaApiClient client, string name,
/// <param name="cancellationToken">The token to cancel the operation with</param>
public static async Task CreateModel(this IOllamaApiClient client, string name, string modelFileContent, IResponseStreamer<CreateStatus> streamer, CancellationToken cancellationToken = default)
{
await client.CreateModel(new CreateModelRequest { Name = name, ModelFileContent = modelFileContent, Stream = true }, streamer, cancellationToken);
await client.CreateModel(new CreateModelRequest { Model = name, ModelFileContent = modelFileContent, Stream = true }, streamer, cancellationToken);
}

/// <summary>
Expand All @@ -124,7 +124,7 @@ public static async Task CreateModel(this IOllamaApiClient client, string name,
{
await client.CreateModel(new CreateModelRequest
{
Name = name,
Model = name,
ModelFileContent = modelFileContent,
Path = path,
Stream = true
Expand All @@ -147,7 +147,7 @@ await client.CreateModel(new CreateModelRequest
/// <param name="cancellationToken">The token to cancel the operation with</param>
public static async Task CreateModel(this IOllamaApiClient client, string name, string modelFileContent, string path, IResponseStreamer<CreateStatus> streamer, CancellationToken cancellationToken = default)
{
await client.CreateModel(new CreateModelRequest { Name = name, ModelFileContent = modelFileContent, Path = path, Stream = true }, streamer, cancellationToken);
await client.CreateModel(new CreateModelRequest { Model = name, ModelFileContent = modelFileContent, Path = path, Stream = true }, streamer, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -175,7 +175,7 @@ public static async Task PullModel(this IOllamaApiClient client, string model, A
/// <param name="cancellationToken">The token to cancel the operation with</param>
public static async Task PullModel(this IOllamaApiClient client, string model, IResponseStreamer<PullStatus> streamer, CancellationToken cancellationToken = default)
{
await client.PullModel(new PullModelRequest { Name = model }, streamer, cancellationToken);
await client.PullModel(new PullModelRequest { Model = model }, streamer, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -203,7 +203,7 @@ public static async Task PushModel(this IOllamaApiClient client, string name, Ac
/// <param name="cancellationToken">The token to cancel the operation with</param>
public static async Task PushModel(this IOllamaApiClient client, string name, IResponseStreamer<PushStatus> streamer, CancellationToken cancellationToken = default)
{
await client.PushModel(new PushRequest { Name = name, Stream = true }, streamer, cancellationToken);
await client.PushModel(new PushRequest { Model = name, Stream = true }, streamer, cancellationToken);
}

/// <summary>
Expand Down
Loading