-
Notifications
You must be signed in to change notification settings - Fork 195
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
Support Azure content filters in completion #280
Comments
Hi there, Thank you for detailed description of your use case and offering to contribute. I added Azure support without even having access to it, because access was based on approval from Azure/Microsoft (not sure if that's still the case), thanks to community for helping test and getting the PR merged #67 In retrospect, that was short sighted because there's no way for me to test new contributions or even existing code, and Azure introducing non-compatible changes have made it even more challenging. As far the options that you have listed, there's no easy answer to it either, for example how do you now incorporate something like #106? In short, its just complicated to build and maintain, given that majority of the issues are related to de-serialization. And all of this makes it unsustainable for me, and every time I come to conclusion to remove Azure support. For now its an uncertainty. So unfortunately your best bet is to go with a public fork having Azure specific changes - that way community has an option too. |
Thanks for your quick reply, and for your understanding! About #106 I'm not sure I see the issue? You already have a Anyway that's out of scope if you don't want to add Azure stuff. I absolutely understand that without a way to test it yourself or automatically, it's unreasonable. I have some ideas on how to do an "extension" allowing access to extra Azure features, building on your crate, instead of a fork. I'll see how it goes! |
Hello again, I've begun exploring the idea of building on top of your crate instead of forking it, which sounds much better on many levels 😄 . The idea would be to add "extensions" to your You can see a PoC here: https://github.com/Sufflope/async-openai/tree/azure_extensions It's of course WIP, I haven't decided whether I would want to transparently "replace" the The only problem is: for it to work, I would need the |
Thanks for sharing an approach. I think the root of the problem is not have ability for user to provide custom types for request and response. So something like:
This way one can easily use custom Request type via But on the other hand it would be nice to have ability to just inject a custom nested type (for example |
Your idea is interesting too, especially with a macro to reduce the boilerplate. You would have to add the About the serde boilerplate, if you're talking about my manual Another approach would be to just copy-paste those two types (
Haha sure if I could just somehow monkey-patch ChatChoice it would be solved. But I don't see a way to do it without having a generics nightmare where every |
I see. Combining both of our ideas: instead of wrapping existing
That way And of course this increases the work that's required to add |
As you said, that sounds like a lot of work to maintain all those After taking some time thinking about it, I think your idea of an |
That would require some abstracting of the validations, like whether the request is Probably something like: /// somewhere in common types
pub trait Streamable {
fn stream(&self) -> bool;
}
/// ...
impl Streamable for CreateChatCompletionRequest {
fn stream(&self) -> bool {
self.stream == Some(true)
}
}
/// ...
#[ext(Streamable)]
pub async fn create(
&self,
request: CreateChatCompletionRequest,
) -> Result<CreateChatCompletionResponse, OpenAIError> {
if request.stream() {
return Err(OpenAIError::InvalidArgument(
"When stream is true, use Chat::create_stream".into(),
));
}
self.client.post("/chat/completions", request).await
} That would generate a |
Thank you for looking into it further, I'm onboard with either #[ext] or APIExt - they both have pros and cons, on surface looks like APIExt might be easier to implement, however either one would get the job done. There are other edge cases like multiple inputs, the client enforcing If you're onboard too, PR is welcome! |
I drafted a first PoC, you can see it in:
+use async_azure_openai::types::CreateChatCompletionResponse;
...
- let response = self
+ let response: CreateChatCompletionResponse = self
.client
.chat()
- .create(request)
+ .create_ext(request) As you can see I tried to allow genericizing multiple parameters if needed, with the ability to add needed bounds, but also not necessarily not all parameters. This should work for functions that accept a big Request parameter but also an additional e.g. String one. For the result though I went with the strict decision that it would be |
Hi again! Could you have a look at my last PoC? I'll soon need support for content filters for a release, I can settle for a temporary ad-hoc fork, so no pressure, but it would be great if I could use your upstream instead 😃 |
Hi @Sufflope thank you for the PoC I'll take a look today and get back to you. |
Please excuse my delayed response since your PoC. Your approach and choices looks good to me. Having this minimal surface area for public I'd say for output type Please do send a PR when you get a chance, and thank you for taking ownership on this feature, its very exciting addition! |
I would say that I'll prepare a PR soon. |
…and response Fixes 64bit#280
…and response Fixes 64bit#280
Hello,
we currently use
async-openai
to query Azure OpenAI and we would need support for the new content filters on Azure OpenAI. Basically it's a newcontent_filter_results
field in(Chat)Choice
.I would be happy to work on it, however I read the
Contributing
section of the README 😄 and I understand you want to stick to OpenAI specs, while this is an Azure extension. But also (thankfully for us) there are already some Azure specific stuff I reckon (e.g. the AzureConfig), although limited admittedly.What would be the best course of action? I see a few options:
azure
feature to the crate and gate Azure-specific stuff behind it(Chat)Choice
where anything extra would be stored as aserde_value::Map
(and then people "do their thing" with those extra fields) so it supports "extra features" from providers without being Azure-specific1
would work for me of course, but I think2
(my preference) would be interesting, to have both pure OpenAI as default, but also support Azure extensions, since I believe Azure is actually a big de facto OpenAI provider, but I understand if you're not interested / willing to.3
sounds quite hackish.4
is OK of course as last resort. What do you think?The text was updated successfully, but these errors were encountered: