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

Expose more pub(crate) methods as public or provide traits to override behavior #297

Open
ryanolson opened this issue Dec 12, 2024 · 1 comment

Comments

@ryanolson
Copy link

First off, this is a really well done project. Thank you for all your work.

There is one feature missing that is preventing me from fully scratching my current OAI bits and moving to this project.

I have an OAI service, but I have added new behavior to the SSE event stream to augment the information sent back in the streaming response. Besides just using the data: field in the SSE stream, I use SSE events and comments to provide a more rich description of the server-side state.

You already have the abstractions needed:
https://github.com/64bit/async-openai/blob/main/async-openai/src/client.rs#L493

With this method, you can provide an event handler, which could handle event:, etc.

In my specific case, my output stream would be an Annotated where all the sole data: message are O and all the events and other bits are wrapped by the Annotated wrapper. Your abstractions already allow get/post to be generic with respect to O.

Would you be willing to extend the client functionality to provide more custom SSE handling?

What would this look like? I'm not entirely sure. Initially, we could make this method fully public:
https://github.com/64bit/async-openai/blob/main/async-openai/src/client.rs#L402

Later, we could decide if/how to use the trait system.

Thoughts?

@ryanolson
Copy link
Author

If I had a trait like

#[async_trait]
pub trait AnnotatedStream<I, O> {
    async fn create_annotated_stream(&self, mut request: I) -> Result<AnnotatedStream<O>, OpenAIError>;
}

I could then apply that to the Chat object.

One further thing would be needed. I would need to access the underlying client. We might expose that as via a ClientProvider trait.

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

No branches or pull requests

1 participant