outlines-core icon indicating copy to clipboard operation
outlines-core copied to clipboard

Redefine `Error`s interface

Open torymur opened this issue 1 year ago • 5 comments

We would like to keep the size of Error as small as possible (currently, it's 48 bytes already).

So it needs to be defined as a struct with Boxed inner error, in the same manner as it's done in serde_json or reqwest: https://github.com/serde-rs/json/blob/master/src/error.rs https://github.com/seanmonstar/reqwest/blob/master/src/error.rs

torymur avatar Dec 12 '24 19:12 torymur

@torymur but with this change, we will have to update code at all places which uses Error::IndexError for example. Should it then be handled in this way ??

// Convert from ErrorImpl to Error
impl From<ErrorImpl> for Error {
    fn from(err_impl: ErrorImpl) -> Self {
        Error(Box::new(err_impl))
    }
}

And replacing this:

Err(Error::IndexError)

with this:

Err(ErrorImpl::IndexError.into())

Another option is to use constructor methods, I am not sure which design pattern would be better, lmk your thoughts on this.

sky-2002 avatar Dec 21 '24 09:12 sky-2002

Hey @sky-2002

Apologies, I now assigned myself to this issue and I will figure out a better way to communicate issues like this, which is more of a note to not forget, rather than anything actionable (even for a better thought than in description). This part of the project is in the middle of heavy refactoring and is not stabilized yet enough to answer here right now.

torymur avatar Dec 21 '24 10:12 torymur

@torymur ahh right, thanks for clearing, thought as much, it did look like a note to not to forget, my bad 🙌🏻 . Anyways, apologies for the interruption. Actually I keep looking for issues to get hands on with rust (as I come from python) and also with outlines, and so found this one.

sky-2002 avatar Dec 21 '24 10:12 sky-2002

@sky-2002 There are some unassigned issues with json schema, for example, recently outlines added support for objects in enum fields, but we didn't have it here: https://github.com/dottxt-ai/outlines-core/issues/100

torymur avatar Dec 21 '24 10:12 torymur

Cool, will check out those.

sky-2002 avatar Dec 21 '24 10:12 sky-2002