Tinygo + WASI Support
I was attempting to use this library in a Go project that is targeting WASI preview 2 and using Tinygo to compile to that target. Due to some unimplemented portions of reflect and httputil packages in Tinygo (AssignableTo, ConvertibleTo, SliceOf, DumpRequestOut, DumpResponse), I'm unable to compile code that depends on this library.
I believe the httputil usage could be fixed with a build tag to omit the functionality. However, the reflect dependencies are in the encoder / decoder and would likely take more significant changes.
Is there a desire to be able to use this library from a Go application targeting WASI + Wasm?
This is a good call out. It's not a priority to support these platforms at the moment, but it certainly would be nice.
This package depends heavily on net/http which is also unimplemented by Tinygo. Unfortunately it would require pretty significant changes to the library to make that work.
I think it's realistic to remove SliceOf and ConvertibleTo from the custom encoders/decoders.
Rather than a full library, are there specific OpenAI-Go SDK utilities we could make Tinygo-friendly that would be helpful?
E.g. types that implement json.Marshaler and json.Unmarshaler
I don't think it's quite a big lift. Here's an example of chat completion in Golang that can compile to Wasm, which uses encoding/json.
This https://github.com/bytecodealliance/go-modules/pull/305 should provide the niceties needed to support HTTP transport and related bits for Golang.
The couple bits missing are httptrace and httputil which are related to https://github.com/tinygo-org/tinygo/issues/4822, and some of the reflect related stuff.
Thanks, that's helpful knowledge.
Our focus will initially be on other features before the GA launch. However, I can split the Error.DumpRequest and Error.DumpResponse methods in internal/apierror/apierror.go into a different file with build tags, and remove reflect.SliceOf & reflect.ConvertibleTo from the encoder/decoders.
At that point, if you're willing to share a PR that solves any remaining issues, I'd gladly review and incorporate it.
How does that sound as a short term goal? I'll update the thread when that's ready.
Sounds great! I'd be delighted to help with the effort.
Just following up after a little bit of experimentation, I'll have a branch up by this afternoon that you can begin to play with
I've modified the code generator on the jacob/tinygo-dev branch to remove reflect.ConvertibleTo and hide Error.DumpReq/Response behind a build tag.
It only contains the autogenerated code without any of the handwritten helper functions, so many of the examples may need some extra work to compile.
Feel free to compare with the generated branch to see the differences.
I will be a bit delayed on this as I'm about to leave for KubeCon London, and have a couple talks to prep. Please don't infer that my brief silence implies I've lost interest. Just ran out of time in the last day to do any significant work on this topic.
👀