async-openai icon indicating copy to clipboard operation
async-openai copied to clipboard

[suggestion] Let list methods take an Option argument

Open vrurg opened this issue 1 year ago • 5 comments

Maybe this is my lack of experience, but when I'm requesting just a full list of objects like files I have to write something like:

    let file_list = files.list::<[&str; 0]>(&[]).await?;

Wouldn't it be better to let it be just files.list(None).await??

vrurg avatar Jul 12 '24 00:07 vrurg

Thanks for suggestion, it can be improved, how about having two functions

  1. files.list() with no parameters, which calls another public function below
  2. files.list_with_query(query: Q)

I think files.list() has better ergonomics than files.list(None).

64bit avatar Jul 12 '24 22:07 64bit

I think files.list() has better ergonomics than files.list(None).

I agree. I just followed #167 and tried to figure out a good compromise.

BTW, a side note here. The query arguments are currently undocumented (vector store list method uses the same design). Perhaps it worth pointing out at reqwest crate for those looking for understanding without digging into the sources, like I did.

vrurg avatar Jul 13 '24 00:07 vrurg

That's a good observation too about lack of documentation on query parameter - any contribution to help improve it is most welcome! (I think one of examples have a usage but that's not very visible/searchable on docs.rs)

Discussion in #167 was in context of missing the call for Files api group. It does seem like it needs to be addressed across the whole crate, that does sound like a breaking change where existing list becomes list_with_query

Its a small breaking-change and and an improvement so why not? Can be released in a version bump.

In addition, breaking change is ok too because list would wrap list_with_query so easy to maintain and implement.

64bit avatar Jul 14 '24 03:07 64bit

That's a good observation too about lack of documentation on query parameter - any contribution to help improve it is most welcome! (I think one of examples have a usage but that's not very visible/searchable on docs.rs)

Oh, I know this tone... :) Unfortunately, as you can see, I barely find time on side-projects now. Had to even quit Raku development. Otherwise it'd be my pleasure!

vrurg avatar Jul 17 '24 21:07 vrurg

No obligations, thank you for your contributions, the issue is going to be here if you wanna give it a shot.

64bit avatar Jul 18 '24 14:07 64bit

This is implemented in the latest release as fluid api:

client.files().query(&[("limit", 10)])?.list().await?

All other APIs also implement it, hence closing.

64bit avatar Nov 18 '25 22:11 64bit