64bit / async-openai

Rust library for OpenAI
https://docs.rs/async-openai
MIT License
1.09k stars 161 forks source link

VectorStores list method errors out when no stores defined for a project #242

Open vrurg opened 1 month ago

vrurg commented 1 month ago

When attempting to list vector stores of a project where no store created yet the method list results in:

Error: JSONDeserialize(Error("invalid type: null, expected a string", line: 4, column: 18))

Perhaps the problem is in field data of ListVectorStoresResponse is just a Vec whereas the API can return a JSON null for it.

The proper fix would be turning the Vec into Option<Vec>, but it's a breaking change.

64bit commented 1 month ago

Thanks for reporting the error. Do you mind running same example with tracing enabled? so that actual payload which was failed to deserialize is printed, please also post the payload.

vrurg commented 1 month ago

No problem, if I can find out how to enable it. :) I'm afraid, your help in a form of advise is needed here.

64bit commented 1 month ago

Here's an example which set up tracing and library already has code to log paylod.

https://github.com/64bit/async-openai/blob/main/examples/assistants-func-call-stream/src/main.rs#L19

(perhaps this is another opportunity for improvement where failed payload can be part of the JSONDeserialize variant of OpenAIError so its easily available - however that puts burden on the user to log it - logging in the library makes it available for everyone. perhaps having both can be a an option too)

vrurg commented 1 month ago

I finally got time to give the tracing a try. Here is what it says:

2024-07-17T21:18:46.326525Z ERROR async_openai::error: failed deserialization of: {
  "object": "list",
  "data": [],
  "first_id": null,
  "last_id": null,
  "has_more": false
}
Error: JSONDeserialize(Error("invalid type: null, expected a string", line: 4, column: 18))
64bit commented 1 month ago

Thank you for providing the error. This means that the bug is last_id and first_id needs to be Optional in ListVectorStoresResponse

https://github.com/64bit/async-openai/blob/main/async-openai/src/types/vector_store.rs#L108-L109