neferdata / allms

allms: One Rust Library to rule them aLLMs
https://crates.io/crates/allms
Other
45 stars 6 forks source link

Improved error response propagation #35

Closed kamillitman closed 4 months ago

kamillitman commented 4 months ago

This PR improves how we propagate errors received from AI APIs.

Most of these errors were previously passed as serialization. For example, currently in logs we would see something like below that is not very helpful for troubleshooting:

[2024-07-21T16:42:54Z ERROR allms::assistants::openai::openai_assistant] [OpenAIAssistant] Messages API response serialization error: missing field id at line 8 column 1

This PR takes advantage of the recently introduced AllmsError struct and passes information about what caused the error but also the response received from AI API. For example:

[2024-07-21T16:51:42Z ERROR allms::completions] AllmsError { crate_name: "allms", module: "assistants::completions::claude-2.1", error_message: "Completions API response serialization error: missing field id at line 1 column 86", error_detail: "{\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"}}" }