From f9db5a3b081097e27481e79f213f214934f5db0e Mon Sep 17 00:00:00 2001 From: awaescher Date: Mon, 25 Nov 2024 17:39:44 +0100 Subject: [PATCH] Format whitespace --- OllamaSharp.FunctionalTests/ChatTests.cs | 6 +- OllamaSharp.FunctionalTests/Helpers.cs | 2 +- .../OllamaApiClientTests.cs | 17 +- src/Chat.cs | 2 +- src/IOllamaApiClient.cs | 242 +++++++++--------- .../OllamaFunctionResultContent.cs | 2 +- test/Tests.csproj | 56 ++-- 7 files changed, 164 insertions(+), 163 deletions(-) diff --git a/OllamaSharp.FunctionalTests/ChatTests.cs b/OllamaSharp.FunctionalTests/ChatTests.cs index 585d8f5..0f2528a 100644 --- a/OllamaSharp.FunctionalTests/ChatTests.cs +++ b/OllamaSharp.FunctionalTests/ChatTests.cs @@ -42,9 +42,9 @@ public async Task SendAsync_ShouldSucceed() // Act var response = await _chat .SendAsync("What is the ultimate answer to " + - "life, the universe, and everything, as specified in " + - "a Hitchhikers Guide to the Galaxy. " + - "Provide only the answer.", + "life, the universe, and everything, as specified in " + + "a Hitchhikers Guide to the Galaxy. " + + "Provide only the answer.", CancellationToken.None) .StreamToEndAsync(); diff --git a/OllamaSharp.FunctionalTests/Helpers.cs b/OllamaSharp.FunctionalTests/Helpers.cs index 7d52ce8..11ab5ab 100644 --- a/OllamaSharp.FunctionalTests/Helpers.cs +++ b/OllamaSharp.FunctionalTests/Helpers.cs @@ -5,7 +5,7 @@ namespace OllamaSharp.FunctionalTests; public static class Helpers { public static async Task PullIfNotExistsAsync( - this IOllamaApiClient client, + this IOllamaApiClient client, string model) { var modelExists = (await client.ListLocalModelsAsync()) diff --git a/OllamaSharp.FunctionalTests/OllamaApiClientTests.cs b/OllamaSharp.FunctionalTests/OllamaApiClientTests.cs index 99c2f04..298af92 100644 --- a/OllamaSharp.FunctionalTests/OllamaApiClientTests.cs +++ b/OllamaSharp.FunctionalTests/OllamaApiClientTests.cs @@ -62,11 +62,11 @@ public async Task PullModel() var response = await _client .PullModelAsync(new PullModelRequest { Model = _model }) .ToListAsync(); - + // Assert var models = await _client.ListLocalModelsAsync(); models.Should().Contain(m => m.Name == _model); - + response.Should().NotBeEmpty(); response.Should().Contain(r => r!.Status == "pulling manifest"); response.Should().Contain(r => r!.Status == "success"); @@ -206,7 +206,8 @@ public async Task DeleteModel() await PullIfNotExists(_localModel); await _client.CopyModelAsync(new CopyModelRequest { - Source = _localModel, Destination = $"{_localModel}-copy" + Source = _localModel, + Destination = $"{_localModel}-copy" }); var exists = (await _client.ListLocalModelsAsync()) @@ -236,14 +237,14 @@ public async Task GenerateAsync() "What is the meaning to life, the universe, and everything according to the Hitchhikers Guide to the Galaxy?" }) .ToListAsync(); - + var joined = string.Join("", response.Select(r => r.Response)); - + // Assert response.Should().NotBeEmpty(); joined.Should().Contain("42"); } - + [Test] public async Task ChatAsync() { @@ -281,7 +282,7 @@ public async Task ChatAsync() response.Should().NotBeEmpty(); joined.Should().Contain("Douglas Adams"); } - + [Test] public async Task IsRunningAsync() { @@ -291,7 +292,7 @@ public async Task IsRunningAsync() // Assert response.Should().BeTrue(); } - + [Test] public async Task GetVersionAsync() { diff --git a/src/Chat.cs b/src/Chat.cs index d788766..65c18e5 100644 --- a/src/Chat.cs +++ b/src/Chat.cs @@ -146,7 +146,7 @@ public IAsyncEnumerable SendAsync(string message, IEnumerable public interface IOllamaApiClient { - /// - /// Gets the endpoint URI used by the API client. - /// - Uri Uri { get; } - - /// - /// Gets or sets the name of the model to run requests on. - /// - string SelectedModel { get; set; } - - /// - /// Sends a request to the /api/chat endpoint and streams the response of the chat. - /// - /// The request to send to Ollama. - /// The token to cancel the operation with. - /// - /// An asynchronous enumerable that yields . Each item - /// represents a message in the chat response stream. Returns null when the - /// stream is completed. - /// - /// - /// This is the method to call the Ollama endpoint /api/chat. You might not want to do this manually. - /// To implement a fully interactive chat, you should make use of the Chat class with "new Chat(...)" - /// - IAsyncEnumerable ChatAsync(ChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/copy endpoint to copy a model. - /// - /// The parameters required to copy a model. - /// The token to cancel the operation with. - Task CopyModelAsync(CopyModelRequest request, CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/create endpoint to create a model. - /// - /// The request object containing the model details. - /// The token to cancel the operation with. - /// An asynchronous enumerable of the model creation status. - IAsyncEnumerable CreateModelAsync(CreateModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/delete endpoint to delete a model. - /// - /// The request containing the model to delete. - /// The token to cancel the operation with. - Task DeleteModelAsync(DeleteModelRequest request, CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/embed endpoint to generate embeddings. - /// - /// The parameters to generate embeddings for. - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains the . - Task EmbedAsync(EmbedRequest request, CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/tags endpoint to get all models that are available locally. - /// - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains a collection of . - Task> ListLocalModelsAsync(CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/ps endpoint to get the running models. - /// - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains a collection of . - Task> ListRunningModelsAsync(CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/pull endpoint to pull a new model. - /// - /// The request specifying the model name and whether to use an insecure connection. - /// The token to cancel the operation with. - /// - /// An asynchronous enumerable of objects representing the status of the - /// model pull operation. - /// - IAsyncEnumerable PullModelAsync(PullModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); - - /// - /// Pushes a model to the Ollama API endpoint. - /// - /// The request containing the model information to push. - /// The token to cancel the operation with. - /// - /// An asynchronous enumerable of push status updates. Use the enumerator - /// to retrieve the push status updates. - /// - IAsyncEnumerable PushModelAsync(PushModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); - - /// - /// Sends a request to the /api/show endpoint to show the information of a model. - /// - /// The request containing the name of the model to get the information for. - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains the . - Task ShowModelAsync(ShowModelRequest request, CancellationToken cancellationToken = default); - - /// - /// Streams completion responses from the /api/generate endpoint on the Ollama API based on the provided request. - /// - /// The request containing the parameters for the completion. - /// The token to cancel the operation with. - /// An asynchronous enumerable of . - IAsyncEnumerable GenerateAsync(GenerateRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); - - /// - /// Sends a query to check whether the Ollama API is running or not. - /// - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains a boolean indicating whether the API is running. - Task IsRunningAsync(CancellationToken cancellationToken = default); - - /// - /// Gets the version of Ollama. - /// - /// The token to cancel the operation with. - /// A task that represents the asynchronous operation. The task result contains the . - Task GetVersionAsync(CancellationToken cancellationToken = default); + /// + /// Gets the endpoint URI used by the API client. + /// + Uri Uri { get; } + + /// + /// Gets or sets the name of the model to run requests on. + /// + string SelectedModel { get; set; } + + /// + /// Sends a request to the /api/chat endpoint and streams the response of the chat. + /// + /// The request to send to Ollama. + /// The token to cancel the operation with. + /// + /// An asynchronous enumerable that yields . Each item + /// represents a message in the chat response stream. Returns null when the + /// stream is completed. + /// + /// + /// This is the method to call the Ollama endpoint /api/chat. You might not want to do this manually. + /// To implement a fully interactive chat, you should make use of the Chat class with "new Chat(...)" + /// + IAsyncEnumerable ChatAsync(ChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/copy endpoint to copy a model. + /// + /// The parameters required to copy a model. + /// The token to cancel the operation with. + Task CopyModelAsync(CopyModelRequest request, CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/create endpoint to create a model. + /// + /// The request object containing the model details. + /// The token to cancel the operation with. + /// An asynchronous enumerable of the model creation status. + IAsyncEnumerable CreateModelAsync(CreateModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/delete endpoint to delete a model. + /// + /// The request containing the model to delete. + /// The token to cancel the operation with. + Task DeleteModelAsync(DeleteModelRequest request, CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/embed endpoint to generate embeddings. + /// + /// The parameters to generate embeddings for. + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains the . + Task EmbedAsync(EmbedRequest request, CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/tags endpoint to get all models that are available locally. + /// + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains a collection of . + Task> ListLocalModelsAsync(CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/ps endpoint to get the running models. + /// + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains a collection of . + Task> ListRunningModelsAsync(CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/pull endpoint to pull a new model. + /// + /// The request specifying the model name and whether to use an insecure connection. + /// The token to cancel the operation with. + /// + /// An asynchronous enumerable of objects representing the status of the + /// model pull operation. + /// + IAsyncEnumerable PullModelAsync(PullModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); + + /// + /// Pushes a model to the Ollama API endpoint. + /// + /// The request containing the model information to push. + /// The token to cancel the operation with. + /// + /// An asynchronous enumerable of push status updates. Use the enumerator + /// to retrieve the push status updates. + /// + IAsyncEnumerable PushModelAsync(PushModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); + + /// + /// Sends a request to the /api/show endpoint to show the information of a model. + /// + /// The request containing the name of the model to get the information for. + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains the . + Task ShowModelAsync(ShowModelRequest request, CancellationToken cancellationToken = default); + + /// + /// Streams completion responses from the /api/generate endpoint on the Ollama API based on the provided request. + /// + /// The request containing the parameters for the completion. + /// The token to cancel the operation with. + /// An asynchronous enumerable of . + IAsyncEnumerable GenerateAsync(GenerateRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default); + + /// + /// Sends a query to check whether the Ollama API is running or not. + /// + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains a boolean indicating whether the API is running. + Task IsRunningAsync(CancellationToken cancellationToken = default); + + /// + /// Gets the version of Ollama. + /// + /// The token to cancel the operation with. + /// A task that represents the asynchronous operation. The task result contains the . + Task GetVersionAsync(CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/MicrosoftAi/OllamaFunctionResultContent.cs b/src/MicrosoftAi/OllamaFunctionResultContent.cs index 28e941c..e36f393 100644 --- a/src/MicrosoftAi/OllamaFunctionResultContent.cs +++ b/src/MicrosoftAi/OllamaFunctionResultContent.cs @@ -11,7 +11,7 @@ internal sealed class OllamaFunctionResultContent /// The function call ID for which this is the result. /// public string? CallId { get; set; } - + /// /// This element value may be if the function returned , /// if the function was void-returning and thus had no result, or if the function call failed. diff --git a/test/Tests.csproj b/test/Tests.csproj index 1a72fdf..61bacd1 100644 --- a/test/Tests.csproj +++ b/test/Tests.csproj @@ -1,34 +1,34 @@  - - net8.0 - enable - enable - false - true - IDE0065;IDE0055;IDE0011;CS8602;CS8604;S6608 - True - ..\OllamaSharp.snk - + + net8.0 + enable + enable + false + true + IDE0065;IDE0055;IDE0011;CS8602;CS8604;S6608 + True + ..\OllamaSharp.snk + - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + - - - + + +