From a9169511b23ed2dd438e8a31ca30dddff07a5624 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sun, 12 May 2024 22:21:04 +0400 Subject: [PATCH] fix: Fixed 400 error when use RequestOptions. --- src/libs/Directory.Build.props | 2 +- src/libs/Ollama/OllamaApiClient.cs | 1 + .../Tests.Integration.cs | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libs/Directory.Build.props b/src/libs/Directory.Build.props index ae02883..d1b82af 100755 --- a/src/libs/Directory.Build.props +++ b/src/libs/Directory.Build.props @@ -14,7 +14,7 @@ - 0.9.4 + 0.9.5 true true tryAGI and contributors diff --git a/src/libs/Ollama/OllamaApiClient.cs b/src/libs/Ollama/OllamaApiClient.cs index 77c5974..14fab7c 100644 --- a/src/libs/Ollama/OllamaApiClient.cs +++ b/src/libs/Ollama/OllamaApiClient.cs @@ -341,6 +341,7 @@ private async IAsyncEnumerable StreamPostAsync( } } +[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] [JsonSerializable(typeof(DeleteModelRequest))] [JsonSerializable(typeof(GenerateCompletionRequest))] [JsonSerializable(typeof(GenerateCompletionResponse))] diff --git a/src/tests/Ollama.IntegrationTests/Tests.Integration.cs b/src/tests/Ollama.IntegrationTests/Tests.Integration.cs index 4bfbaa0..bf075d4 100755 --- a/src/tests/Ollama.IntegrationTests/Tests.Integration.cs +++ b/src/tests/Ollama.IntegrationTests/Tests.Integration.cs @@ -78,6 +78,28 @@ public async Task PullModel() await container.ApiClient.PullModelAsync("nomic-embed-text").WaitAsync(); } + [TestMethod] + public async Task GetCompletionWithOptions() + { +#if DEBUG + await using var container = await PrepareEnvironmentAsync(EnvironmentType.Local, "llama3"); +#else + await using var container = await PrepareEnvironmentAsync(EnvironmentType.Container, "llama3"); +#endif + + var response = await container.ApiClient.GetCompletionAsync(new GenerateCompletionRequest + { + Model = "llama3", + Prompt = "answer me just \"123\"", + Stream = true, + Options = new RequestOptions + { + Temperature = 0, + }, + }).WaitAsync(); + Console.WriteLine(response.Response); + } + [TestMethod] public async Task GetCompletion() {