Skip to content

Commit

Permalink
feat: Added AnyOf/Enum support, added new endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 5, 2024
1 parent 522f9cd commit 9f12c6d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<PropertyGroup Label="Nuget">
<Version>1.2.1</Version>
<Version>1.3.0</Version>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>tryAGI and contributors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Ollama.Models/Ollama.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenApiGenerator" Version="0.9.7">
<PackageReference Include="OpenApiGenerator" Version="0.9.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Ollama/Ollama.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenApiGenerator" Version="0.9.7">
<PackageReference Include="OpenApiGenerator" Version="0.9.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Ollama/OllamaApiClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public static void EnsureSuccess(
{
response = response ?? throw new ArgumentNullException(nameof(response));

if (response.Status != PullModelResponseStatus.Success)
if (response.Status.Value2 != PullModelResponseStatus.Success)
{
throw new InvalidOperationException($"Failed to pull model with status {response.Status}");
throw new InvalidOperationException($"Failed to pull model with status {response.Status.Object}");
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/libs/Ollama/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
using System.Text.Json.Serialization;
using OpenApiGenerator.JsonConverters;

namespace Ollama;

[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSourceGenerationOptions(
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters =
[
// We need specify explicitly all converters for enums inside AnyOf/OneOf/AllOf to make them work
typeof(CreateModelResponseStatusJsonConverter),
typeof(CreateModelResponseStatusNullableJsonConverter),
typeof(PullModelResponseStatusJsonConverter),
typeof(PullModelResponseStatusNullableJsonConverter),
typeof(PushModelResponseStatusJsonConverter),
typeof(PushModelResponseStatusNullableJsonConverter),
])]
[JsonSerializable(typeof(JsonSerializerContextTypes))]
internal sealed partial class SourceGenerationContext : JsonSerializerContext;
1 change: 1 addition & 0 deletions src/tests/Ollama.IntegrationTests/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Ollama.IntegrationTests;

public sealed class Environment : IAsyncDisposable
{
public required EnvironmentType Type { get; init; }
public IContainer? Container { get; init; }
public required OllamaApiClient ApiClient { get; init; }

Expand Down
17 changes: 16 additions & 1 deletion src/tests/Ollama.IntegrationTests/Tests.Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private static async Task<Environment> PrepareEnvironmentAsync(EnvironmentType e

return new Environment
{
Type = environmentType,
ApiClient = apiClient,
};
}
Expand All @@ -42,6 +43,7 @@ private static async Task<Environment> PrepareEnvironmentAsync(EnvironmentType e

return new Environment
{
Type = environmentType,
Container = container,
ApiClient = apiClient,
};
Expand Down Expand Up @@ -74,7 +76,7 @@ public async Task PullModel()

await foreach (var response in container.ApiClient.Models.PullModelAsync("all-minilm", stream: true))
{
Console.WriteLine($"{response.Status}. Progress: {response.Completed}/{response.Total}");
Console.WriteLine($"{response.Status.Object}. Progress: {response.Completed}/{response.Total}");
}

var response2 = await container.ApiClient.Models.PullModelAsync("all-minilm").WaitAsync();
Expand All @@ -88,13 +90,26 @@ public async Task Embeddings()
{
await using var container = await PrepareEnvironmentAsync(EnvironmentType.Container);

if (container.Type == EnvironmentType.Local)
{
var models = await container.ApiClient.Models.ListRunningModelsAsync();
models.Models.Should().BeNullOrEmpty();
}

await container.ApiClient.Models.PullModelAndEnsureSuccessAsync("all-minilm");

var embeddingResponse = await container.ApiClient.Embeddings.GenerateEmbeddingAsync(
model:"all-minilm",
prompt: "hello");

embeddingResponse.Embedding.Should().NotBeNullOrEmpty();

if (container.Type == EnvironmentType.Local)
{
var models2 = await container.ApiClient.Models.ListRunningModelsAsync();
models2.Models.Should().NotBeNullOrEmpty();
}

}

[TestMethod]
Expand Down

0 comments on commit 9f12c6d

Please sign in to comment.