Skip to content

Tinygo + WASI Support #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
devigned opened this issue Mar 24, 2025 · 7 comments
Open

Tinygo + WASI Support #318

devigned opened this issue Mar 24, 2025 · 7 comments
Labels
enhancement New feature or request

Comments

@devigned
Copy link

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?

@jacobzim-stl
Copy link
Collaborator

jacobzim-stl commented Mar 26, 2025

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

@jacobzim-stl jacobzim-stl reopened this Mar 26, 2025
@jacobzim-stl jacobzim-stl added the enhancement New feature or request label Mar 26, 2025
@devigned
Copy link
Author

devigned commented Mar 26, 2025

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 bytecodealliance/go-modules#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 tinygo-org/tinygo#4822, and some of the reflect related stuff.

@jacobzim-stl
Copy link
Collaborator

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.

@devigned
Copy link
Author

Sounds great! I'd be delighted to help with the effort.

@jacobzim-stl
Copy link
Collaborator

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

@jacobzim-stl
Copy link
Collaborator

jacobzim-stl commented Mar 27, 2025

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.

@devigned
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants