-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CancellationToken parameters to the most complete convenience o…
…verloads. (#53) * added CancellationToken parameters to the ChatClient * cleaned up RO extension * added CTs to AudioClient * added CTs to EmbeddingClient * added CTs to FileClient * added CTs to ModeriationClient * added CTs to ImageClient * added CTs to VectorStoreClient * added CTs to AssistantClient * fixed test sources as the callsite become ambiguous * fixed formatting in one file * PR feedback * removed back the special CT overload
- Loading branch information
1 parent
b1fa082
commit 19a65a0
Showing
11 changed files
with
401 additions
and
237 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.ClientModel.Primitives; | ||
using System.Threading; | ||
|
||
internal static class CancellationTokenExtensions | ||
{ | ||
public static RequestOptions ToRequestOptions(this CancellationToken cancellationToken, bool streaming = false) | ||
{ | ||
if (cancellationToken == default) | ||
{ | ||
if (!streaming) return null; | ||
return StreamRequestOptions; | ||
} | ||
|
||
return new RequestOptions() { | ||
CancellationToken = cancellationToken, | ||
BufferResponse = !streaming, | ||
}; | ||
} | ||
|
||
private static RequestOptions StreamRequestOptions => _streamRequestOptions ??= new() { BufferResponse = false }; | ||
private static RequestOptions _streamRequestOptions; | ||
} |
Oops, something went wrong.