Skip to content

Commit

Permalink
feat: Added await support for IAsyncEnumerable methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 24, 2024
1 parent 83065c1 commit 91e8ca3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/libs/Ollama/OllamaApiClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Runtime.CompilerServices;
using System.Text;

namespace Ollama;

Expand Down Expand Up @@ -165,4 +166,17 @@ public static async Task<T> WaitAsync<T>(

return currentResponse;
}

/// <summary>
/// Waits for the enumerable to complete and combines the responses into a single response.
/// </summary>
/// <param name="enumerable"></param>
/// <returns></returns>
public static TaskAwaiter<T> GetAwaiter<T>(
this IAsyncEnumerable<T> enumerable) where T : new()
{
enumerable = enumerable ?? throw new ArgumentNullException(nameof(enumerable));

return enumerable.WaitAsync().GetAwaiter();
}
}
3 changes: 2 additions & 1 deletion src/libs/Ollama/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ oag generate openapi.yaml \
--namespace Ollama \
--clientClassName OllamaApiClient \
--targetFramework net8.0 \
--output Generated
--output Generated \
--exclude-deprecated-operations
#openapi-generator generate \
# -i openapi.yaml \
# -g csharp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task GetCompletionWithOptions()
{
Temperature = 0,
},
}).WaitAsync();
});
Console.WriteLine(response.Response);
}
}
2 changes: 1 addition & 1 deletion src/tests/Ollama.IntegrationTests/Tests.PullModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public async Task PullModel()
Console.WriteLine($"{response.Status?.Object}. Progress: {response.Completed}/{response.Total}");
}

var response2 = await container.ApiClient.Models.PullModelAsync("all-minilm").WaitAsync();
var response2 = await container.ApiClient.Models.PullModelAsync("all-minilm");
response2.EnsureSuccess();

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

0 comments on commit 91e8ca3

Please sign in to comment.