Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CancellationToken parameters to the most complete convenience overloads. #53

Merged
merged 13 commits into from
Jun 14, 2024

Conversation

KrzysztofCwalina
Copy link
Collaborator

@KrzysztofCwalina KrzysztofCwalina commented Jun 12, 2024

fixes #35

@KrzysztofCwalina KrzysztofCwalina marked this pull request as ready for review June 13, 2024 16:44
@@ -915,7 +980,4 @@ private static ClientResult<T> CreateResultFromProtocol<T>(ClientResult protocol
T deserializedResultValue = responseDeserializer.Invoke(pipelineResponse);
return ClientResult.FromValue(deserializedResultValue, pipelineResponse);
}

private static RequestOptions StreamRequestOptions => _streamRequestOptions ??= new() { BufferResponse = false };
private static RequestOptions _streamRequestOptions;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Ctrl+C/Ctrl+V aren't worn out on the keyboard yet, could we also mirror this in the companion AssistantClient.Convenience.cs file's overloads? I know we have a pending discussion item on whether we should even have those, but in the interim it'd be great to retain parity if at all possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to do that. These are just simple call throughs, and if I add more and more overloads, the possibility of ambiguities at the call sites just goes up. That's why the title of the PR says "most complete convenience overloads".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that, for example, in the AudioClient, the methods that take a Stream do have a CancellationToken, but the overloads that take a string file path do not. Also noticed the same with other similar overloads in the FileClient and the ImageClient. I think this is a little unexpected because it forces users that need a CancellationToken into a specific paradigm.

If the main concern of adding CancellationToken is that things are more likely to break due to ambiguities in the future, I wonder if there are mitigation strategies that we could consider. Off the top of my head, what if any client method only ever had two optional parameters: The CancellationToken parameter and an options class parameter (and then the options class holds all the other optional parameters, present and future). I recognize that preemptively adding an options class for methods that only have one or two optional parameters today is perhaps not ideal, but personally I think that the benefit of knowing that this would never break due to ambiguities in the future is a good tradeoff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's look at the APIs wholistically and see if we want to add more of these overloads.

@KrzysztofCwalina KrzysztofCwalina merged commit 19a65a0 into main Jun 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CancellationToken support
3 participants