thmsmlr / instructor_ex

Structured outputs for LLMs in Elixir
https://hexdocs.pm/instructor
432 stars 49 forks source link

Test fixes #13

Closed thbar closed 4 months ago

thbar commented 4 months ago

On my platform (Mac M1), I had failures on a number of tests while running just mix test.

For the reference, here is my current setup:

❯ elixir --version
Erlang/OTP 25 [erts-13.2.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.15.2 (compiled with Erlang/OTP 25)

Since I want to contribute a bit to this project, this was a good first issue :smile:.

The root cause is that Map.keys order is not guaranteed (see references below).

This PR fixes a couple of those (the ones happening on my machine) - note that I didn't run the full suite, only mix test basic suite.

EDIT: I didn't see a CHANGELOG on the project yet, it could be useful in the future to document such changes.

References

A couple of references on that topic:

https://hexdocs.pm/elixir/keywords-and-maps.html

Compared to keyword lists, we can already see two differences:

  • Maps allow any value as a key.
  • Maps' keys do not follow any ordering.

And also:

https://fly.io/phoenix-files/taking-control-of-map-sort-order-in-elixir/

If you’ve recently upgraded to Elixir 1.14.4 and OTP 26, you may have noticed that map keys are no longer showing in a predictable order

thmsmlr commented 4 months ago

Amazing, thanks. That's good to know didn't realize they weren't ordered. Not sure how I didn't run into that before

thbar commented 4 months ago

Amazing, thanks. That's good to know didn't realize they weren't ordered. Not sure how I didn't run into that before

No problem, it's a common issue, and it depends on your language or OS maybe even (if I remember well).

Thanks for accepting the fixes! Happy to contribute more :smile: