Skip to content

Commit

Permalink
Format whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
awaescher committed Nov 25, 2024
1 parent 4c5c1ed commit f55e38c
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 135 deletions.
6 changes: 3 additions & 3 deletions OllamaSharp.FunctionalTests/ChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion OllamaSharp.FunctionalTests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 9 additions & 8 deletions OllamaSharp.FunctionalTests/OllamaApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -281,7 +282,7 @@ public async Task ChatAsync()
response.Should().NotBeEmpty();
joined.Should().Contain("Douglas Adams");
}

[Test]
public async Task IsRunningAsync()
{
Expand All @@ -291,7 +292,7 @@ public async Task IsRunningAsync()
// Assert
response.Should().BeTrue();
}

[Test]
public async Task GetVersionAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public IAsyncEnumerable<string> SendAsync(string message, IEnumerable<IEnumerabl
/// var chat = new Chat(ollama);
/// var response = chat.SendAsync("What do you see?", [base64Cat]);
/// await foreach (var answerToken in response) Console.Write(answerToken);
///
///
/// // Output:
/// // The image shows a cat lying on the floor next to an iPad. The cat is looking
/// // at the screen, which displays a game with fish and other sea creatures. The
Expand Down
242 changes: 121 additions & 121 deletions src/IOllamaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,125 +15,125 @@ namespace OllamaSharp;
/// </summary>
public interface IOllamaApiClient
{
/// <summary>
/// Gets the endpoint URI used by the API client.
/// </summary>
Uri Uri { get; }

/// <summary>
/// Gets or sets the name of the model to run requests on.
/// </summary>
string SelectedModel { get; set; }

/// <summary>
/// Sends a request to the /api/chat endpoint and streams the response of the chat.
/// </summary>
/// <param name="request">The request to send to Ollama.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable that yields <see cref="ChatResponseStream"/>. Each item
/// represents a message in the chat response stream. Returns null when the
/// stream is completed.
/// </returns>
/// <remarks>
/// 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(...)"
/// </remarks>
IAsyncEnumerable<ChatResponseStream?> ChatAsync(ChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/copy endpoint to copy a model.
/// </summary>
/// <param name="request">The parameters required to copy a model.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
Task CopyModelAsync(CopyModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/create endpoint to create a model.
/// </summary>
/// <param name="request">The request object containing the model details.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>An asynchronous enumerable of the model creation status.</returns>
IAsyncEnumerable<CreateModelResponse?> CreateModelAsync(CreateModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/delete endpoint to delete a model.
/// </summary>
/// <param name="request">The request containing the model to delete.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
Task DeleteModelAsync(DeleteModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/embed endpoint to generate embeddings.
/// </summary>
/// <param name="request">The parameters to generate embeddings for.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="EmbedResponse"/>.</returns>
Task<EmbedResponse> EmbedAsync(EmbedRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/tags endpoint to get all models that are available locally.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of <see cref="Model"/>.</returns>
Task<IEnumerable<Model>> ListLocalModelsAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/ps endpoint to get the running models.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of <see cref="RunningModel"/>.</returns>
Task<IEnumerable<RunningModel>> ListRunningModelsAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/pull endpoint to pull a new model.
/// </summary>
/// <param name="request">The request specifying the model name and whether to use an insecure connection.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable of <see cref="PullModelResponse"/> objects representing the status of the
/// model pull operation.
/// </returns>
IAsyncEnumerable<PullModelResponse?> PullModelAsync(PullModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Pushes a model to the Ollama API endpoint.
/// </summary>
/// <param name="request">The request containing the model information to push.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable of push status updates. Use the enumerator
/// to retrieve the push status updates.
/// </returns>
IAsyncEnumerable<PushModelResponse?> PushModelAsync(PushModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/show endpoint to show the information of a model.
/// </summary>
/// <param name="request">The request containing the name of the model to get the information for.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="ShowModelResponse"/>.</returns>
Task<ShowModelResponse> ShowModelAsync(ShowModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Streams completion responses from the /api/generate endpoint on the Ollama API based on the provided request.
/// </summary>
/// <param name="request">The request containing the parameters for the completion.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>An asynchronous enumerable of <see cref="GenerateResponseStream"/>.</returns>
IAsyncEnumerable<GenerateResponseStream?> GenerateAsync(GenerateRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a query to check whether the Ollama API is running or not.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean indicating whether the API is running.</returns>
Task<bool> IsRunningAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Gets the version of Ollama.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="Version"/>.</returns>
Task<Version> GetVersionAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the endpoint URI used by the API client.
/// </summary>
Uri Uri { get; }

/// <summary>
/// Gets or sets the name of the model to run requests on.
/// </summary>
string SelectedModel { get; set; }

/// <summary>
/// Sends a request to the /api/chat endpoint and streams the response of the chat.
/// </summary>
/// <param name="request">The request to send to Ollama.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable that yields <see cref="ChatResponseStream"/>. Each item
/// represents a message in the chat response stream. Returns null when the
/// stream is completed.
/// </returns>
/// <remarks>
/// 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(...)"
/// </remarks>
IAsyncEnumerable<ChatResponseStream?> ChatAsync(ChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/copy endpoint to copy a model.
/// </summary>
/// <param name="request">The parameters required to copy a model.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
Task CopyModelAsync(CopyModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/create endpoint to create a model.
/// </summary>
/// <param name="request">The request object containing the model details.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>An asynchronous enumerable of the model creation status.</returns>
IAsyncEnumerable<CreateModelResponse?> CreateModelAsync(CreateModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/delete endpoint to delete a model.
/// </summary>
/// <param name="request">The request containing the model to delete.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
Task DeleteModelAsync(DeleteModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/embed endpoint to generate embeddings.
/// </summary>
/// <param name="request">The parameters to generate embeddings for.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="EmbedResponse"/>.</returns>
Task<EmbedResponse> EmbedAsync(EmbedRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/tags endpoint to get all models that are available locally.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of <see cref="Model"/>.</returns>
Task<IEnumerable<Model>> ListLocalModelsAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/ps endpoint to get the running models.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of <see cref="RunningModel"/>.</returns>
Task<IEnumerable<RunningModel>> ListRunningModelsAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/pull endpoint to pull a new model.
/// </summary>
/// <param name="request">The request specifying the model name and whether to use an insecure connection.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable of <see cref="PullModelResponse"/> objects representing the status of the
/// model pull operation.
/// </returns>
IAsyncEnumerable<PullModelResponse?> PullModelAsync(PullModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Pushes a model to the Ollama API endpoint.
/// </summary>
/// <param name="request">The request containing the model information to push.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>
/// An asynchronous enumerable of push status updates. Use the enumerator
/// to retrieve the push status updates.
/// </returns>
IAsyncEnumerable<PushModelResponse?> PushModelAsync(PushModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a request to the /api/show endpoint to show the information of a model.
/// </summary>
/// <param name="request">The request containing the name of the model to get the information for.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="ShowModelResponse"/>.</returns>
Task<ShowModelResponse> ShowModelAsync(ShowModelRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Streams completion responses from the /api/generate endpoint on the Ollama API based on the provided request.
/// </summary>
/// <param name="request">The request containing the parameters for the completion.</param>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>An asynchronous enumerable of <see cref="GenerateResponseStream"/>.</returns>
IAsyncEnumerable<GenerateResponseStream?> GenerateAsync(GenerateRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default);

/// <summary>
/// Sends a query to check whether the Ollama API is running or not.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean indicating whether the API is running.</returns>
Task<bool> IsRunningAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Gets the version of Ollama.
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the <see cref="Version"/>.</returns>
Task<Version> GetVersionAsync(CancellationToken cancellationToken = default);
}
2 changes: 1 addition & 1 deletion src/MicrosoftAi/OllamaFunctionResultContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class OllamaFunctionResultContent
/// The function call ID for which this is the result.
/// </summary>
public string? CallId { get; set; }

/// <summary>
/// This element value may be <see langword="null" /> if the function returned <see langword="null" />,
/// if the function was void-returning and thus had no result, or if the function call failed.
Expand Down

0 comments on commit f55e38c

Please sign in to comment.