Skip to content
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

OpenAI API proxy with Wasi preview 2 and the WebAssembly Component Model #11

Merged
merged 27 commits into from
Nov 30, 2024

Conversation

petersalomonsen
Copy link
Owner

@petersalomonsen petersalomonsen commented Oct 11, 2024

This Pull Request contains another variant of implementing an OpenAI API proxy. It is written in Rust compiling to WASI 0.2.0 and packaged according to the WebAssembly Component Model. This provides a serverless and highly scalable proxy

For tracking spending, and initiating a conversation, the proxy is connecting to a NEAR Fungible Token contract which can be found here: petersalomonsen/quickjs-rust-near#21

TODO

  • Serverless proxy to OpenAI API
  • Require Fungible Token deposits to start a conversation
  • Track token usage throughout the conversation
  • Generate refund request signed by the server
  • The conversation ID should be hashed in the contract ( so that others cannot hijack it )
  • FT contract and network should be environment variables
  • Github action for building and testing the Wasm component

Demo

See a demo video of the application here

https://youtu.be/-R_zok--L_A?si=AkBl4IBjk6dbXDiw

image

@petersalomonsen petersalomonsen changed the title Wasip2 OpenAI API proxy with Wasi preview 2 and the WebAssembly Component Model Oct 11, 2024
Copy link

vercel bot commented Nov 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
near-openai-c9p4 ⬜️ Ignored (Inspect) Visit Preview Nov 30, 2024 8:45pm

@petersalomonsen petersalomonsen marked this pull request as ready for review November 30, 2024 19:59
@petersalomonsen petersalomonsen marked this pull request as draft November 30, 2024 20:06
@petersalomonsen petersalomonsen marked this pull request as ready for review November 30, 2024 20:56
@petersalomonsen petersalomonsen merged commit 5cf31a0 into main Nov 30, 2024
3 checks passed
petersalomonsen added a commit to petersalomonsen/quickjs-rust-near that referenced this pull request Dec 12, 2024
petersalomonsen added a commit to petersalomonsen/quickjs-rust-near that referenced this pull request Dec 14, 2024
- copied code from petersalomonsen/near-openai#11, which adds a [spin](https://github.com/fermyon/spin) app with a proxy to the OpenAI API, using the Fungible Token contract to cover usage cost
- hash `conversation_id` when calling the smart contract from the proxy to ensure that the smart contract does not reveal the conversation id that the AI proxy accepts
- added a test for the [aiconversation.js](https://github.com/petersalomonsen/quickjs-rust-near/blob/master/examples/fungibletoken/e2e/aiconversation.js) script that also shows the full process of starting a conversation and to get the refund when done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant