-
Notifications
You must be signed in to change notification settings - Fork 186
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
Borrow instead of moving CreateChatCompletionRequest #181
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR! While its a small change, it creates an inconsistent developer experience with remaining APIs that library exposes. Here are few options that I'd suggest:
You're welcome to pick any choice from above. |
f1017ae
to
41c803f
Compare
Sorry for the delay, I was trying to meet a deadline. This looks to be a little harder than expected. If I do it for, say, this function in pub async fn create(&self, request: &CreateFileRequest) -> Result<OpenAIFile, OpenAIError> {
self.client.post_form("/files", request).await
} I get the error
If I then try to change that #[async_convert::async_trait]
impl<'a> async_convert::TryFrom<&'a CreateFileRequest> for reqwest::multipart::Form {
type Error = OpenAIError;
async fn try_from(request: &'a CreateFileRequest) -> Result<Self, Self::Error> {
let file_part = create_file_part(request.file.source).await?;
let form = reqwest::multipart::Form::new()
.part("file", file_part)
.text("purpose", request.purpose);
Ok(form)
}
} then this error crops up:
This appears to be a known issue, and the suggested solution is hard to apply here because we can't edit the signature of the I've uploaded my edits thus far, but I don't know how feasible it is to do this for the async traits. What do you think about doing this just for the requests that don't require a I'm ok with simply closing this PR too and maintaining my own fork. I just wanted to run the idea by you, that's all. |
No worries, thank you for taking time to follow up with your findings!
Thanks for digging deeper and venturing into the unknowns - based on your findings - let say we do this for requests that don't require a TryFrom yet (required mostly for file uploads) and extrapolating that to future chat completion request which takes file uploads too - it would have similar problem and wont be future proof. Right? Alternatively, if editing signature of |
Good point!
Sounds good. I've gotten the code compiling and tests passing. Some |
I wish to retain control over the
CreateChatCompletionRequest
for logging and caching purposes after the call is made. Since thecreate
function doesn't actually need to own any of the data in the request, it can simply borrow it instead.This PR would unfortunately break the current API, but I'd like to bring it to your attention as a consideration for the next breaking release.