dongri / openai-api-rs

OpenAI API client library for Rust (unofficial)
https://docs.rs/openai-api-rs
MIT License
303 stars 53 forks source link

Bring back support for sync requests #103

Open sztomi opened 2 months ago

sztomi commented 2 months ago

Describe the feature or improvement you're requesting

92 says it introduces support for async, but it also seems to fully remove sync requests. This is a disruptive and likely undersirable change for applications that are not already async. Is there any chance to bring back support for sync operations?

Additional context

No response

dongri commented 2 months ago

I wanted to continue processing synchronously, but I changed to asynchronous because the library I was using had various flaws.

What specific inconveniences are there?

sztomi commented 2 months ago

What specific inconveniences are there?

My use-case is a simple CLI application that takes a ticket number and uses the OpenAI API to synthetise a branch name that describes the title of the ticket. This is a fully synchronous, it uses ureq to query the ticketing system, then uses openai-api-rs (3.0.1) to query OpenAI. While this is a small program and refactoring it to support async is not a huge deal, it introduces unwanted complexity, obscuring the control flow for no tangible benefit (it is always two, sequential requests that happen in the program).

dongri commented 2 months ago

@sztomi I see, understanding the challenge of depending on tokio can indeed make the program larger. However, you're struggling to find a good way to support both synchronous and asynchronous execution. Do you have any good ideas?

sztomi commented 2 months ago

I think the three main approaches that libraries take are:

In future Rust, keyword generics will allow solving this problem in a more elegant way.